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); }
// 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); }
/* * This function is for uploading an ENTIRE calendar, not just one * component. This would be for webcal:// 'publish' operations, not * for GroupDAV. */ void dav_put_bigics(void) { wcsession *WCC = WC; char buf[1024]; /* * Tell the server that when we save a calendar event, we * do *not* want the server to generate invitations. */ serv_puts("ICAL sgi|0"); serv_getln(buf, sizeof buf); serv_puts("ICAL putics"); serv_getln(buf, sizeof buf); if (buf[0] != '4') { hprintf("HTTP/1.1 502 Bad Gateway\r\n"); dav_common_headers(); hprintf("Content-type: text/plain\r\n"); begin_burst(); wc_printf("%s\r\n", &buf[4]); end_burst(); return; } serv_putbuf(WCC->upload); serv_printf("\n000"); /* Report success and not much else. */ hprintf("HTTP/1.1 204 No Content\r\n"); syslog(LOG_DEBUG, "HTTP/1.1 204 No Content\r\n"); dav_common_headers(); begin_burst(); end_burst(); }
/* * Display a list of all pages in a Wiki room (template callback) */ void tmplput_display_wiki_pagelist(StrBuf *Target, WCTemplputParams *TP) { StrBuf *Buf; int row = 0; if (!IsEmptyStr(bstr("query"))) { serv_printf("MSGS SEARCH|%s||4", bstr("query")); /* search-reduced list */ } else { serv_printf("MSGS ALL|||4"); /* full list */ } Buf = NewStrBuf(); StrBuf_ServGetln(Buf); if (GetServerStatus(Buf, NULL) == 1) { StrBuf *pagetitle = NewStrBuf(); wc_printf("<table class=\"wiki_pagelist_background\">"); wc_printf("<th>%s</th>", _("Page title")); while((StrBuf_ServGetln(Buf) >= 0) && strcmp(ChrPtr(Buf), "000")) { StrBufExtract_token(pagetitle, Buf, 1, '|'); if (!bmstrcasestr((char *)ChrPtr(pagetitle), "_HISTORY_")) { /* no history pages */ wc_printf("<tr bgcolor=\"%s\">", ((row%2) ? "#FFFFFF" : "#DDDDDD")); wc_printf("<td><a href=\"wiki?page="); urlescputs(ChrPtr(pagetitle)); wc_printf("\">"); escputs(ChrPtr(pagetitle)); wc_printf("</a></td>"); wc_printf("</tr>\n"); ++row; } } wc_printf("</table>\n"); FreeStrBuf(&pagetitle); } FreeStrBuf(&Buf); }
/* * Detach an OpenID from the currently logged-in account */ void openid_detach(void) { StrBuf *Line; if (havebstr("id_to_detach")) { serv_printf("OIDD %s", bstr("id_to_detach")); Line = NewStrBuf(); StrBuf_ServGetln(Line); GetServerStatusMsg(Line, NULL, 1, 2); FreeStrBuf(&Line); } display_openids(); }
/* * Serialize a vnote and write it to the server */ void write_vnote_to_server(struct vnote *v) { char buf[1024]; char *pch; char boundary[256]; static int seq = 0; snprintf(boundary, sizeof boundary, "Citadel--Multipart--%s--%04x--%04x", ChrPtr(WC->serv_info->serv_fqdn), getpid(), ++seq ); serv_puts("ENT0 1|||4"); serv_getln(buf, sizeof buf); if (buf[0] == '4') { /* Remember, serv_printf() appends an extra newline */ serv_printf("Content-type: multipart/alternative; " "boundary=\"%s\"\n", boundary); serv_printf("This is a multipart message in MIME format.\n"); serv_printf("--%s", boundary); serv_puts("Content-type: text/plain; charset=utf-8"); serv_puts("Content-Transfer-Encoding: 7bit"); serv_puts(""); serv_puts(v->body); serv_puts(""); serv_printf("--%s", boundary); serv_puts("Content-type: text/vnote"); serv_puts("Content-Transfer-Encoding: 7bit"); serv_puts(""); pch = vnote_serialize(v); serv_puts(pch); free(pch); serv_printf("--%s--", boundary); serv_puts("000"); } }
/* * Display a specific page from a wiki room * * "rev" may be set to an empty string to display the current version. * "do_revert" may be set to nonzero to perform a reversion to the specified version. */ void display_wiki_page_backend(char *pagename, char *rev, int do_revert) { wcsession *WCC = WC; const StrBuf *Mime; long msgnum = (-1L); char buf[256]; if ((WCC->CurRoom.view != VIEW_WIKI) && (WCC->CurRoom.view != VIEW_WIKIMD)) { wc_printf(_("'%s' is not a Wiki room."), ChrPtr(WCC->CurRoom.name) ); return; } if (IsEmptyStr(pagename)) { strcpy(pagename, "home"); } str_wiki_index(pagename); /* convert index name to lowercase and numeric only */ if ((rev != NULL) && (strlen(rev) > 0)) { /* read an older revision */ serv_printf("WIKI rev|%s|%s|%s", pagename, rev, (do_revert ? "revert" : "fetch") ); serv_getln(buf, sizeof buf); if (buf[0] == '2') { msgnum = extract_long(&buf[4], 0); } } else { /* read the current revision */ msgnum = locate_message_by_uid(pagename); } if (msgnum >= 0L) { read_message(WCC->WBuf, HKEY("view_message"), msgnum, NULL, &Mime); return; } wc_printf("<br><br>" "<div align=\"center\">" "<table border=\"0\" bgcolor=\"#ffffff\" cellpadding=\"10\">" "<tr><td align=\"center\">" ); wc_printf("<br><b>"); wc_printf(_("There is no page called '%s' here."), pagename); wc_printf("</b><br><br>"); wc_printf(_("Select the 'Edit this page' link in the room banner " "if you would like to create this page.")); wc_printf("<br><br>"); wc_printf("</td></tr></table></div>\n"); }
HashList *iterate_FindConflict(StrBuf *Target, WCTemplputParams *TP) { StrBuf *Line; HashList *Conflicts = NULL; CalendarConflict *Conflict; wc_mime_attachment *Mime = (wc_mime_attachment *) CTX(CTX_MIME_ATACH); serv_printf("ICAL conflicts|%ld|%s|", Mime->msgnum, ChrPtr(Mime->PartNum)); Line = NewStrBuf(); StrBuf_ServGetln(Line); if (GetServerStatus(Line, NULL) == 1) { const char *Pos = NULL; int Done = 0; int n = 0; Conflicts = NewHash(1, Flathash); while(!Done && (StrBuf_ServGetln(Line) >= 0) ) if ( (StrLength(Line)==3) && !strcmp(ChrPtr(Line), "000")) { Done = 1; } else { Conflict = (CalendarConflict *) malloc(sizeof(CalendarConflict)); Conflict->conflict_event_uid = NewStrBufPlain(NULL, StrLength(Line)); Conflict->conflict_event_summary = NewStrBufPlain(NULL, StrLength(Line)); Conflict->existing_msgnum = StrBufExtractNext_long(Line, &Pos, '|'); StrBufSkip_NTokenS(Line, &Pos, '|', 1); StrBufExtract_NextToken(Conflict->conflict_event_uid, Line, &Pos, '|'); StrBufExtract_NextToken(Conflict->conflict_event_summary, Line, &Pos, '|'); Conflict->is_update = StrBufExtractNext_long(Line, &Pos, '|'); Put(Conflicts, IKEY(n), Conflict, DeleteConflict); n++; Pos = NULL; } } FreeStrBuf(&Line); syslog(LOG_DEBUG, "...done.\n"); return Conflicts; }
void display_graphics_upload(char *filename) { StrBuf *Line; Line = NewStrBuf(); serv_printf("UIMG 0||%s", filename); StrBuf_ServGetln(Line); if (GetServerStatusMsg(Line, NULL, 1, 2) != 2) { display_main_menu(); return; } else { output_headers(1, 0, 0, 0, 1, 0); do_template("files_graphicsupload"); end_burst(); } FreeStrBuf(&Line); }
// display the picture (icon, photo, whatever) associated with the current room void display_roompic(void) { off_t bytes; StrBuf *Buf = NewStrBuf(); serv_printf("DLRI"); StrBuf_ServGetln(Buf); if (GetServerStatus(Buf, NULL) == 6) { StrBufCutLeft(Buf, 4); bytes = StrBufExtract_long(Buf, 0, '|'); StrBuf *content_type = NewStrBuf(); StrBufExtract_token(content_type, Buf, 3, '|'); WC->WBuf = NewStrBuf(); StrBuf_ServGetBLOBBuffered(WC->WBuf, bytes); http_transmit_thing(ChrPtr(content_type), 0); FreeStrBuf(&content_type); } else { output_error_pic("", ""); } FreeStrBuf(&Buf); }
/* * Receiving side of the chat window. * This does JavaScript writes to * other divs whenever it refreshes and finds new data. */ void chat_recv(void) { char buf[SIZ]; char cl_user[SIZ]; serv_printf("RCHT poll|%d", WC->last_chat_seq); serv_getln(buf, sizeof buf); if (buf[0] == '1') { WC->last_chat_seq = extract_int(&buf[4], 0); extract_token(cl_user, &buf[4], 2, '|', sizeof cl_user); /* who is speaking ... */ if (strcasecmp(cl_user, WC->last_chat_user)) { wc_printf("<br>\n"); if (!strcasecmp(cl_user, ChrPtr(WC->wc_fullname))) { wc_printf("<span class=\"chat_myname_class\">"); } else { wc_printf("<span class=\"chat_notmyname_class\">"); } escputs(cl_user); strcpy(WC->last_chat_user, cl_user); wc_printf(": </span>"); } else { wc_printf(" "); } /* what did they say ... */ wc_printf("<span class=\"chat_text_class\">"); while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { escputs(buf); } wc_printf("<br></span>\n"); } }
/* * Display the revision history for a wiki page (template callback) */ void tmplput_display_wiki_history(StrBuf *Target, WCTemplputParams *TP) { char pagename[128]; StrBuf *Buf; int row = 0; safestrncpy(pagename, bstr("page"), sizeof pagename); str_wiki_index(pagename); serv_printf("WIKI history|%s", pagename); Buf = NewStrBuf(); StrBuf_ServGetln(Buf); if (GetServerStatus(Buf, NULL) == 1) { time_t rev_date; char rev_date_displayed[64]; StrBuf *rev_uuid = NewStrBuf(); StrBuf *author = NewStrBuf(); StrBuf *node = NewStrBuf(); wc_printf("<table class=\"wiki_history_background\">"); wc_printf("<th>%s</th>", _("Date")); wc_printf("<th>%s</th>", _("Author")); while((StrBuf_ServGetln(Buf) >= 0) && strcmp(ChrPtr(Buf), "000")) { rev_date = extract_long(ChrPtr(Buf), 1); webcit_fmt_date(rev_date_displayed, sizeof rev_date_displayed, rev_date, DATEFMT_FULL); StrBufExtract_token(author, Buf, 2, '|'); wc_printf("<tr bgcolor=\"%s\">", ((row%2) ? "#FFFFFF" : "#DDDDDD")); wc_printf("<td>%s</td><td>", rev_date_displayed); if (!strcasecmp(ChrPtr(node), (char *)WC->serv_info->serv_nodename)) { escputs(ChrPtr(author)); wc_printf(" @ "); escputs(ChrPtr(node)); } else { wc_printf("<a href=\"showuser?who="); urlescputs(ChrPtr(author)); wc_printf("\">"); escputs(ChrPtr(author)); wc_printf("</a>"); } wc_printf("</td>"); if (row == 0) { wc_printf("<td><a href=\"wiki?page=%s", bstr("page")); wc_printf("?go="); urlescputs(ChrPtr(WC->CurRoom.name)); wc_printf("\">%s</a></td>", _("(show)")); wc_printf("<td>(%s)</td>", _("Current version")); } else { wc_printf("<td><a href=\"wiki?page=%s?rev=%s", bstr("page"), ChrPtr(rev_uuid) ); wc_printf("?go="); urlescputs(ChrPtr(WC->CurRoom.name)); wc_printf("\">%s</a></td>", _("(show)")); wc_printf("<td><a href=\"javascript:GetLoggedInFirst(encodeURIComponent('wiki?page=%s?rev=%s?revert=1'))\">%s</a></td>", bstr("page"), ChrPtr(rev_uuid), _("(revert)") ); } wc_printf("</tr>\n"); /* Extract all fields except the author and date after displaying the row. This * is deliberate, because the timestamp reflects when the diff was written, not * when the version which it reflects was written. Similarly, the name associated * with each diff is the author who created the newer version of the page that * made the diff happen. */ StrBufExtract_token(rev_uuid, Buf, 0, '|'); StrBufExtract_token(node, Buf, 3, '|'); ++row; } wc_printf("</table>\n"); FreeStrBuf(&author); FreeStrBuf(&node); FreeStrBuf(&rev_uuid); } else { wc_printf("%s", ChrPtr(Buf)); } FreeStrBuf(&Buf); }
/* * Fetch a message from the server and extract a vNote from it */ struct vnote *vnote_new_from_msg(long msgnum,int unread) { StrBuf *Buf; StrBuf *Data = NULL; const char *bptr; int Done = 0; char uid_from_headers[256]; char mime_partnum[256]; char mime_filename[256]; char mime_content_type[256]; char mime_disposition[256]; char relevant_partnum[256]; int phase = 0; /* 0 = citadel headers, 1 = mime headers, 2 = body */ char msg4_content_type[256] = ""; char msg4_content_encoding[256] = ""; int msg4_content_length = 0; struct vnote *vnote_from_body = NULL; int vnote_inline = 0; /* 1 = MSG4 gave us a text/x-vnote top level */ relevant_partnum[0] = '\0'; serv_printf("MSG4 %ld", msgnum); /* we need the mime headers */ Buf = NewStrBuf(); StrBuf_ServGetln(Buf); if (GetServerStatus(Buf, NULL) != 1) { FreeStrBuf (&Buf); return NULL; } while ((StrBuf_ServGetln(Buf)>=0) && !Done) { if ( (StrLength(Buf)==3) && !strcmp(ChrPtr(Buf), "000")) { Done = 1; break; } bptr = ChrPtr(Buf); switch (phase) { case 0: if (!strncasecmp(bptr, "exti=", 5)) { safestrncpy(uid_from_headers, &(ChrPtr(Buf)[5]), sizeof uid_from_headers); } else if (!strncasecmp(bptr, "part=", 5)) { extract_token(mime_filename, &bptr[5], 1, '|', sizeof mime_filename); extract_token(mime_partnum, &bptr[5], 2, '|', sizeof mime_partnum); extract_token(mime_disposition, &bptr[5], 3, '|', sizeof mime_disposition); extract_token(mime_content_type, &bptr[5], 4, '|', sizeof mime_content_type); if (!strcasecmp(mime_content_type, "text/vnote")) { strcpy(relevant_partnum, mime_partnum); } } else if ((phase == 0) && (!strncasecmp(bptr, "text", 4))) { phase = 1; } break; case 1: if (!IsEmptyStr(bptr)) { if (!strncasecmp(bptr, "Content-type: ", 14)) { safestrncpy(msg4_content_type, &bptr[14], sizeof msg4_content_type); striplt(msg4_content_type); } else if (!strncasecmp(bptr, "Content-transfer-encoding: ", 27)) { safestrncpy(msg4_content_encoding, &bptr[27], sizeof msg4_content_encoding); striplt(msg4_content_type); } else if ((!strncasecmp(bptr, "Content-length: ", 16))) { msg4_content_length = atoi(&bptr[16]); } break; } else { phase++; if ((msg4_content_length > 0) && ( !strcasecmp(msg4_content_encoding, "7bit")) && (!strcasecmp(msg4_content_type, "text/vnote")) ) { vnote_inline = 1; } } case 2: if (vnote_inline) { Data = NewStrBufPlain(NULL, msg4_content_length * 2); if (msg4_content_length > 0) { StrBuf_ServGetBLOBBuffered(Data, msg4_content_length); phase ++; } else { StrBufAppendBuf(Data, Buf, 0); StrBufAppendBufPlain(Data, "\r\n", 1, 0); } } case 3: if (vnote_inline) { StrBufAppendBuf(Data, Buf, 0); } } } FreeStrBuf(&Buf); /* If MSG4 didn't give us the part we wanted, but we know that we can find it * as one of the other MIME parts, attempt to load it now. */ if ((!vnote_inline) && (!IsEmptyStr(relevant_partnum))) { Data = load_mimepart(msgnum, relevant_partnum); } if (StrLength(Data) > 0) { if (IsEmptyStr(uid_from_headers)) { /* Convert an old-style note to a vNote */ vnote_from_body = vnote_new(); vnote_from_body->uid = strdup(uid_from_headers); vnote_from_body->color_red = pastel_palette[3][0]; vnote_from_body->color_green = pastel_palette[3][1]; vnote_from_body->color_blue = pastel_palette[3][2]; vnote_from_body->body = malloc(StrLength(Data) + 1); vnote_from_body->body[0] = 0; memcpy(vnote_from_body->body, ChrPtr(Data), StrLength(Data) + 1); FreeStrBuf(&Data); return vnote_from_body; } else { char *Buf = SmashStrBuf(&Data); struct vnote *v = vnote_new_from_str(Buf); free(Buf); return(v); } } return NULL; }
/* * Background ajax call to receive updates from the browser when a note is moved, resized, or updated. */ void ajax_update_note(void) { char buf[1024]; int msgnum; struct vnote *v = NULL; if (!havebstr("note_uid")) { begin_ajax_response(); wc_printf("Received ajax_update_note() request without a note UID."); end_ajax_response(); return; } serv_printf("EUID %s", bstr("note_uid")); serv_getln(buf, sizeof buf); if (buf[0] != '2') { begin_ajax_response(); wc_printf("Cannot find message containing vNote with the requested uid!"); end_ajax_response(); return; } msgnum = atol(&buf[4]); /* Was this request a delete operation? If so, nuke it... */ if (havebstr("deletenote")) { if (!strcasecmp(bstr("deletenote"), "yes")) { serv_printf("DELE %d", msgnum); serv_getln(buf, sizeof buf); begin_ajax_response(); wc_printf("%s", buf); end_ajax_response(); return; } } /* If we get to this point it's an update, not a delete */ v = vnote_new_from_msg(msgnum, 0); if (!v) { begin_ajax_response(); wc_printf("Cannot locate a vNote within message %d\n", msgnum); end_ajax_response(); return; } /* Make any requested changes */ if (havebstr("top")) { v->pos_top = atoi(bstr("top")); } if (havebstr("left")) { v->pos_left = atoi(bstr("left")); } if (havebstr("height")) { v->pos_height = atoi(bstr("height")); } if (havebstr("width")) { v->pos_width = atoi(bstr("width")); } if (havebstr("red")) { v->color_red = atoi(bstr("red")); } if (havebstr("green")) { v->color_green = atoi(bstr("green")); } if (havebstr("blue")) { v->color_blue = atoi(bstr("blue")); } if (havebstr("value")) { /* I would have preferred 'body' but InPlaceEditor hardcodes 'value' */ if (v->body) free(v->body); v->body = strdup(bstr("value")); } /* Serialize it and save it to the message base. Server will delete the old one. */ write_vnote_to_server(v); begin_ajax_response(); if (v->body) { escputs(v->body); } end_ajax_response(); vnote_free(v); }
/* * The pathname is always going to be /groupdav/room_name/euid */ void dav_delete(void) { wcsession *WCC = WC; char dav_uid[SIZ]; long dav_msgnum = (-1); char buf[SIZ]; int n = 0; StrBuf *dav_roomname = NewStrBuf(); /* Now extract the message euid */ n = StrBufNum_tokens(WCC->Hdr->HR.ReqLine, '/'); extract_token(dav_uid, ChrPtr(WCC->Hdr->HR.ReqLine), n-1, '/', sizeof dav_uid); StrBufExtract_token(dav_roomname, WCC->Hdr->HR.ReqLine, 0, '/'); ///* What's left is the room name. Remove trailing slashes. */ //len = StrLength(WCC->Hdr->HR.ReqLine); //if ((len > 0) && (ChrPtr(WCC->Hdr->HR.ReqLinee)[len-1] == '/')) { // StrBufCutRight(WCC->Hdr->HR.ReqLine, 1); //} //StrBufCutLeft(WCC->Hdr->HR.ReqLine, 1); /* Go to the correct room. */ if (strcasecmp(ChrPtr(WC->CurRoom.name), ChrPtr(dav_roomname))) { gotoroom(dav_roomname); } if (strcasecmp(ChrPtr(WC->CurRoom.name), ChrPtr(dav_roomname))) { hprintf("HTTP/1.1 404 not found\r\n"); dav_common_headers(); hprintf("Content-Length: 0\r\n\r\n"); begin_burst(); end_burst(); FreeStrBuf(&dav_roomname); return; } dav_msgnum = locate_message_by_uid(dav_uid); /* * If no item exists with the requested uid ... simple error. */ if (dav_msgnum < 0L) { hprintf("HTTP/1.1 404 Not Found\r\n"); dav_common_headers(); hprintf("Content-Length: 0\r\n\r\n"); begin_burst(); end_burst(); FreeStrBuf(&dav_roomname); return; } /* * It's there ... check the ETag and make sure it matches * the message number. */ if (StrLength(WCC->Hdr->HR.dav_ifmatch) > 0) { if (StrTol(WCC->Hdr->HR.dav_ifmatch) != dav_msgnum) { hprintf("HTTP/1.1 412 Precondition Failed\r\n"); dav_common_headers(); hprintf("Content-Length: 0\r\n\r\n"); begin_burst(); end_burst(); FreeStrBuf(&dav_roomname); return; } } /* * Ok, attempt to delete the item. */ serv_printf("DELE %ld", dav_msgnum); serv_getln(buf, sizeof buf); if (buf[0] == '2') { hprintf("HTTP/1.1 204 No Content\r\n"); /* success */ dav_common_headers(); hprintf("Content-Length: 0\r\n\r\n"); begin_burst(); end_burst(); } else { hprintf("HTTP/1.1 403 Forbidden\r\n"); /* access denied */ dav_common_headers(); hprintf("Content-Length: 0\r\n\r\n"); begin_burst(); end_burst(); } FreeStrBuf(&dav_roomname); return; }
void save_pushemail(void) { folder Room; int Done = 0; StrBuf *Buf; char buf[SIZ]; int msgnum = 0; char *pushsetting = bstr("pushsetting"); char *sms = NULL; if (strncasecmp(pushsetting, "textmessage", 11) == 0) { sms = bstr("user_sms_number"); } Buf = NewStrBuf(); memset(&Room, 0, sizeof(folder)); if (goto_config_room(Buf, &Room) != 0) { FreeStrBuf(&Buf); FlushFolder(&Room); return; /* oh well. */ } FlushFolder(&Room); serv_puts("MSGS ALL|0|1"); StrBuf_ServGetln(Buf); if (GetServerStatus(Buf, NULL) == 8) { serv_puts("subj|__ Push email settings __"); serv_puts("000"); } else { printf("Junk in save_pushemail buffer!: %s\n", buf); FreeStrBuf(&Buf); return; } while (!Done && StrBuf_ServGetln(Buf) >= 0) { if ( (StrLength(Buf)==3) && !strcmp(ChrPtr(Buf), "000")) { Done = 1; break; } msgnum = StrTol(Buf); } if (msgnum > 0L) { serv_printf("DELE %d", msgnum); StrBuf_ServGetln(Buf); GetServerStatus(Buf, NULL); } serv_printf("ENT0 1||0|1|__ Push email settings __|"); StrBuf_ServGetln(Buf); if (GetServerStatus(Buf, NULL) == 4) { serv_puts(pushsetting); if (sms != NULL) { serv_puts(sms); } serv_puts(""); serv_puts("000"); } /** Go back to the room we're supposed to be in */ serv_printf("GOTO %s", ChrPtr(WC->CurRoom.name)); StrBuf_ServGetln(Buf); GetServerStatus(Buf, NULL); http_redirect("display_pushemail"); FreeStrBuf(&Buf); }
/* * Entry point for WebCit transaction */ void session_loop(void) { int xhttp; StrBuf *Buf; /* * We stuff these with the values coming from the client cookies, * so we can use them to reconnect a timed out session if we have to. */ wcsession *WCC; WCC= WC; WCC->upload_length = 0; WCC->upload = NULL; WCC->Hdr->nWildfireHeaders = 0; if (WCC->Hdr->HR.ContentLength > 0) { if (ReadPostData() < 0) { return; } } Buf = NewStrBuf(); WCC->trailing_javascript = NewStrBuf(); /* Convert base64-encoded URL's back to plain text */ if (!strncmp(ChrPtr(WCC->Hdr->this_page), "/B64", 4)) { StrBufCutLeft(WCC->Hdr->this_page, 4); StrBufDecodeBase64(WCC->Hdr->this_page); http_redirect(ChrPtr(WCC->Hdr->this_page)); goto SKIP_ALL_THIS_CRAP; } /* If there are variables in the URL, we must grab them now */ if (WCC->Hdr->PlainArgs != NULL) ParseURLParams(WCC->Hdr->PlainArgs); /* If the client sent a nonce that is incorrect, kill the request. */ if (havebstr("nonce")) { if (verbose) syslog(LOG_DEBUG, "Comparing supplied nonce %s to session nonce %d", bstr("nonce"), WCC->nonce ); if (ibstr("nonce") != WCC->nonce) { syslog(LOG_INFO, "Ignoring request with mismatched nonce."); hprintf("HTTP/1.1 404 Security check failed\r\n"); hprintf("Content-Type: text/plain\r\n"); begin_burst(); wc_printf("Security check failed.\r\n"); end_burst(); goto SKIP_ALL_THIS_CRAP; } } /* * If we're not connected to a Citadel server, try to hook up the connection now. */ if (!WCC->connected) { if (GetConnected()) { hprintf("HTTP/1.1 503 Service Unavailable\r\n"); hprintf("Content-Type: text/html\r\n"); begin_burst(); wc_printf("<html><head><title>503 Service Unavailable</title></head><body>\n"); wc_printf(_("This program was unable to connect or stay " "connected to the Citadel server. Please report " "this problem to your system administrator.") ); wc_printf("<br>"); wc_printf("<a href=\"http://www.citadel.org/doku.php/" "faq:generalquestions:webcit_unable_to_connect\">%s</a>", _("Read More...") ); wc_printf("</body></html>\n"); end_burst(); goto SKIP_ALL_THIS_CRAP; } } /* * If we're not logged in, but we have authentication data (either from * a cookie or from http-auth), try logging in to Citadel using that. */ if ( (!WCC->logged_in) && (StrLength(WCC->Hdr->c_username) > 0) && (StrLength(WCC->Hdr->c_password) > 0) ) { long Status; FlushStrBuf(Buf); serv_printf("USER %s", ChrPtr(WCC->Hdr->c_username)); StrBuf_ServGetln(Buf); if (GetServerStatus(Buf, &Status) == 3) { serv_printf("PASS %s", ChrPtr(WCC->Hdr->c_password)); StrBuf_ServGetln(Buf); if (GetServerStatus(Buf, NULL) == 2) { become_logged_in(WCC->Hdr->c_username, WCC->Hdr->c_password, Buf); } else { /* Should only display when password is wrong */ WCC->ImportantMsg = NewStrBufPlain(ChrPtr(Buf) + 4, StrLength(Buf) - 4); authorization_required(); FreeStrBuf(&Buf); goto SKIP_ALL_THIS_CRAP; } } else if (Status == 541) { WCC->logged_in = 1; } } xhttp = (WCC->Hdr->HR.eReqType != eGET) && (WCC->Hdr->HR.eReqType != ePOST) && (WCC->Hdr->HR.eReqType != eHEAD); /* * If a 'go' (or 'gotofirst') parameter has been specified, attempt to goto that room * prior to doing anything else. */ if (havebstr("go")) { int ret; if (verbose) syslog(LOG_DEBUG, "Explicit room selection: %s", bstr("go")); ret = gotoroom(sbstr("go")); /* do quietly to avoid session output! */ if ((ret/100) != 2) { if (verbose) syslog(LOG_DEBUG, "Unable to change to [%s]; Reason: %d", bstr("go"), ret); } } else if (havebstr("gotofirst")) { int ret; if (verbose) syslog(LOG_DEBUG, "Explicit room selection: %s", bstr("gotofirst")); ret = gotoroom(sbstr("gotofirst")); /* do quietly to avoid session output! */ if ((ret/100) != 2) { syslog(LOG_INFO, "Unable to change to [%s]; Reason: %d", bstr("gotofirst"), ret); } } /* * If we aren't in any room yet, but we have cookie data telling us where we're * supposed to be, and 'go' was not specified, then go there. */ else if ( (StrLength(WCC->CurRoom.name) == 0) && ( (StrLength(WCC->Hdr->c_roomname) > 0) )) { int ret; if (verbose) syslog(LOG_DEBUG, "We are in '%s' but cookie indicates '%s', going there...", ChrPtr(WCC->CurRoom.name), ChrPtr(WCC->Hdr->c_roomname) ); ret = gotoroom(WCC->Hdr->c_roomname); /* do quietly to avoid session output! */ if ((ret/100) != 2) { if (verbose) syslog(LOG_DEBUG, "COOKIEGOTO: Unable to change to [%s]; Reason: %d", ChrPtr(WCC->Hdr->c_roomname), ret); } } if (WCC->Hdr->HR.Handler != NULL) { if ( (!WCC->logged_in) && ((WCC->Hdr->HR.Handler->Flags & ANONYMOUS) == 0) && (WCC->serv_info != NULL) && (WCC->serv_info->serv_supports_guest == 0) ) { display_login(); } else { if ((WCC->Hdr->HR.Handler->Flags & AJAX) != 0) { begin_ajax_response(); } WCC->Hdr->HR.Handler->F(); if ((WCC->Hdr->HR.Handler->Flags & AJAX) != 0) { end_ajax_response(); } } } /* When all else fails, display the default landing page or a main menu. */ else { /* * ordinary browser users get a nice login screen, DAV etc. requsets * are given a 401 so they can handle it appropriate. */ if (!WCC->logged_in) { if (xhttp) { authorization_required(); } else { display_default_landing_page(); } } /* * Toplevel dav requests? or just a flat browser request? */ else { if (xhttp) { dav_main(); } else { display_main_menu(); } } } SKIP_ALL_THIS_CRAP: FreeStrBuf(&Buf); fflush(stdout); }
/* * The pathname is always going to take one of two formats: * [/groupdav/]room_name/euid (GroupDAV) * [/groupdav/]room_name (webcal) */ void dav_put(void) { wcsession *WCC = WC; StrBuf *dav_roomname; StrBuf *dav_uid; long new_msgnum = (-2L); long old_msgnum = (-1L); char buf[SIZ]; int n = 0; if (StrBufNum_tokens(WCC->Hdr->HR.ReqLine, '/') < 2) { hprintf("HTTP/1.1 404 not found\r\n"); dav_common_headers(); hprintf("Content-Type: text/plain\r\n"); begin_burst(); wc_printf("The object you requested was not found.\r\n"); end_burst(); return; } dav_roomname = NewStrBuf();; dav_uid = NewStrBuf();; StrBufExtract_token(dav_roomname, WCC->Hdr->HR.ReqLine, 0, '/'); StrBufExtract_token(dav_uid, WCC->Hdr->HR.ReqLine, 1, '/'); if ((!strcasecmp(ChrPtr(dav_uid), "ics")) || (!strcasecmp(ChrPtr(dav_uid), "calendar.ics"))) { FlushStrBuf(dav_uid); } /* Go to the correct room. */ if (strcasecmp(ChrPtr(WC->CurRoom.name), ChrPtr(dav_roomname))) { gotoroom(dav_roomname); } if (strcasecmp(ChrPtr(WC->CurRoom.name), ChrPtr(dav_roomname))) { hprintf("HTTP/1.1 404 not found\r\n"); dav_common_headers(); hprintf("Content-Type: text/plain\r\n"); begin_burst(); wc_printf("There is no folder called \"%s\" on this server.\r\n", ChrPtr(dav_roomname)); end_burst(); FreeStrBuf(&dav_roomname); FreeStrBuf(&dav_uid); return; } /* * If an HTTP If-Match: header is present, the client is attempting * to replace an existing item. We have to check to see if the * message number associated with the supplied uid matches what the * client is expecting. If not, the server probably contains a newer * version, so we fail... */ if (StrLength(WCC->Hdr->HR.dav_ifmatch) > 0) { syslog(LOG_DEBUG, "dav_ifmatch: %s\n", ChrPtr(WCC->Hdr->HR.dav_ifmatch)); old_msgnum = locate_message_by_uid(ChrPtr(dav_uid)); syslog(LOG_DEBUG, "old_msgnum: %ld\n", old_msgnum); if (StrTol(WCC->Hdr->HR.dav_ifmatch) != old_msgnum) { hprintf("HTTP/1.1 412 Precondition Failed\r\n"); syslog(LOG_INFO, "HTTP/1.1 412 Precondition Failed (ifmatch=%ld, old_msgnum=%ld)\r\n", StrTol(WCC->Hdr->HR.dav_ifmatch), old_msgnum); dav_common_headers(); end_burst(); FreeStrBuf(&dav_roomname); FreeStrBuf(&dav_uid); return; } } /** PUT on the collection itself uploads an ICS of the entire collection. */ if (StrLength(dav_uid) == 0) { dav_put_bigics(); FreeStrBuf(&dav_roomname); FreeStrBuf(&dav_uid); return; } /* * We are cleared for upload! We use the new calling syntax for ENT0 * which allows a confirmation to be sent back to us. That's how we * extract the message ID. */ serv_puts("ENT0 1|||4|||1|"); serv_getln(buf, sizeof buf); if (buf[0] != '8') { hprintf("HTTP/1.1 502 Bad Gateway\r\n"); dav_common_headers(); hprintf("Content-type: text/plain\r\n"); begin_burst(); wc_printf("%s\r\n", &buf[4]); end_burst(); return; } /* Send the content to the Citadel server */ //serv_printf("Content-type: %s\n\n", WCC->upload_content_type); serv_putbuf(WCC->upload); serv_puts("\n000"); /* Fetch the reply from the Citadel server */ n = 0; FlushStrBuf(dav_uid); while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { switch(n++) { case 0: new_msgnum = atol(buf); break; case 1: syslog(LOG_DEBUG, "new_msgnum=%ld (%s)\n", new_msgnum, buf); break; case 2: StrBufAppendBufPlain(dav_uid, buf, -1, 0); break; default: break; } } /* Tell the client what happened. */ /* Citadel failed in some way? */ if (new_msgnum < 0L) { hprintf("HTTP/1.1 502 Bad Gateway\r\n"); dav_common_headers(); hprintf("Content-type: text/plain\r\n"); begin_burst(); wc_printf("new_msgnum is %ld\r\n" "\r\n", new_msgnum); end_burst(); FreeStrBuf(&dav_roomname); FreeStrBuf(&dav_uid); return; } /* We created this item for the first time. */ if (old_msgnum < 0L) { char escaped_uid[1024]; hprintf("HTTP/1.1 201 Created\r\n"); syslog(LOG_DEBUG, "HTTP/1.1 201 Created\r\n"); dav_common_headers(); hprintf("etag: \"%ld\"\r\n", new_msgnum); hprintf("Location: "); dav_identify_hosthdr(); hprintf("/groupdav/");/* TODO */ hurlescputs(ChrPtr(dav_roomname)); euid_escapize(escaped_uid, ChrPtr(dav_uid)); hprintf("/%s\r\n", escaped_uid); end_burst(); FreeStrBuf(&dav_roomname); FreeStrBuf(&dav_uid); return; } /* We modified an existing item. */ hprintf("HTTP/1.1 204 No Content\r\n"); syslog(LOG_DEBUG, "HTTP/1.1 204 No Content\r\n"); dav_common_headers(); hprintf("Etag: \"%ld\"\r\n", new_msgnum); /* The item we replaced has probably already been deleted by * the Citadel server, but we'll do this anyway, just in case. */ serv_printf("DELE %ld", old_msgnum); serv_getln(buf, sizeof buf); begin_burst(); end_burst(); FreeStrBuf(&dav_roomname); FreeStrBuf(&dav_uid); return; }
/* * RSS feed generator -- do one message */ void feed_rss_one_message(long msgnum) { int in_body = 0; int in_messagetext = 0; int found_title = 0; int found_guid = 0; char pubdate[128]; StrBuf *messagetext = NULL; int is_top_level_post = 1; const char *BufPtr = NULL; StrBuf *Line = NewStrBufPlain(NULL, 1024); char buf[1024]; int permalink_hash = 0; /* Phase 1: read the message into memory */ serv_printf("MSG4 %ld", msgnum); serv_getln(buf, sizeof buf); if (buf[0] != '1') return; StrBuf *ServerResponse = NewStrBuf(); while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { StrBufAppendPrintf(ServerResponse, "%s\n", buf); } /* Phase 2: help SkyNet become self-aware */ BufPtr = NULL; while (StrBufSipLine(Line, ServerResponse, &BufPtr), ((BufPtr!=StrBufNOTNULL)&&(BufPtr!=NULL)) ) { if (in_body) { /* do nothing */ } else if (StrLength(Line) == 0) { ++in_body; } else if ((StrLength(Line) > 5) && (!strncasecmp(ChrPtr(Line), "wefw=", 5))) { is_top_level_post = 0; /* presence of references means it's a reply/comment */ } else if ((StrLength(Line) > 5) && (!strncasecmp(ChrPtr(Line), "msgn=", 5))) { StrBufCutLeft(Line, 5); permalink_hash = ThreadIdHash(Line); } } /* * Phase 3: output the message in RSS <item> form * (suppress replies [comments] if this is a blog room) */ if ( (WC->CurRoom.view != VIEW_BLOG) || (is_top_level_post == 1) ) { wc_printf("<item>"); wc_printf("<link>%s/readfwd?go=", ChrPtr(site_prefix)); urlescputs(ChrPtr(WC->CurRoom.name)); if ((WC->CurRoom.view == VIEW_BLOG) && (permalink_hash != 0)) { wc_printf("?p=%d", permalink_hash); } else { wc_printf("?start_reading_at=%ld", msgnum); } wc_printf("</link>"); BufPtr = NULL; in_body = 0; in_messagetext = 0; while (StrBufSipLine(Line, ServerResponse, &BufPtr), ((BufPtr!=StrBufNOTNULL)&&(BufPtr!=NULL)) ) { safestrncpy(buf, ChrPtr(Line), sizeof buf); /* XML parsers can be picky; strip out nonprintable header characters */ if ((strlen(buf)>=6) && (buf[4]=='=')) { char *p = &buf[5]; while (*p) { if (!isprint(*p)) { *p = 0; } ++p; } } /* Now output fields */ if (in_body) { if (in_messagetext) { StrBufAppendBufPlain(messagetext, buf, -1, 0); StrBufAppendBufPlain(messagetext, HKEY("\r\n"), 0); } else if (IsEmptyStr(buf)) { in_messagetext = 1; } } else if (!strncasecmp(buf, "subj=", 5)) { wc_printf("<title>"); escputs(&buf[5]); wc_printf("</title>"); ++found_title; } else if (!strncasecmp(buf, "exti=", 5)) { wc_printf("<guid isPermaLink=\"false\">"); escputs(&buf[5]); wc_printf("</guid>"); ++found_guid; } else if (!strncasecmp(buf, "time=", 5)) { http_datestring(pubdate, sizeof pubdate, atol(&buf[5])); wc_printf("<pubDate>%s</pubDate>", pubdate); } else if (!strncasecmp(buf, "text", 4)) { if (!found_title) { wc_printf("<title>Message #%ld</title>", msgnum); } if (!found_guid) { wc_printf("<guid isPermaLink=\"false\">%ld@%s</guid>", msgnum, ChrPtr(WC->serv_info->serv_humannode) ); } wc_printf("<description>"); in_body = 1; messagetext = NewStrBuf(); } } if (in_body) { cdataout((char*)ChrPtr(messagetext)); FreeStrBuf(&messagetext); wc_printf("</description>"); } wc_printf("</item>"); } FreeStrBuf(&Line); FreeStrBuf(&ServerResponse); return; }
void display_pushemail(void) { folder Room; int Done = 0; StrBuf *Buf; long vector[8] = {8, 0, 0, 1, 2, 3, 4, 5}; WCTemplputParams SubTP; char mobnum[20]; StackContext(NULL, &SubTP, &vector, CTX_LONGVECTOR, 0, NULL); vector[0] = 16; /* Find any existing settings*/ Buf = NewStrBuf(); memset(&Room, 0, sizeof(folder)); if (goto_config_room(Buf, &Room) == 0) { int msgnum = 0; serv_puts("MSGS ALL|0|1"); StrBuf_ServGetln(Buf); if (GetServerStatus(Buf, NULL) == 8) { serv_puts("subj|__ Push email settings __"); serv_puts("000"); while (!Done && StrBuf_ServGetln(Buf) >= 0) { if ( (StrLength(Buf)==3) && !strcmp(ChrPtr(Buf), "000")) { Done = 1; break; } msgnum = StrTol(Buf); } } if (msgnum > 0L) { serv_printf("MSG0 %d", msgnum); StrBuf_ServGetln(Buf); if (GetServerStatus(Buf, NULL) == 1) { int i =0; Done = 0; while (!Done && StrBuf_ServGetln(Buf) >= 0) { if (( (StrLength(Buf)==3) && !strcmp(ChrPtr(Buf), "000"))|| ((StrLength(Buf)==4) && !strcmp(ChrPtr(Buf), "text"))) { Done = 1; break; } } if (!strcmp(ChrPtr(Buf), "text")) { Done = 0; while (!Done && StrBuf_ServGetln(Buf) >= 0) { if ( (StrLength(Buf)==3) && !strcmp(ChrPtr(Buf), "000")) { Done = 1; break; } if (strncasecmp(ChrPtr(Buf), "none", 4) == 0) { vector[1] = 0; } else if (strncasecmp(ChrPtr(Buf), "textmessage", 11) == 0) { vector[1] = 1; i++; } else if (strncasecmp(ChrPtr(Buf), "funambol", 8) == 0) { vector[1] = 2; } else if (strncasecmp(ChrPtr(Buf), "httpmessage", 12) == 0) { vector[1] = 3; } else if (i == 1) { strncpy(mobnum, ChrPtr(Buf), 20); i++; } } } } } serv_printf("GOTO %s", ChrPtr(WC->CurRoom.name)); StrBuf_ServGetln(Buf); GetServerStatus(Buf, NULL); } FlushFolder(&Room); output_headers(1, 1, 1, 0, 0, 0); DoTemplate(HKEY("prefs_pushemail"), NULL, &SubTP); wDumpContent(1); UnStackContext(&SubTP); FreeStrBuf(&Buf); }