- offer to not call the msg hooks (and set the preivous default in all places)
- move the serialization of messages into own functions
- split saving of messages and saving of new messages and make them use each other
Fix import / export
- don't use fingercount strlen(), CPP can do that way better.
- properly de-serialize messages so we know they're good.
- don't roll our own message saving facilities, use the common one (which then also does the big message data splitting)
conf = NULL;
}
else {
- msg = CtdlFetchMessage(msgnum, 1);
+ msg = CtdlFetchMessage(msgnum, 1, 1);
if (msg != NULL) {
conf = strdup(msg->cm_fields[eMesageText]);
CM_Free(msg);
void rebuild_euid_index_for_msg(long msgnum, void *userdata) {
struct CtdlMessage *msg = NULL;
- msg = CtdlFetchMessage(msgnum, 0);
+ msg = CtdlFetchMessage(msgnum, 0, 1);
if (msg == NULL) return;
if (!CM_IsEmpty(msg, eExclusiveID)) {
index_message_by_euid(msg->cm_fields[eExclusiveID], &CC->room, msgnum);
int i = 0;
char *nnn = NULL;
- msg = CtdlFetchMessage(msgnum, 1);
+ msg = CtdlFetchMessage(msgnum, 1, 1);
if (msg == NULL) return;
v = vcard_load(msg->cm_fields[eMesageText]);
return;
}
- msg = CtdlFetchMessage(msgnum, 1);
+ msg = CtdlFetchMessage(msgnum, 1, 1);
if (msg == NULL) {
cprintf("%d Message %ld not found.\n",
ERROR + ILLEGAL_VALUE,
* us the ability to load the event into memory so we can diddle the
* attendees.
*/
- msg = CtdlFetchMessage(msgnum_being_replaced, 1);
+ msg = CtdlFetchMessage(msgnum_being_replaced, 1, 1);
if (msg == NULL) {
return(2); /* internal error */
}
return;
}
- msg = CtdlFetchMessage(msgnum, 1);
+ msg = CtdlFetchMessage(msgnum, 1, 1);
if (msg == NULL) {
cprintf("%d Message %ld not found.\n",
ERROR + ILLEGAL_VALUE,
proposed_event = (icalcomponent *)data;
- msg = CtdlFetchMessage(msgnum, 1);
+ msg = CtdlFetchMessage(msgnum, 1, 1);
if (msg == NULL) return;
memset(&ird, 0, sizeof ird);
strcpy(ird.desired_partnum, "_HUNT_");
struct CtdlMessage *msg = NULL;
struct ical_respond_data ird;
- msg = CtdlFetchMessage(msgnum, 1);
+ msg = CtdlFetchMessage(msgnum, 1, 1);
if (msg == NULL) {
cprintf("%d Message %ld not found\n",
ERROR + ILLEGAL_VALUE,
fb = (icalcomponent *)data; /* User-supplied data will be the VFREEBUSY component */
- msg = CtdlFetchMessage(msgnum, 1);
+ msg = CtdlFetchMessage(msgnum, 1, 1);
if (msg == NULL) return;
memset(&ird, 0, sizeof ird);
strcpy(ird.desired_partnum, "_HUNT_");
/* Look for the calendar event... */
- msg = CtdlFetchMessage(msgnum, 1);
+ msg = CtdlFetchMessage(msgnum, 1, 1);
if (msg == NULL) return;
memset(&ird, 0, sizeof ird);
strcpy(ird.desired_partnum, "_HUNT_");
{
struct CtdlMessage *msg;
- msg = CtdlFetchMessage(msgnum, 0);
+ msg = CtdlFetchMessage(msgnum, 0, 1);
if (msg == NULL) {
cprintf("%ld|0|||||\n", msgnum);
return;
{
struct CtdlMessage *msg;
- msg = CtdlFetchMessage(msgnum, 0);
+ msg = CtdlFetchMessage(msgnum, 0, 1);
if (msg == NULL) {
cprintf("%ld||\n", msgnum);
return;
}
msgnum = extract_long(cmdbuf, 0);
- msg = CtdlFetchMessage(msgnum, 1);
+ msg = CtdlFetchMessage(msgnum, 1, 1);
if (msg == NULL) {
cprintf("%d Message %ld not found.\n",
ERROR + MESSAGE_NOT_FOUND, msgnum);
for (a=0; a<num_msgs; ++a) {
delnum = msglist[a];
- msg = CtdlFetchMessage(delnum, 0); /* dont need body */
+ msg = CtdlFetchMessage(delnum, 0, 1); /* dont need body */
if (msg != NULL) {
xtime = atol(msg->cm_fields[eTimestamp]);
CM_Free(msg);
memcpy(&msgnum, cdbei->ptr, sizeof(long));
- msg = CtdlFetchMessage(msgnum, 0);
+ msg = CtdlFetchMessage(msgnum, 0, 1);
if (msg != NULL) {
CM_Free(msg); /* it still exists, so do nothing */
}
return eNone; /* No messages at all? No further action. */
}
for (a = 0; a < num_msgs; ++a) {
- msg = CtdlFetchMessage(msglist[a], 1);
+ msg = CtdlFetchMessage(msglist[a], 1, 1);
if (msg != NULL) {
if (!CM_IsEmpty(msg, eMsgSubject) &&
(strncasecmp(msg->cm_fields[eMsgSubject],
Ctx = (NotifyContext*) usrdata;
- msg = CtdlFetchMessage(NotifyMsgnum, 1);
+ msg = CtdlFetchMessage(NotifyMsgnum, 1, 1);
if (!CM_IsEmpty(msg, eExtnotify))
{
Type = extNotify_getConfigMessage(
int tok;
struct CtdlMessage *msg = NULL;
- msg = CtdlFetchMessage(msgnum, 1);
+ msg = CtdlFetchMessage(msgnum, 1, 1);
if (msg == NULL) {
syslog(LOG_ERR, "ft_index_message() could not load msg %ld", msgnum);
return;
if (Imap->cached_body == NULL) {
CCC->redirect_buffer = NewStrBufPlain(NULL, SIZ);
loading_body_now = 1;
- msg = CtdlFetchMessage(msgnum, (need_body ? 1 : 0));
+ msg = CtdlFetchMessage(msgnum, (need_body ? 1 : 0), 1);
}
/* Now figure out what the client wants, and get it */
msg = NULL;
}
if (msg == NULL) {
- msg = CtdlFetchMessage(Imap->msgids[seq-1], 1);
+ msg = CtdlFetchMessage(Imap->msgids[seq-1], 1, 1);
body_loaded = 1;
}
imap_fetch_bodystructure(Imap->msgids[seq-1],
}
else if (!strcasecmp(Cmd->Params[i].Key, "ENVELOPE")) {
if (msg == NULL) {
- msg = CtdlFetchMessage(Imap->msgids[seq-1], 0);
+ msg = CtdlFetchMessage(Imap->msgids[seq-1], 0, 1);
body_loaded = 0;
}
imap_fetch_envelope(msg);
}
else if (!strcasecmp(Cmd->Params[i].Key, "INTERNALDATE")) {
if (msg == NULL) {
- msg = CtdlFetchMessage(Imap->msgids[seq-1], 0);
+ msg = CtdlFetchMessage(Imap->msgids[seq-1], 0, 1);
body_loaded = 0;
}
imap_fetch_internaldate(msg);
else if (!strcasecmp(itemlist[pos].Key, "BCC")) {
if (msg == NULL) {
- msg = CtdlFetchMessage(Imap->msgids[seq-1], 1);
+ msg = CtdlFetchMessage(Imap->msgids[seq-1], 1, 1);
need_to_free_msg = 1;
}
if (msg != NULL) {
else if (!strcasecmp(itemlist[pos].Key, "BEFORE")) {
if (msg == NULL) {
- msg = CtdlFetchMessage(Imap->msgids[seq-1], 1);
+ msg = CtdlFetchMessage(Imap->msgids[seq-1], 1, 1);
need_to_free_msg = 1;
}
if (msg != NULL) {
/* Otherwise, we have to do a slow search. */
else {
if (msg == NULL) {
- msg = CtdlFetchMessage(Imap->msgids[seq-1], 1);
+ msg = CtdlFetchMessage(Imap->msgids[seq-1], 1, 1);
need_to_free_msg = 1;
}
if (msg != NULL) {
else if (!strcasecmp(itemlist[pos].Key, "CC")) {
if (msg == NULL) {
- msg = CtdlFetchMessage(Imap->msgids[seq-1], 1);
+ msg = CtdlFetchMessage(Imap->msgids[seq-1], 1, 1);
need_to_free_msg = 1;
}
if (msg != NULL) {
else if (!strcasecmp(itemlist[pos].Key, "FROM")) {
if (msg == NULL) {
- msg = CtdlFetchMessage(Imap->msgids[seq-1], 1);
+ msg = CtdlFetchMessage(Imap->msgids[seq-1], 1, 1);
need_to_free_msg = 1;
}
if (msg != NULL) {
* examining the message body.
*/
if (msg == NULL) {
- msg = CtdlFetchMessage(Imap->msgids[seq-1], 1);
+ msg = CtdlFetchMessage(Imap->msgids[seq-1], 1, 1);
need_to_free_msg = 1;
}
else if (!strcasecmp(itemlist[pos].Key, "LARGER")) {
if (msg == NULL) {
- msg = CtdlFetchMessage(Imap->msgids[seq-1], 1);
+ msg = CtdlFetchMessage(Imap->msgids[seq-1], 1, 1);
need_to_free_msg = 1;
}
if (msg != NULL) {
else if (!strcasecmp(itemlist[pos].Key, "ON")) {
if (msg == NULL) {
- msg = CtdlFetchMessage(Imap->msgids[seq-1], 1);
+ msg = CtdlFetchMessage(Imap->msgids[seq-1], 1, 1);
need_to_free_msg = 1;
}
if (msg != NULL) {
else if (!strcasecmp(itemlist[pos].Key, "SENTBEFORE")) {
if (msg == NULL) {
- msg = CtdlFetchMessage(Imap->msgids[seq-1], 1);
+ msg = CtdlFetchMessage(Imap->msgids[seq-1], 1, 1);
need_to_free_msg = 1;
}
if (msg != NULL) {
else if (!strcasecmp(itemlist[pos].Key, "SENTON")) {
if (msg == NULL) {
- msg = CtdlFetchMessage(Imap->msgids[seq-1], 1);
+ msg = CtdlFetchMessage(Imap->msgids[seq-1], 1, 1);
need_to_free_msg = 1;
}
if (msg != NULL) {
else if (!strcasecmp(itemlist[pos].Key, "SENTSINCE")) {
if (msg == NULL) {
- msg = CtdlFetchMessage(Imap->msgids[seq-1], 1);
+ msg = CtdlFetchMessage(Imap->msgids[seq-1], 1, 1);
need_to_free_msg = 1;
}
if (msg != NULL) {
else if (!strcasecmp(itemlist[pos].Key, "SINCE")) {
if (msg == NULL) {
- msg = CtdlFetchMessage(Imap->msgids[seq-1], 1);
+ msg = CtdlFetchMessage(Imap->msgids[seq-1], 1, 1);
need_to_free_msg = 1;
}
if (msg != NULL) {
else if (!strcasecmp(itemlist[pos].Key, "SMALLER")) {
if (msg == NULL) {
- msg = CtdlFetchMessage(Imap->msgids[seq-1], 1);
+ msg = CtdlFetchMessage(Imap->msgids[seq-1], 1, 1);
need_to_free_msg = 1;
}
if (msg != NULL) {
else if (!strcasecmp(itemlist[pos].Key, "SUBJECT")) {
if (msg == NULL) {
- msg = CtdlFetchMessage(Imap->msgids[seq-1], 1);
+ msg = CtdlFetchMessage(Imap->msgids[seq-1], 1, 1);
need_to_free_msg = 1;
}
if (msg != NULL) {
else if (!strcasecmp(itemlist[pos].Key, "TEXT")) {
if (msg == NULL) {
- msg = CtdlFetchMessage(Imap->msgids[seq-1], 1);
+ msg = CtdlFetchMessage(Imap->msgids[seq-1], 1, 1);
need_to_free_msg = 1;
}
if (msg != NULL) {
else if (!strcasecmp(itemlist[pos].Key, "TO")) {
if (msg == NULL) {
- msg = CtdlFetchMessage(Imap->msgids[seq-1], 1);
+ msg = CtdlFetchMessage(Imap->msgids[seq-1], 1, 1);
need_to_free_msg = 1;
}
if (msg != NULL) {
void inetcfg_init_backend(long msgnum, void *userdata) {
struct CtdlMessage *msg;
- msg = CtdlFetchMessage(msgnum, 1);
+ msg = CtdlFetchMessage(msgnum, 1, 1);
if (msg != NULL) {
inetcfg_setTo(msg);
CM_Free(msg);
while (*c != 0) {
if (*c == '\"') {
- client_write(""", 6);
+ client_write(HKEY("""));
}
else if (*c == '\'') {
- client_write("'", 6);
+ client_write(HKEY("'"));
}
else if (*c == '<') {
- client_write("<", 4);
+ client_write(HKEY("<"));
}
else if (*c == '>') {
- client_write(">", 4);
+ client_write(HKEY(">"));
}
else if (*c == '&') {
- client_write("&", 5);
+ client_write(HKEY("&"));
}
else {
client_write(c, 1);
* Export a user record as XML
*/
void migr_export_users_backend(struct ctdluser *buf, void *data) {
- client_write("<user>\n", 7);
+ client_write(HKEY("<user>\n"));
cprintf("<u_version>%d</u_version>\n", buf->version);
cprintf("<u_uid>%ld</u_uid>\n", (long)buf->uid);
- client_write("<u_password>", 12); xml_strout(buf->password); client_write("</u_password>\n", 14);
+ client_write(HKEY("<u_password>")); xml_strout(buf->password); client_write(HKEY("</u_password>\n"));
cprintf("<u_flags>%u</u_flags>\n", buf->flags);
cprintf("<u_timescalled>%ld</u_timescalled>\n", buf->timescalled);
cprintf("<u_posted>%ld</u_posted>\n", buf->posted);
cprintf("<u_usernum>%ld</u_usernum>\n", buf->usernum);
cprintf("<u_lastcall>%ld</u_lastcall>\n", (long)buf->lastcall);
cprintf("<u_USuserpurge>%d</u_USuserpurge>\n", buf->USuserpurge);
- client_write("<u_fullname>", 12); xml_strout(buf->fullname); client_write("</u_fullname>\n", 14);
- client_write("</user>\n", 8);
+ client_write(HKEY("<u_fullname>")); xml_strout(buf->fullname); client_write(HKEY("</u_fullname>\n"));
+ client_write(HKEY("</user>\n"));
}
void migr_export_rooms_backend(struct ctdlroom *buf, void *data) {
- client_write("<room>\n", 7);
- client_write("<QRname>", 8); xml_strout(buf->QRname); client_write("</QRname>\n", 10);
- client_write("<QRpasswd>", 10); xml_strout(buf->QRpasswd); client_write("</QRpasswd>\n", 12);
+ client_write(HKEY("<room>\n"));
+ client_write(HKEY("<QRname>")); xml_strout(buf->QRname); client_write(HKEY("</QRname>\n"));
+ client_write(HKEY("<QRpasswd>")); xml_strout(buf->QRpasswd); client_write(HKEY("</QRpasswd>\n"));
cprintf("<QRroomaide>%ld</QRroomaide>\n", buf->QRroomaide);
cprintf("<QRhighest>%ld</QRhighest>\n", buf->QRhighest);
cprintf("<QRgen>%ld</QRgen>\n", (long)buf->QRgen);
cprintf("<QRflags>%u</QRflags>\n", buf->QRflags);
if (buf->QRflags & QR_DIRECTORY) {
- client_write("<QRdirname>", 11);
+ client_write(HKEY("<QRdirname>"));
xml_strout(buf->QRdirname);
- client_write("</QRdirname>\n", 13);
+ client_write(HKEY("</QRdirname>\n"));
}
cprintf("<QRinfo>%ld</QRinfo>\n", buf->QRinfo);
cprintf("<QRfloor>%d</QRfloor>\n", buf->QRfloor);
cprintf("<QRorder>%d</QRorder>\n", buf->QRorder);
cprintf("<QRflags2>%u</QRflags2>\n", buf->QRflags2);
cprintf("<QRdefaultview>%d</QRdefaultview>\n", buf->QRdefaultview);
- client_write("</room>\n", 8);
+ client_write(HKEY("</room>\n"));
/* message list goes inside this tag */
CtdlGetRoom(&CC->room, buf->QRname);
- client_write("<room_messages>", 15);
- client_write("<FRname>", 8); xml_strout(CC->room.QRname); client_write("</FRname>\n", 10);
- client_write("<FRmsglist>", 11);
+ client_write(HKEY("<room_messages>"));
+ client_write(HKEY("<FRname>")); xml_strout(CC->room.QRname); client_write(HKEY("</FRname>\n"));
+ client_write(HKEY("<FRmsglist>"));
CtdlForEachMessage(MSGS_ALL, 0L, NULL, NULL, NULL, migr_export_room_msg, NULL);
- client_write("</FRmsglist>\n", 13);
- client_write("</room_messages>\n", 17);
+ client_write(HKEY("</FRmsglist>\n"));
+ client_write(HKEY("</room_messages>\n"));
}
int i;
for (i=0; i < MAXFLOORS; ++i) {
- client_write("<floor>\n", 8);
+ client_write(HKEY("<floor>\n"));
cprintf("<f_num>%d</f_num>\n", i);
CtdlGetFloor(&qfbuf, i);
buf = &qfbuf;
cprintf("<f_flags>%u</f_flags>\n", buf->f_flags);
- client_write("<f_name>", 8); xml_strout(buf->f_name); client_write("</f_name>\n", 10);
+ client_write(HKEY("<f_name>")); xml_strout(buf->f_name); client_write(HKEY("</f_name>\n"));
cprintf("<f_ref_count>%d</f_ref_count>\n", buf->f_ref_count);
cprintf("<f_ep_expire_mode>%d</f_ep_expire_mode>\n", buf->f_ep.expire_mode);
cprintf("<f_ep_expire_value>%d</f_ep_expire_value>\n", buf->f_ep.expire_value);
- client_write("</floor>\n", 9);
+ client_write(HKEY("</floor>\n"));
}
}
sizeof(visit) : cdbv->len));
cdb_free(cdbv);
- client_write("<visit>\n", 8);
+ client_write(HKEY("<visit>\n"));
cprintf("<v_roomnum>%ld</v_roomnum>\n", vbuf.v_roomnum);
cprintf("<v_roomgen>%ld</v_roomgen>\n", vbuf.v_roomgen);
cprintf("<v_usernum>%ld</v_usernum>\n", vbuf.v_usernum);
- client_write("<v_seen>", 8);
+ client_write(HKEY("<v_seen>"));
if ( (!IsEmptyStr(vbuf.v_seen)) && (is_sequence_set(vbuf.v_seen)) ) {
xml_strout(vbuf.v_seen);
}
else {
cprintf("%ld", vbuf.v_lastseen);
}
- client_write("</v_seen>", 9);
+ client_write(HKEY("</v_seen>"));
if ( (!IsEmptyStr(vbuf.v_answered)) && (is_sequence_set(vbuf.v_answered)) ) {
- client_write("<v_answered>", 12);
+ client_write(HKEY("<v_answered>"));
xml_strout(vbuf.v_answered);
- client_write("</v_answered>\n", 14);
+ client_write(HKEY("</v_answered>\n"));
}
cprintf("<v_flags>%u</v_flags>\n", vbuf.v_flags);
cprintf("<v_view>%d</v_view>\n", vbuf.v_view);
- client_write("</visit>\n", 9);
+ client_write(HKEY("</visit>\n"));
}
}
/* Ok, here we go ... */
- msg = CtdlFetchMessage(msgnum, 1);
+ msg = CtdlFetchMessage(msgnum, 1, 0);
if (msg == NULL) return; /* fail silently */
- client_write("<message>\n", 10);
+ client_write(HKEY("<message>\n"));
GetMetaData(&smi, msgnum);
cprintf("<msg_msgnum>%ld</msg_msgnum>\n", msgnum);
cprintf("<msg_meta_refcount>%d</msg_meta_refcount>\n", smi.meta_refcount);
- client_write("<msg_meta_content_type>", 23); xml_strout(smi.meta_content_type); client_write("</msg_meta_content_type>\n", 25);
+ client_write(HKEY("<msg_meta_content_type>")); xml_strout(smi.meta_content_type); client_write(HKEY("</msg_meta_content_type>\n"));
- client_write("<msg_text>", 10);
+ client_write(HKEY("<msg_text>"));
CtdlSerializeMessage(&smr, msg);
CM_Free(msg);
free(smr.ser);
- client_write("</msg_text>\n", 12);
- client_write("</message>\n", 11);
+ client_write(HKEY("</msg_text>\n"));
+ client_write(HKEY("</message>\n"));
}
cdb_rewind(CDB_OPENID);
while (cdboi = cdb_next_item(CDB_OPENID), cdboi != NULL) {
if (cdboi->len > sizeof(long)) {
- client_write("<openid>\n", 9);
+ client_write(HKEY("<openid>\n"));
memcpy(&usernum, cdboi->ptr, sizeof(long));
snprintf(url, sizeof url, "%s", (cdboi->ptr)+sizeof(long) );
- client_write("<oid_url>", 9);
+ client_write(HKEY("<oid_url>"));
xml_strout(url);
- client_write("</oid_url>\n", 11);
+ client_write(HKEY("</oid_url>\n"));
cprintf("<oid_usernum>%ld</oid_usernum>\n", usernum);
- client_write("</openid>\n", 10);
+ client_write(HKEY("</openid>\n"));
}
cdb_free(cdboi);
}
cprintf("%d Exporting all Citadel databases.\n", LISTING_FOLLOWS);
Ctx->dont_term = 1;
- client_write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n", 40);
- client_write("<citadel_migrate_data>\n", 23);
+ client_write(HKEY("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"));
+ client_write(HKEY("<citadel_migrate_data>\n"));
cprintf("<version>%d</version>\n", REV_LEVEL);
cprintf("<progress>%d</progress>\n", 0);
/* export the config file (this is done using x-macros) */
- client_write("<config>\n", 9);
- client_write("<c_nodename>", 12); xml_strout(config.c_nodename); client_write("</c_nodename>\n", 14);
- client_write("<c_fqdn>", 8); xml_strout(config.c_fqdn); client_write("</c_fqdn>\n", 10);
- client_write("<c_humannode>", 13); xml_strout(config.c_humannode); client_write("</c_humannode>\n", 15);
- client_write("<c_phonenum>", 12); xml_strout(config.c_phonenum); client_write("</c_phonenum>\n", 14);
+ client_write(HKEY("<config>\n"));
+ client_write(HKEY("<c_nodename>")); xml_strout(config.c_nodename); client_write(HKEY("</c_nodename>\n"));
+ client_write(HKEY("<c_fqdn>")); xml_strout(config.c_fqdn); client_write(HKEY("</c_fqdn>\n"));
+ client_write(HKEY("<c_humannode>")); xml_strout(config.c_humannode); client_write(HKEY("</c_humannode>\n"));
+ client_write(HKEY("<c_phonenum>")); xml_strout(config.c_phonenum); client_write(HKEY("</c_phonenum>\n"));
cprintf("<c_ctdluid>%d</c_ctdluid>\n", config.c_ctdluid);
cprintf("<c_creataide>%d</c_creataide>\n", config.c_creataide);
cprintf("<c_sleeping>%d</c_sleeping>\n", config.c_sleeping);
cprintf("<c_initax>%d</c_initax>\n", config.c_initax);
cprintf("<c_regiscall>%d</c_regiscall>\n", config.c_regiscall);
cprintf("<c_twitdetect>%d</c_twitdetect>\n", config.c_twitdetect);
- client_write("<c_twitroom>", 12); xml_strout(config.c_twitroom); client_write("</c_twitroom>\n", 14);
- client_write("<c_moreprompt>", 14); xml_strout(config.c_moreprompt); client_write("</c_moreprompt>\n", 16);
+ client_write(HKEY("<c_twitroom>")); xml_strout(config.c_twitroom); client_write(HKEY("</c_twitroom>\n"));
+ client_write(HKEY("<c_moreprompt>")); xml_strout(config.c_moreprompt); client_write(HKEY("</c_moreprompt>\n"));
cprintf("<c_restrict>%d</c_restrict>\n", config.c_restrict);
- client_write("<c_site_location>", 17); xml_strout(config.c_site_location); client_write("</c_site_location>\n", 19);
- client_write("<c_sysadm>", 10); xml_strout(config.c_sysadm); client_write("</c_sysadm>\n", 12);
+ client_write(HKEY("<c_site_location>")); xml_strout(config.c_site_location); client_write(HKEY("</c_site_location>\n"));
+ client_write(HKEY("<c_sysadm>")); xml_strout(config.c_sysadm); client_write(HKEY("</c_sysadm>\n"));
cprintf("<c_maxsessions>%d</c_maxsessions>\n", config.c_maxsessions);
- client_write("<c_ip_addr>", 11); xml_strout(config.c_ip_addr); client_write("</c_ip_addr>\n", 13);
+ client_write(HKEY("<c_ip_addr>")); xml_strout(config.c_ip_addr); client_write(HKEY("</c_ip_addr>\n"));
cprintf("<c_port_number>%d</c_port_number>\n", config.c_port_number);
cprintf("<c_ep_expire_mode>%d</c_ep_expire_mode>\n", config.c_ep.expire_mode);
cprintf("<c_ep_expire_value>%d</c_ep_expire_value>\n", config.c_ep.expire_value);
cprintf("<c_userpurge>%d</c_userpurge>\n", config.c_userpurge);
cprintf("<c_roompurge>%d</c_roompurge>\n", config.c_roompurge);
- client_write("<c_logpages>", 12); xml_strout(config.c_logpages); client_write("</c_logpages>\n", 14);
+ client_write(HKEY("<c_logpages>")); xml_strout(config.c_logpages); client_write(HKEY("</c_logpages>\n"));
cprintf("<c_createax>%d</c_createax>\n", config.c_createax);
cprintf("<c_maxmsglen>%ld</c_maxmsglen>\n", config.c_maxmsglen);
cprintf("<c_min_workers>%d</c_min_workers>\n", config.c_min_workers);
cprintf("<c_net_freq>%ld</c_net_freq>\n", config.c_net_freq);
cprintf("<c_disable_newu>%d</c_disable_newu>\n", config.c_disable_newu);
cprintf("<c_enable_fulltext>%d</c_enable_fulltext>\n", config.c_enable_fulltext);
- client_write("<c_baseroom>", 12); xml_strout(config.c_baseroom); client_write("</c_baseroom>\n", 14);
- client_write("<c_aideroom>", 12); xml_strout(config.c_aideroom); client_write("</c_aideroom>\n", 14);
+ client_write(HKEY("<c_baseroom>")); xml_strout(config.c_baseroom); client_write(HKEY("</c_baseroom>\n"));
+ client_write(HKEY("<c_aideroom>")); xml_strout(config.c_aideroom); client_write(HKEY("</c_aideroom>\n"));
cprintf("<c_purge_hour>%d</c_purge_hour>\n", config.c_purge_hour);
cprintf("<c_mbxep_expire_mode>%d</c_mbxep_expire_mode>\n", config.c_mbxep.expire_mode);
cprintf("<c_mbxep_expire_value>%d</c_mbxep_expire_value>\n", config.c_mbxep.expire_value);
- client_write("<c_ldap_host>", 13); xml_strout(config.c_ldap_host); client_write("</c_ldap_host>\n", 15);
+ client_write(HKEY("<c_ldap_host>")); xml_strout(config.c_ldap_host); client_write(HKEY("</c_ldap_host>\n"));
cprintf("<c_ldap_port>%d</c_ldap_port>\n", config.c_ldap_port);
- client_write("<c_ldap_base_dn>", 16); xml_strout(config.c_ldap_base_dn); client_write("</c_ldap_base_dn>\n", 18);
- client_write("<c_ldap_bind_dn>", 16); xml_strout(config.c_ldap_bind_dn); client_write("</c_ldap_bind_dn>\n", 18);
- client_write("<c_ldap_bind_pw>", 16); xml_strout(config.c_ldap_bind_pw); client_write("</c_ldap_bind_pw>\n", 18);
+ client_write(HKEY("<c_ldap_base_dn>")); xml_strout(config.c_ldap_base_dn); client_write(HKEY("</c_ldap_base_dn>\n"));
+ client_write(HKEY("<c_ldap_bind_dn>")); xml_strout(config.c_ldap_bind_dn); client_write(HKEY("</c_ldap_bind_dn>\n"));
+ client_write(HKEY("<c_ldap_bind_pw>")); xml_strout(config.c_ldap_bind_pw); client_write(HKEY("</c_ldap_bind_pw>\n"));
cprintf("<c_msa_port>%d</c_msa_port>\n", config.c_msa_port);
cprintf("<c_imaps_port>%d</c_imaps_port>\n", config.c_imaps_port);
cprintf("<c_pop3s_port>%d</c_pop3s_port>\n", config.c_pop3s_port);
cprintf("<c_allow_spoofing>%d</c_allow_spoofing>\n", config.c_allow_spoofing);
cprintf("<c_journal_email>%d</c_journal_email>\n", config.c_journal_email);
cprintf("<c_journal_pubmsgs>%d</c_journal_pubmsgs>\n", config.c_journal_pubmsgs);
- client_write("<c_journal_dest>", 16); xml_strout(config.c_journal_dest); client_write("</c_journal_dest>\n", 18);
- client_write("<c_default_cal_zone>", 20); xml_strout(config.c_default_cal_zone); client_write("</c_default_cal_zone>\n", 22);
+ client_write(HKEY("<c_journal_dest>")); xml_strout(config.c_journal_dest); client_write(HKEY("</c_journal_dest>\n"));
+ client_write(HKEY("<c_default_cal_zone>")); xml_strout(config.c_default_cal_zone); client_write(HKEY("</c_default_cal_zone>\n"));
cprintf("<c_pftcpdict_port>%d</c_pftcpdict_port>\n", config.c_pftcpdict_port);
cprintf("<c_managesieve_port>%d</c_managesieve_port>\n", config.c_managesieve_port);
cprintf("<c_auth_mode>%d</c_auth_mode>\n", config.c_auth_mode);
- client_write("<c_funambol_host>", 17); xml_strout(config.c_funambol_host); client_write("</c_funambol_host>\n", 19);
+ client_write(HKEY("<c_funambol_host>")); xml_strout(config.c_funambol_host); client_write(HKEY("</c_funambol_host>\n"));
cprintf("<c_funambol_port>%d</c_funambol_port>\n", config.c_funambol_port);
- client_write("<c_funambol_source>", 19); xml_strout(config.c_funambol_source); client_write("</c_funambol_source>\n", 21);
- client_write("<c_funambol_auth>", 17); xml_strout(config.c_funambol_auth); client_write("</c_funambol_auth>\n", 19);
+ client_write(HKEY("<c_funambol_source>")); xml_strout(config.c_funambol_source); client_write(HKEY("</c_funambol_source>\n"));
+ client_write(HKEY("<c_funambol_auth>")); xml_strout(config.c_funambol_auth); client_write(HKEY("</c_funambol_auth>\n"));
cprintf("<c_rbl_at_greeting>%d</c_rbl_at_greeting>\n", config.c_rbl_at_greeting);
- client_write("<c_master_user>", 15); xml_strout(config.c_master_user); client_write("</c_master_user>\n", 17);
- client_write("<c_master_pass>", 15); xml_strout(config.c_master_pass); client_write("</c_master_pass>\n", 17);
- client_write("<c_pager_program>", 17); xml_strout(config.c_pager_program); client_write("</c_pager_program>\n", 19);
+ client_write(HKEY("<c_master_user>")); xml_strout(config.c_master_user); client_write(HKEY("</c_master_user>\n"));
+ client_write(HKEY("<c_master_pass>")); xml_strout(config.c_master_pass); client_write(HKEY("</c_master_pass>\n"));
+ client_write(HKEY("<c_pager_program>")); xml_strout(config.c_pager_program); client_write(HKEY("</c_pager_program>\n"));
cprintf("<c_imap_keep_from>%d</c_imap_keep_from>\n", config.c_imap_keep_from);
cprintf("<c_xmpp_c2s_port>%d</c_xmpp_c2s_port>\n", config.c_xmpp_c2s_port);
cprintf("<c_xmpp_s2s_port>%d</c_xmpp_s2s_port>\n", config.c_xmpp_s2s_port);
cprintf("<c_spam_flag_only>%d</c_spam_flag_only>\n", config.c_spam_flag_only);
cprintf("<c_nntp_port>%d</c_nntp_port>\n", config.c_nntp_port);
cprintf("<c_nntps_port>%d</c_nntps_port>\n", config.c_nntps_port);
- client_write("</config>\n", 10);
+ client_write(HKEY("</config>\n"));
cprintf("<progress>%d</progress>\n", 1);
/* Export the control file */
get_control();
- client_write("<control>\n", 10);
+ client_write(HKEY("<control>\n"));
cprintf("<control_highest>%ld</control_highest>\n", CitControl.MMhighest);
cprintf("<control_flags>%u</control_flags>\n", CitControl.MMflags);
cprintf("<control_nextuser>%ld</control_nextuser>\n", CitControl.MMnextuser);
cprintf("<control_nextroom>%ld</control_nextroom>\n", CitControl.MMnextroom);
cprintf("<control_version>%d</control_version>\n", CitControl.version);
- client_write("</control>\n", 11);
+ client_write(HKEY("</control>\n"));
cprintf("<progress>%d</progress>\n", 2);
if (Ctx->kill_me == 0) migr_export_users();
if (Ctx->kill_me == 0) migr_export_visits();
cprintf("<progress>%d</progress>\n", 25);
if (Ctx->kill_me == 0) migr_export_messages();
- client_write("</citadel_migrate_data>\n", 24);
+ client_write(HKEY("</citadel_migrate_data>\n"));
cprintf("<progress>%d</progress>\n", 100);
- client_write("000\n", 4);
+ client_write(HKEY("000\n"));
Ctx->dont_term = 0;
}
else if (!strcasecmp(el, "msg_text"))
{
-
- FlushStrBuf(migr_MsgData);
- StrBufDecodeBase64To(migr_MsgData, migr_MsgData);
-
- cdb_store(CDB_MSGMAIN,
- &import_msgnum,
- sizeof(long),
- ChrPtr(migr_MsgData),
- StrLength(migr_MsgData) + 1);
+ long rc;
+ struct CtdlMessage *msg;
smi.meta_msgnum = import_msgnum;
- PutMetaData(&smi);
+ FlushStrBuf(migr_MsgData);
+ StrBufDecodeBase64To(migr_chardata, migr_MsgData);
+
+ msg = CtdlDeserializeMessage(import_msgnum, -1,
+ ChrPtr(migr_MsgData),
+ StrLength(migr_MsgData));
+ if (msg != NULL) {
+ rc = CtdlSaveThisMessage(msg, import_msgnum, 0);
+ if (rc > 0) {
+ PutMetaData(&smi);
+ }
+ CM_Free(msg);
+ }
+ else {
+ rc = -1;
+ }
syslog(LOG_INFO,
- "Imported message #%ld, size=%d, refcount=%d, content-type: %s\n",
+ "%s message #%ld, size=%d, refcount=%d, content-type: %s\n",
+ (rc!= 0)?"failed to import ":"Imported ",
import_msgnum,
StrLength(migr_MsgData),
smi.meta_refcount,
sc = (SpoolControl *)userdata;
- msg = CtdlFetchMessage(msgnum, 1);
+ msg = CtdlFetchMessage(msgnum, 1, 1);
if (msg == NULL)
{
if (msgnum < lr->lo) return;
if ((lr->hi != 0) && (msgnum > lr->hi)) return;
- struct CtdlMessage *msg = CtdlFetchMessage(msgnum, 0);
+ struct CtdlMessage *msg = CtdlFetchMessage(msgnum, 0, 1);
if (msg == NULL) {
return;
}
return SIEVE2_ERROR_BADARGS;
}
- msg = CtdlFetchMessage(cs->msgnum, 1);
+ msg = CtdlFetchMessage(cs->msgnum, 1, 1);
if (msg == NULL) {
SV_syslog(LOG_WARNING, "REDIRECT failed: unable to fetch msg %ld", cs->msgnum);
free_recipients(valid);
/*
* Make sure you include message body so you can get those second-level headers ;)
*/
- msg = CtdlFetchMessage(msgnum, 1);
+ msg = CtdlFetchMessage(msgnum, 1, 1);
if (msg == NULL) return;
/*
long conflen;
u->config_msgnum = msgnum;
- msg = CtdlFetchMessage(msgnum, 1);
+ msg = CtdlFetchMessage(msgnum, 1, 1);
if (msg == NULL) {
u->config_msgnum = (-1) ;
return;
return; // already got it
}
- msg = CtdlFetchMessage(msgnum, 1);
+ msg = CtdlFetchMessage(msgnum, 1, 1);
if (msg == NULL) {
return;
}
SMTPC_syslog(LOG_DEBUG, "smtp_do_procmsg(%ld)\n", msgnum);
///strcpy(envelope_from, "");
- msg = CtdlFetchMessage(msgnum, 1);
+ msg = CtdlFetchMessage(msgnum, 1, 1);
if (msg == NULL) {
SMTPC_syslog(LOG_ERR, "tried %ld but no such message!\n",
msgnum);
void vcard_add_to_directory(long msgnum, void *data) {
struct CtdlMessage *msg;
- msg = CtdlFetchMessage(msgnum, 1);
+ msg = CtdlFetchMessage(msgnum, 1, 1);
if (msg != NULL) {
vcard_extract_internet_addresses(msg, vcard_directory_add_user);
}
if (VCmsgnum < 0L) return vcard_new();
- msg = CtdlFetchMessage(VCmsgnum, 1);
+ msg = CtdlFetchMessage(VCmsgnum, 1, 1);
if (msg == NULL) return vcard_new();
v = vcard_load(msg->cm_fields[eMesageText]);
return;
}
- msg = CtdlFetchMessage(msgnum, 1);
+ msg = CtdlFetchMessage(msgnum, 1, 1);
if (msg == NULL) return;
if (CM_IsEmpty(msg, eMesageText))
void dvca_callback(long msgnum, void *userdata) {
struct CtdlMessage *msg = NULL;
- msg = CtdlFetchMessage(msgnum, 1);
+ msg = CtdlFetchMessage(msgnum, 1, 1);
if (msg == NULL) return;
mime_parser(CM_RANGE(msg, eMesageText),
*dvca_mime_callback, /* callback function */
collected_addresses = (char *)userdata;
- msg = CtdlFetchMessage(msgnum, 1);
+ msg = CtdlFetchMessage(msgnum, 1, 1);
if (msg == NULL) return;
v = vcard_load(msg->cm_fields[eMesageText]);
CM_Free(msg);
/* See if we can retrieve the previous version. */
old_msgnum = CtdlLocateMessageByEuid(msg->cm_fields[eExclusiveID], &CCC->room);
if (old_msgnum > 0L) {
- old_msg = CtdlFetchMessage(old_msgnum, 1);
+ old_msg = CtdlFetchMessage(old_msgnum, 1, 1);
}
else {
old_msg = NULL;
history_msgnum = CtdlLocateMessageByEuid(history_page, &CCC->room);
history_msg = NULL;
if (history_msgnum > 0L) {
- history_msg = CtdlFetchMessage(history_msgnum, 1);
+ history_msg = CtdlFetchMessage(history_msgnum, 1, 1);
}
/* Create a new history message if necessary */
snprintf(history_page_name, sizeof history_page_name, "%s_HISTORY_", pagename);
msgnum = CtdlLocateMessageByEuid(history_page_name, &CC->room);
if (msgnum > 0L) {
- msg = CtdlFetchMessage(msgnum, 1);
+ msg = CtdlFetchMessage(msgnum, 1, 1);
}
else {
msg = NULL;
*/
msgnum = CtdlLocateMessageByEuid(pagename, &CCC->room);
if (msgnum > 0L) {
- msg = CtdlFetchMessage(msgnum, 1);
+ msg = CtdlFetchMessage(msgnum, 1, 1);
}
else {
msg = NULL;
snprintf(history_page_name, sizeof history_page_name, "%s_HISTORY_", pagename);
msgnum = CtdlLocateMessageByEuid(history_page_name, &CCC->room);
if (msgnum > 0L) {
- msg = CtdlFetchMessage(msgnum, 1);
+ msg = CtdlFetchMessage(msgnum, 1, 1);
}
else {
msg = NULL;
char *ptr = NULL;
char *lasts = NULL;
- msg = CtdlFetchMessage(msgnum, 1);
+ msg = CtdlFetchMessage(msgnum, 1, 1);
if (msg == NULL) {
return;
}
free(msglist);
return -1;
}
- msg = CtdlFetchMessage(msglist[a], 1);
+ msg = CtdlFetchMessage(msglist[a], 1, 1);
if (msg != NULL) {
if (CtdlMsgCmp(msg, compare)) {
msglist[a] = 0L;
}
}
-
-/*
- * Load a message from disk into memory.
- * This is used by CtdlOutputMsg() and other fetch functions.
- *
- * NOTE: Caller is responsible for freeing the returned CtdlMessage struct
- * using the CtdlMessageFree() function.
- */
-struct CtdlMessage *CtdlFetchMessage(long msgnum, int with_body)
+struct CtdlMessage *CtdlDeserializeMessage(long msgnum, int with_body, const char *Buffer, long Length)
{
struct CitContext *CCC = CC;
- struct cdbdata *dmsgtext;
struct CtdlMessage *ret = NULL;
- char *mptr;
- char *upper_bound;
+ const char *mptr;
+ const char *upper_bound;
cit_uint8_t ch;
cit_uint8_t field_header;
eMsgField which;
- MSG_syslog(LOG_DEBUG, "CtdlFetchMessage(%ld, %d)\n", msgnum, with_body);
- dmsgtext = cdb_fetch(CDB_MSGMAIN, &msgnum, sizeof(long));
- if (dmsgtext == NULL) {
- MSG_syslog(LOG_ERR, "CtdlFetchMessage(%ld, %d) Failed!\n", msgnum, with_body);
- return NULL;
- }
- mptr = dmsgtext->ptr;
- upper_bound = mptr + dmsgtext->len;
+ mptr = Buffer;
+ upper_bound = Buffer + Length;
/* Parse the three bytes that begin EVERY message on disk.
* The first is always 0xFF, the on-disk magic number.
ch = *mptr++;
if (ch != 255) {
MSG_syslog(LOG_ERR, "Message %ld appears to be corrupted.\n", msgnum);
- cdb_free(dmsgtext);
return NULL;
}
ret = (struct CtdlMessage *) malloc(sizeof(struct CtdlMessage));
ret->cm_anon_type = *mptr++; /* Anon type byte */
ret->cm_format_type = *mptr++; /* Format type byte */
-
- if (dmsgtext->ptr[dmsgtext->len - 1] != '\0')
- {
- MSG_syslog(LOG_ERR, "CtdlFetchMessage(%ld, %d) Forcefully terminating message!!\n", msgnum, with_body);
- dmsgtext->ptr[dmsgtext->len - 1] = '\0';
- }
-
/*
* The rest is zero or more arbitrary fields. Load them in.
* We're done when we encounter either a zero-length field or
} while ((mptr < upper_bound) && (field_header != 'M'));
+ return (ret);
+}
+
+
+/*
+ * Load a message from disk into memory.
+ * This is used by CtdlOutputMsg() and other fetch functions.
+ *
+ * NOTE: Caller is responsible for freeing the returned CtdlMessage struct
+ * using the CtdlMessageFree() function.
+ */
+struct CtdlMessage *CtdlFetchMessage(long msgnum, int with_body, int run_msg_hooks)
+{
+ struct CitContext *CCC = CC;
+ struct cdbdata *dmsgtext;
+ struct CtdlMessage *ret = NULL;
+
+ MSG_syslog(LOG_DEBUG, "CtdlFetchMessage(%ld, %d)\n", msgnum, with_body);
+ dmsgtext = cdb_fetch(CDB_MSGMAIN, &msgnum, sizeof(long));
+ if (dmsgtext == NULL) {
+ MSG_syslog(LOG_ERR, "CtdlFetchMessage(%ld, %d) Failed!\n", msgnum, with_body);
+ return NULL;
+ }
+
+ if (dmsgtext->ptr[dmsgtext->len - 1] != '\0')
+ {
+ MSG_syslog(LOG_ERR, "CtdlFetchMessage(%ld, %d) Forcefully terminating message!!\n", msgnum, with_body);
+ dmsgtext->ptr[dmsgtext->len - 1] = '\0';
+ }
+
+ ret = CtdlDeserializeMessage(msgnum, with_body, dmsgtext->ptr, dmsgtext->len);
+
cdb_free(dmsgtext);
+ if (ret == NULL) {
+ return NULL;
+ }
+
/* Always make sure there's something in the msg text field. If
* it's NULL, the message text is most likely stored separately,
* so go ahead and fetch that. Failing that, just set a dummy
}
/* Perform "before read" hooks (aborting if any return nonzero) */
- if (PerformMessageHooks(ret, NULL, EVT_BEFOREREAD) > 0) {
+ if (run_msg_hooks && (PerformMessageHooks(ret, NULL, EVT_BEFOREREAD) > 0)) {
CM_Free(ret);
return NULL;
}
* request that we don't even bother loading the body into memory.
*/
if (headers_only == HEADERS_FAST) {
- TheMessage = CtdlFetchMessage(msg_num, 0);
+ TheMessage = CtdlFetchMessage(msg_num, 0, 1);
}
else {
- TheMessage = CtdlFetchMessage(msg_num, 1);
+ TheMessage = CtdlFetchMessage(msg_num, 1, 1);
}
if (TheMessage == NULL) {
msg = supplied_msg;
}
else {
- msg = CtdlFetchMessage(msgid, 0);
+ msg = CtdlFetchMessage(msgid, 0, 1);
}
if (msg != NULL) {
* called by server-side modules.
*
*/
-long send_message(struct CtdlMessage *msg) {
+long CtdlSaveThisMessage(struct CtdlMessage *msg, long msgid, int Reply) {
struct CitContext *CCC = CC;
- long newmsgid;
long retval;
- char msgidbuf[256];
- long msgidbuflen;
struct ser_ret smr;
int is_bigmsg = 0;
char *holdM = NULL;
long holdMLen = 0;
- /* Get a new message number */
- newmsgid = get_new_message_number();
- msgidbuflen = snprintf(msgidbuf, sizeof msgidbuf, "%08lX-%08lX@%s",
- (long unsigned int) time(NULL),
- (long unsigned int) newmsgid,
- config.c_fqdn
- );
-
- /* Generate an ID if we don't have one already */
- if (CM_IsEmpty(msg, emessageId)) {
- CM_SetField(msg, emessageId, msgidbuf, msgidbuflen);
- }
-
- /* If the message is big, set its body aside for storage elsewhere */
- if (!CM_IsEmpty(msg, eMesageText)) {
- if (msg->cm_lengths[eMesageText] > BIGMSG) {
- is_bigmsg = 1;
- holdM = msg->cm_fields[eMesageText];
- msg->cm_fields[eMesageText] = NULL;
- holdMLen = msg->cm_lengths[eMesageText];
- msg->cm_lengths[eMesageText] = 0;
- }
+ /*
+ * If the message is big, set its body aside for storage elsewhere
+ * and we hide the message body from the serializer
+ */
+ if (!CM_IsEmpty(msg, eMesageText) && msg->cm_lengths[eMesageText] > BIGMSG)
+ {
+ is_bigmsg = 1;
+ holdM = msg->cm_fields[eMesageText];
+ msg->cm_fields[eMesageText] = NULL;
+ holdMLen = msg->cm_lengths[eMesageText];
+ msg->cm_lengths[eMesageText] = 0;
}
/* Serialize our data structure for storage in the database */
CtdlSerializeMessage(&smr, msg);
if (is_bigmsg) {
+ /* put the message body back into the message */
msg->cm_fields[eMesageText] = holdM;
msg->cm_lengths[eMesageText] = holdMLen;
}
if (smr.len == 0) {
- cprintf("%d Unable to serialize message\n",
- ERROR + INTERNAL_ERROR);
+ if (Reply) {
+ cprintf("%d Unable to serialize message\n",
+ ERROR + INTERNAL_ERROR);
+ }
+ else {
+ MSGM_syslog(LOG_ERR, "CtdlSaveMessage() unable to serialize message");
+
+ }
return (-1L);
}
/* Write our little bundle of joy into the message base */
- if (cdb_store(CDB_MSGMAIN, &newmsgid, (int)sizeof(long),
- smr.ser, smr.len) < 0) {
- MSGM_syslog(LOG_ERR, "Can't store message\n");
- retval = 0L;
- } else {
+ retval = cdb_store(CDB_MSGMAIN, &msgid, (int)sizeof(long),
+ smr.ser, smr.len);
+ if (retval < 0) {
+ MSG_syslog(LOG_ERR, "Can't store message %ld: %ld", msgid, retval);
+ }
+ else {
if (is_bigmsg) {
- cdb_store(CDB_BIGMSGS,
- &newmsgid,
- (int)sizeof(long),
- holdM,
- (holdMLen + 1)
+ retval = cdb_store(CDB_BIGMSGS,
+ &msgid,
+ (int)sizeof(long),
+ holdM,
+ (holdMLen + 1)
);
+ if (retval < 0) {
+ MSG_syslog(LOG_ERR, "failed to store message body for msgid %ld: %ld",
+ msgid, retval);
+ }
}
- retval = newmsgid;
}
/* Free the memory we used for the serialized message */
free(smr.ser);
+ return(retval);
+}
+
+long send_message(struct CtdlMessage *msg) {
+ long newmsgid;
+ long retval;
+ char msgidbuf[256];
+ long msgidbuflen;
+
+ /* Get a new message number */
+ newmsgid = get_new_message_number();
+
+ /* Generate an ID if we don't have one already */
+ if (CM_IsEmpty(msg, emessageId)) {
+ msgidbuflen = snprintf(msgidbuf, sizeof msgidbuf, "%08lX-%08lX@%s",
+ (long unsigned int) time(NULL),
+ (long unsigned int) newmsgid,
+ config.c_fqdn
+ );
+
+ CM_SetField(msg, emessageId, msgidbuf, msgidbuflen);
+ }
+
+ retval = CtdlSaveThisMessage(msg, newmsgid, 1);
+
+ if (retval == 0) {
+ retval = newmsgid;
+ }
+
/* Return the *local* message ID to the caller
* (even if we're storing an incoming network message)
*/
* serialized message in memory. THE LATTER MUST BE FREED BY THE CALLER.
*/
void CtdlSerializeMessage(struct ser_ret *ret, /* return values */
- struct CtdlMessage *msg) /* unserialized msg */
+ struct CtdlMessage *msg) /* unserialized msg */
{
struct CitContext *CCC = CC;
size_t wlen;
int is_unique, /* Del others of this type? */
unsigned int flags /* Internal save flags */
);
-struct CtdlMessage *CtdlFetchMessage(long msgnum, int with_body);
+struct CtdlMessage *CtdlFetchMessage(long msgnum, int with_body, int run_msg_hooks);
struct CtdlMessage * CM_Duplicate
(struct CtdlMessage *OrgMsg);
int CM_IsEmpty (struct CtdlMessage *Msg, eMsgField which);
Message->cm_fields[Which] + Message->cm_lengths[Which]
void CtdlSerializeMessage(struct ser_ret *, struct CtdlMessage *);
+struct CtdlMessage *CtdlDeserializeMessage(long msgnum, int with_body, const char *Buffer, long Length);
void ReplicationChecks(struct CtdlMessage *);
int CtdlSaveMsgPointersInRoom(char *roomname, long newmsgidlist[], int num_newmsgs,
- int do_repl_check, struct CtdlMessage *supplied_msg, int suppress_refcount_adj);
+ int do_repl_check, struct CtdlMessage *supplied_msg, int suppress_refcount_adj);
int CtdlSaveMsgPointerInRoom(char *roomname, long msgid, int do_repl_check, struct CtdlMessage *msg);
+long CtdlSaveThisMessage(struct CtdlMessage *msg, long msgid, int Reply);
char *CtdlReadMessageBody(char *terminator, long tlen, size_t maxlen, StrBuf *exist, int crlf, int *sock);
StrBuf *CtdlReadMessageBodyBuf(char *terminator, /* token signalling EOT */
long tlen,
#define CCCID CCC->cs_pid
#define MSG_syslog(LEVEL, FORMAT, ...) \
MSGDBGLOG(LEVEL) syslog(LEVEL, \
- "CC[%d]MSG" FORMAT, \
+ "CC[%d]MSG " FORMAT, \
CCCID, __VA_ARGS__)
#define MSGM_syslog(LEVEL, FORMAT) \
MSGDBGLOG(LEVEL) syslog(LEVEL, \
- "CC[%d]MSG" FORMAT, \
+ "CC[%d]MSG " FORMAT, \
CCCID)
"(example: ctdl.foo.org)\n"
"--> ");
getz(remote_host);
+
+get_remote_user:
printf("\nEnter the name of a user on %s who has full access to Citadel files\n"
"(usually root)\n--> ",
remote_host);
getz(remote_user);
+ if (IsEmptyStr(remote_user))
+ goto get_remote_user;
printf("\nEstablishing an SSH connection to the source system...\n\n");
unlink(socket_path);
}
printf("ctdlmigrate will now begin a database migration...\n");
+ printf(" if the system doesn't start working, \n");
+ printf(" have a look at the syslog for pending jobs needing to be terminated.\n");
snprintf(cmd, sizeof cmd, "ssh -S %s %s@%s %s -w3600 MIGR export",
socket_path, remote_user, remote_host, remote_sendcommand);