// upload the picture (icon, photo, whatever) associated with the current room void common_code_for_editroompic_and_editpic(char *servcmd) { if (havebstr("cancel_button")) { AppendImportantMessage(_("Graphics upload has been cancelled."), -1); display_main_menu(); return; } if (WC->upload_length == 0) { AppendImportantMessage(_("You didn't upload a file."), -1); display_main_menu(); return; } serv_printf("%s %ld|%s", servcmd, (long)WC->upload_length, GuessMimeType(ChrPtr(WC->upload), WC->upload_length)); StrBuf *Line = NewStrBuf(); StrBuf_ServGetln(Line); if (GetServerStatusMsg(Line, NULL, 0, 0) == 7) { serv_write(ChrPtr(WC->upload), WC->upload_length); display_success(ChrPtr(Line) + 4); } else { AppendImportantMessage((ChrPtr(Line) + 4), -1); display_main_menu(); } FreeStrBuf(&Line); }
void do_graphics_upload(char *filename) { StrBuf *Line; const char *MimeType; wcsession *WCC = WC; int bytes_remaining; int pos = 0; int thisblock; bytes_remaining = WCC->upload_length; if (havebstr("cancel_button")) { AppendImportantMessage(_("Graphics upload has been cancelled."), -1); display_main_menu(); return; } if (WCC->upload_length == 0) { AppendImportantMessage(_("You didn't upload a file."), -1); display_main_menu(); return; } MimeType = GuessMimeType(ChrPtr(WCC->upload), bytes_remaining); serv_printf("UIMG 1|%s|%s", MimeType, filename); Line = NewStrBuf(); StrBuf_ServGetln(Line); if (GetServerStatusMsg(Line, NULL, 1, 2) != 2) { display_main_menu(); FreeStrBuf(&Line); return; } while (bytes_remaining) { thisblock = ((bytes_remaining > 4096) ? 4096 : bytes_remaining); serv_printf("WRIT %d", thisblock); StrBuf_ServGetln(Line); if (GetServerStatusMsg(Line, NULL, 1, 7) != 7) { serv_puts("UCLS 0"); StrBuf_ServGetln(Line); display_main_menu(); FreeStrBuf(&Line); return; } thisblock = extract_int(ChrPtr(Line) +4, 0); serv_write(&ChrPtr(WCC->upload)[pos], thisblock); pos += thisblock; bytes_remaining -= thisblock; } serv_puts("UCLS 1"); StrBuf_ServGetln(Line); if (*ChrPtr(Line) != 'x') { display_success(ChrPtr(Line) + 4); } FreeStrBuf(&Line); }
/* * Wraps a Citadel server command in an AJAX transaction. */ void ajax_servcmd(void) { wcsession *WCC = WC; int Done = 0; StrBuf *Buf; char *junk; size_t len; if (verbose) syslog(LOG_DEBUG, "ajax_servcmd() g_cmd=\"%s\"", bstr("g_cmd") ); begin_ajax_response(); Buf = NewStrBuf(); serv_puts(bstr("g_cmd")); StrBuf_ServGetln(Buf); StrBufAppendBuf(WCC->WBuf, Buf, 0); StrBufAppendBufPlain(WCC->WBuf, HKEY("\n"), 0); switch (GetServerStatus(Buf, NULL)) { case 8: serv_puts("\n\n000"); if ( (StrLength(Buf)==3) && !strcmp(ChrPtr(Buf), "000")) { StrBufAppendBufPlain(WCC->WBuf, HKEY("\000"), 0); break; } case 1: while (!Done) { if (StrBuf_ServGetln(Buf) < 0) break; if ( (StrLength(Buf)==3) && !strcmp(ChrPtr(Buf), "000")) { Done = 1; } StrBufAppendBuf(WCC->WBuf, Buf, 0); StrBufAppendBufPlain(WCC->WBuf, HKEY("\n"), 0); } break; case 4: text_to_server(bstr("g_input")); serv_puts("000"); break; case 6: len = atol(&ChrPtr(Buf)[4]); StrBuf_ServGetBLOBBuffered(Buf, len); break; case 7: len = atol(&ChrPtr(Buf)[4]); junk = malloc(len); memset(junk, 0, len); serv_write(junk, len); free(junk); } end_ajax_response(); /* * This is kind of an ugly hack, but this is the only place it can go. * If the command was GEXP, then the instant messenger window must be * running, so reset the "last_pager_check" watchdog timer so * that page_popup() doesn't try to open it a second time. TODO: page_popup isn't with us anymore. */ if (!strncasecmp(bstr("g_cmd"), "GEXP", 4)) { WCC->last_pager_check = time(NULL); } FreeStrBuf(&Buf); }
/* * send line to server - implemented in terms of serv_write() */ void serv_puts(char *buf) { serv_write(buf, strlen(buf)); serv_write("\n", 1); }
/* * send line to server - implemented in terms of serv_write() */ void serv_puts(char *buf) { if (debug) fprintf(stderr, "< %s\n", buf); serv_write(buf, strlen(buf)); serv_write("\n", 1); }