* Pack all session info into one easy-to-digest cookie. Healthy and delicious!
*/
void stuff_to_cookie(char *cookie, size_t clen, int session,
- StrBuf *user, StrBuf *pass, StrBuf *room, char *language)
+ StrBuf *user, StrBuf *pass, StrBuf *room, const char *language)
{
char buf[SIZ];
int i;
long blocksize;
wcsession *WCC = WC; /* stack this for faster access (WC is a function) */
- MimeType = GuessMimeType(WCC->upload, WCC->upload_length);
+ MimeType = GuessMimeType(ChrPtr(WCC->upload), WCC->upload_length);
serv_printf("UOPN %s|%s|%s", WCC->upload_filename, MimeType, bstr("description"));
serv_getln(buf, sizeof buf);
if (buf[0] != '2')
if (buf[0] == '7')
{
blocksize = atoi(&buf[4]);
- serv_write(&WCC->upload[bytes_transmitted], blocksize);
+ serv_write(&ChrPtr(WCC->upload)[bytes_transmitted], blocksize);
bytes_transmitted += blocksize;
}
}
void do_graphics_upload(char *filename)
{
const char *MimeType;
+ wcsession *WCC = WC;
char buf[SIZ];
int bytes_remaining;
int pos = 0;
int thisblock;
- bytes_remaining = WC->upload_length;
+ bytes_remaining = WCC->upload_length;
if (havebstr("cancel_button")) {
strcpy(WC->ImportantMessage,
return;
}
- if (WC->upload_length == 0) {
+ if (WCC->upload_length == 0) {
strcpy(WC->ImportantMessage,
_("You didn't upload a file."));
display_main_menu();
return;
}
- MimeType = GuessMimeType(&WC->upload[0], bytes_remaining);
+ MimeType = GuessMimeType(ChrPtr(WCC->upload), bytes_remaining);
snprintf(buf, SIZ, "UIMG 1|%s|%s", MimeType, filename);
serv_puts(buf);
serv_getln(buf, sizeof buf);
if (buf[0] != '2') {
- strcpy(WC->ImportantMessage, &buf[4]);
+ strcpy(WCC->ImportantMessage, &buf[4]);
display_main_menu();
return;
}
serv_printf("WRIT %d", thisblock);
serv_getln(buf, sizeof buf);
if (buf[0] != '7') {
- strcpy(WC->ImportantMessage, &buf[4]);
+ strcpy(WCC->ImportantMessage, &buf[4]);
serv_puts("UCLS 0");
serv_getln(buf, sizeof buf);
display_main_menu();
return;
}
thisblock = extract_int(&buf[4], 0);
- serv_write(&WC->upload[pos], thisblock);
+ serv_write(&ChrPtr(WCC->upload)[pos], thisblock);
pos = pos + thisblock;
bytes_remaining = bytes_remaining - thisblock;
}
return;
}
- serv_write(WCC->upload, WCC->upload_length);
+ serv_putbuf(WCC->upload);
serv_printf("\n000");
/* Report success and not much else. */
/* Send the content to the Citadel server */
serv_printf("Content-type: %s\n\n", WCC->upload_content_type);
- serv_puts(WCC->upload);
+ serv_putbuf(WCC->upload);
serv_puts("\n000");
/* Fetch the reply from the Citadel server */
* Transfer control of this memory from the upload struct
* to the attachment struct.
*/
- att->Data = NewStrBufPlain(WCC->upload, WCC->upload_length);
- free(WCC->upload);
- WCC->upload_length = 0;
+ att->Data = WCC->upload;
WCC->upload = NULL;
+ WCC->upload_length = 0;
display_enter();
return;
}
void *content, char *cbtype, char *cbcharset,
size_t length, char *encoding, char *cbid, void *userdata)
{
+ wcsession *WCC = WC;
urlcontent *u;
#ifdef DEBUG_URLSTRINGS
lprintf(9, "upload_handler() name=%s, type=%s, len=%d\n", name, cbtype, length);
#endif
- if (WC->Hdr->urlstrings == NULL)
- WC->Hdr->urlstrings = NewHash(1, NULL);
+ if (WCC->Hdr->urlstrings == NULL)
+ WCC->Hdr->urlstrings = NewHash(1, NULL);
/* Form fields */
if ( (length > 0) && (IsEmptyStr(cbtype)) ) {
safestrncpy(u->url_key, name, sizeof(u->url_key));
u->url_data = NewStrBufPlain(content, length);
- Put(WC->Hdr->urlstrings, u->url_key, strlen(u->url_key), u, free_url);
+ Put(WCC->Hdr->urlstrings, u->url_key, strlen(u->url_key), u, free_url);
#ifdef DEBUG_URLSTRINGS
lprintf(9, "Key: <%s> len: [%ld] Data: <%s>\n",
u->url_key,
/** Uploaded files */
if ( (length > 0) && (!IsEmptyStr(cbtype)) ) {
- WC->upload = malloc(length);
- if (WC->upload != NULL) {
- WC->upload_length = length;
- safestrncpy(WC->upload_filename, filename,
- sizeof(WC->upload_filename));
- safestrncpy(WC->upload_content_type, cbtype,
- sizeof(WC->upload_content_type));
- memcpy(WC->upload, content, length);
- }
- else {
- lprintf(3, "malloc() failed: %s\n", strerror(errno));
- }
+ WCC->upload = NewStrBufPlain(content, length);
+ WCC->upload_length = length;
+ safestrncpy(WCC->upload_filename, filename,
+ sizeof(WC->upload_filename));
+ safestrncpy(WCC->upload_content_type, cbtype,
+ sizeof(WC->upload_content_type));
+
}
}
WCC->Hdr->HR.ContentLength +
body_start;
mime_parser(ChrPtr(content), content_end, *upload_handler, NULL, NULL, NULL, 0);
+ } else if (WCC->Hdr->HR.ContentLength > 0) {
+ WCC->upload = content;
+ content = NULL;
}
FreeStrBuf(&content);
}
{
DeleteHash(&sess->Hdr->urlstrings);// TODO?
if (sess->upload_length > 0) {
- free(sess->upload);
+ FreeStrBuf(&sess->upload);
sess->upload_length = 0;
}
FreeStrBuf(&sess->trailing_javascript);
/* Uploading; mime attachments for composing messages */
HashList *attachments; /**< list of attachments for 'enter message' */
int upload_length; /**< content length of http-uploaded data */
- char *upload; /**< pointer to http-uploaded data */
+ StrBuf *upload; /**< pointer to http-uploaded data */
char upload_filename[PATH_MAX]; /**< filename of http-uploaded data */
char upload_content_type[256]; /**< content type of http-uploaded data */
StrBuf *user,
StrBuf *pass,
StrBuf *room,
- char *language
+ const char *language
);
void cookie_to_stuff(StrBuf *cookie,
int *session,