* exporting the message multiple times.)
*/
snprintf(cmd, sizeof cmd, "sort -n <%s >%s", migr_tempfilename1, migr_tempfilename2);
- if (system(cmd) != 0) syslog(LOG_ERR, "Error %d", errno);
+ if (system(cmd) != 0) {
+ syslog(LOG_ERR, "migrate: error %d", errno);
+ }
snprintf(cmd, sizeof cmd, "uniq <%s >%s", migr_tempfilename2, migr_tempfilename1);
- if (system(cmd) != 0) syslog(LOG_ERR, "Error %d", errno);
-
+ if (system(cmd) != 0) {
+ syslog(LOG_ERR, "migrate: error %d", errno);
+ }
snprintf(cmd, sizeof cmd, "wc -l %s", migr_tempfilename1);
FILE *fp = popen(cmd, "r");
else {
total_msgs = 1; // any nonzero just to keep it from barfing
}
- syslog(LOG_DEBUG, "Total messages to be exported: %d", total_msgs);
+ syslog(LOG_DEBUG, "migrate: total messages to be exported: %d", total_msgs);
}
struct MetaData smi;
struct CtdlMessage *msg;
struct ser_ret smr;
+ long bytes_written = 0;
+ long this_block = 0;
+
+ // We can use a static buffer here because there will never be more than
+ // one of this operation happening at any given time, and it's really best
+ // to just keep it allocated once instead of torturing malloc/free.
+ // Call this function with msgnum "-1" to free the buffer when finished.
- /* We can use a static buffer here because there will never be more than
- * one of this operation happening at any given time, and it's really best
- * to just keep it allocated once instead of torturing malloc/free.
- * Call this function with msgnum "-1" to free the buffer when finished.
- */
static int encoded_alloc = 0;
static char *encoded_msg = NULL;
return;
}
- /* Ok, here we go ... */
+ // Ok, here we go ...
msg = CtdlFetchMessage(msgnum, 1);
- if (msg == NULL) return; /* fail silently */
+ if (msg == NULL) return; // fail silently
client_write(HKEY("<message>\n"));
GetMetaData(&smi, msgnum);
CtdlSerializeMessage(&smr, msg);
CM_Free(msg);
- /* Predict the buffer size we need. Expand the buffer if necessary. */
+ // Predict the buffer size we need. Expand the buffer if necessary.
int encoded_len = smr.len * 15 / 10 ;
if (encoded_len > encoded_alloc) {
encoded_alloc = encoded_len;
}
if (encoded_msg == NULL) {
- /* Questionable hack that hopes it'll work next time and we only lose one message */
+ // Questionable hack that hopes it'll work next time and we only lose one message
encoded_alloc = 0;
}
else {
- /* Once we do the encoding we know the exact size */
+ // Once we do the encoding we know the exact size
encoded_len = CtdlEncodeBase64(encoded_msg, (char *)smr.ser, smr.len, 1);
- client_write(encoded_msg, encoded_len);
+
+ // Careful now. If the message is gargantuan, trying to write multiple gigamegs in one
+ // big write operation can make our transport unhappy. So we'll chunk it up 10 KB at a time.
+ bytes_written = 0;
+ while ( (bytes_written < encoded_len) && (!server_shutting_down) ) {
+ this_block = encoded_len - bytes_written;
+ if (this_block > 10240) {
+ this_block = 10240;
+ }
+ client_write(&encoded_msg[bytes_written], this_block);
+ bytes_written += this_block;
+ }
}
free(smr.ser);
Ctx = CC;
migr_global_message_list = fopen(migr_tempfilename1, "r");
if (migr_global_message_list != NULL) {
- syslog(LOG_INFO, "Opened %s", migr_tempfilename1);
+ syslog(LOG_INFO, "migrate: opened %s", migr_tempfilename1);
while ((Ctx->kill_me == 0) &&
(fgets(buf, sizeof(buf), migr_global_message_list) != NULL)) {
msgnum = atol(buf);
fclose(migr_global_message_list);
}
if (Ctx->kill_me == 0) {
- syslog(LOG_INFO, "Exported %d messages.", count);
+ syslog(LOG_INFO, "migrate: exported %d messages.", count);
}
else {
- syslog(LOG_ERR, "Export aborted due to client disconnect!");
+ syslog(LOG_ERR, "migrate: export aborted due to client disconnect!");
}
migr_export_message(-1L); /* This frees the encoding buffer */
* This callback stores up the data which appears in between tags.
*/
void migr_xml_chardata(void *data, const XML_Char *s, int len) {
-
- char aaa[65536];
- memcpy(aaa, s, len);
- aaa[len] = 0;
- syslog(LOG_DEBUG, "chardata <\033[35m%s\033[0m>", aaa);
-
StrBufAppendBufPlain(migr_chardata, s, len, 0);
}
}
if (citadel_migrate_data != 1) {
- syslog(LOG_ERR, "Out-of-sequence tag <%s> detected. Warning: ODD-DATA!", el);
+ syslog(LOG_ERR, "migrate: out-of-sequence tag <%s> detected. Warning: ODD-DATA!", el);
return;
}
}
if (citadel_migrate_data != 1) {
- syslog(LOG_ERR, "Out-of-sequence tag <%s> detected. Warning: ODD-DATA!", el);
+ syslog(LOG_ERR, "migrate: out-of-sequence tag <%s> detected. Warning: ODD-DATA!", el);
return;
}
/*** CONFIG ***/
if (!strcasecmp(el, "config")) {
- syslog(LOG_DEBUG, "Imported config key=%s", ikey);
+ syslog(LOG_DEBUG, "migrate: imported config key=%s", ikey);
if (ikey != NULL) {
CtdlSetConfigStr(ikey, (char *)ChrPtr(migr_chardata));
ikey = NULL;
}
else {
- syslog(LOG_INFO, "Closed a <config> tag but no key name was supplied.");
+ syslog(LOG_INFO, "migrate: closed a <config> tag but no key name was supplied.");
}
}
; /* Nothing to do anymore */
else if (!strcasecmp(el, "user")) {
CtdlPutUser(&usbuf);
- syslog(LOG_INFO, "Imported user: %s", usbuf.fullname);
+ syslog(LOG_INFO, "migrate: imported user: %s", usbuf.fullname);
}
/*** OPENID ***/
memcpy(&oid_data[sizeof(long)], openid_url, strlen(openid_url) + 1);
cdb_store(CDB_EXTAUTH, openid_url, strlen(openid_url), oid_data, oid_data_len);
free(oid_data);
- syslog(LOG_INFO, "Imported OpenID: %s (%ld)", openid_url, openid_usernum);
+ syslog(LOG_INFO, "migrate: imported OpenID: %s (%ld)", openid_url, openid_usernum);
}
/*** ROOM ***/
; /* Nothing to do anymore */
else if (!strcasecmp(el, "room")) {
CtdlPutRoom(&qrbuf);
- syslog(LOG_INFO, "Imported room: %s", qrbuf.QRname);
+ syslog(LOG_INFO, "migrate: imported room: %s", qrbuf.QRname);
}
/*** ROOM MESSAGE POINTERS ***/
msglist_alloc = 1000;
msglist = malloc(sizeof(long) * msglist_alloc);
- syslog(LOG_DEBUG, "Message list for: %s", FRname);
+ syslog(LOG_DEBUG, "migrate: message list for: %s", FRname);
ptr = ChrPtr(migr_chardata);
- syslog(LOG_DEBUG, "\033[31m%s\033[0m", ptr);
while (*ptr != 0) {
while ((*ptr != 0) && (!isdigit(*ptr))) {
++ptr;
msglist = realloc(msglist, sizeof(long) * msglist_alloc);
}
msglist[msgcount++] = msgnum;
- syslog(LOG_DEBUG, "\033[32mmsgnum %ld , count is now %d\033[0m", msgnum, msgcount);
}
}
while ((*ptr != 0) && (isdigit(*ptr))) {
free(msglist);
msglist = NULL;
msglist_alloc = 0;
- syslog(LOG_DEBUG, "Imported %d messages.", msgcount);
+ syslog(LOG_DEBUG, "migrate: imported %d messages.", msgcount);
if (server_shutting_down) {
return;
}
else if (!strcasecmp(el, "floor")) {
CtdlPutFloor(&flbuf, floornum);
- syslog(LOG_INFO, "Imported floor #%d (%s)", floornum, flbuf.f_name);
+ syslog(LOG_INFO, "migrate: imported floor #%d (%s)", floornum, flbuf.f_name);
}
/*** VISITS ***/
}
else if (!strcasecmp(el, "visit")) {
put_visit(&vbuf);
- syslog(LOG_INFO, "Imported visit: %ld/%ld/%ld", vbuf.v_roomnum, vbuf.v_roomgen, vbuf.v_usernum);
+ syslog(LOG_INFO, "migrate: imported visit: %ld/%ld/%ld", vbuf.v_roomnum, vbuf.v_roomgen, vbuf.v_usernum);
}
/*** MESSAGES ***/
}
syslog(LOG_INFO,
- "%s message #%ld, size=%d, refcount=%d, bodylength=%ld, content-type: %s",
+ "migrate: %s message #%ld, size=%d, refcount=%d, bodylength=%ld, content-type: %s",
(rc!= 0)?"failed to import ":"Imported ",
import_msgnum,
StrLength(migr_MsgData),
CC->redirect_buffer = NULL;
syslog(LOG_INFO,
- "Setting message #%ld meta data to: refcount=%d, bodylength=%ld, content-type: %s",
+ "migrate: setting message #%ld meta data to: refcount=%d, bodylength=%ld, content-type: %s",
smi.meta_msgnum,
smi.meta_refcount,
smi.meta_rfc822_length,
const char *Pos = NULL;
StrBuf *oneRoom = NewStrBuf();
- syslog(LOG_INFO, "removing message pointer %ld from these rooms: %s", msgnum, ChrPtr(RoomNameVec));
+ syslog(LOG_INFO, "migrate: removing message pointer %ld from these rooms: %s", msgnum, ChrPtr(RoomNameVec));
while (Pos != StrBufNOTNULL){
StrBufExtract_NextToken(oneRoom, RoomNameVec, &Pos, '|');
* exporting the message multiple times.)
*/
snprintf(cmd, sizeof cmd, "sort -n <%s >%s", migr_tempfilename1, migr_tempfilename2);
- if (system(cmd) != 0) syslog(LOG_ERR, "Error %d", errno);
+ if (system(cmd) != 0) {
+ syslog(LOG_ERR, "migrate: error %d", errno);
+ }
RoomNames = NewStrBuf();
Ctx = CC;
migr_global_message_list = fopen(migr_tempfilename2, "r");
if (migr_global_message_list != NULL) {
- syslog(LOG_INFO, "Opened %s", migr_tempfilename1);
+ syslog(LOG_INFO, "migrate: opened %s", migr_tempfilename1);
while ((Ctx->kill_me == 0) &&
(fgets(buf, sizeof(buf), migr_global_message_list) != NULL)) {
msgnum = atol(buf);
void cmd_migr(char *cmdbuf) {
char cmd[32];
- if (CtdlAccessCheck(ac_internal)) return;
+ if (CtdlAccessCheck(ac_aide)) return;
if (CtdlTrySingleUser()) {
CtdlDisableHouseKeeping();