* This module handles shared rooms, inter-Citadel mail, and outbound
* mailing list processing.
*
- * Copyright (c) 2000-2010 by the citadel.org team
+ * Copyright (c) 2000-2011 by the citadel.org team
*
- * This program is free software; you can redistribute it and/or modify
+ * This program is open source software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
-/* Nonzero while we are doing network processing */
-static int doing_queue = 0;
-
/*
* When we do network processing, it's accomplished in two passes; one to
* gather a list of rooms and one to actually do them. It's ok that rplist
*/
msg = CtdlFetchMessage(msgnum, 1);
if (msg != NULL) {
- int len, rlen;
+ int rlen;
char *pCh;
+ StrBuf *Subject, *FlatSubject;
if (msg->cm_fields['V'] == NULL){
/* local message, no enVelope */
/* Prepend "[List name]" to the subject */
if (msg->cm_fields['U'] == NULL) {
- msg->cm_fields['U'] = strdup("(no subject)");
+ Subject = NewStrBufPlain(HKEY("(no subject)"));
}
-
- len = strlen(msg->cm_fields['U']);
+ else {
+ Subject = NewStrBufPlain(msg->cm_fields['U'], -1);
+ }
+ FlatSubject = NewStrBufPlain(NULL, StrLength(Subject));
+ StrBuf_RFC822_to_Utf8(FlatSubject, Subject, NULL, NULL);
+
rlen = strlen(CC->room.QRname);
- pCh = strstr(msg->cm_fields['U'], CC->room.QRname);
+ pCh = strstr(ChrPtr(FlatSubject), CC->room.QRname);
if ((pCh == NULL) ||
(*(pCh + rlen) != ']') ||
- (pCh == msg->cm_fields['U']) ||
+ (pCh == ChrPtr(FlatSubject)) ||
(*(pCh - 1) != '[')
)
{
- char *pBuff;
+ StrBuf *tmp;
+ StrBufPlain(Subject, HKEY("["));
+ StrBufAppendBufPlain(Subject, CC->room.QRname, rlen, 0);
+ StrBufAppendBufPlain(Subject, HKEY("] "), 0);
+ StrBufAppendBuf(Subject, FlatSubject, 0);
+ tmp = Subject; Subject = FlatSubject; FlatSubject = tmp; /* so we can free the right one... */
+ StrBufRFC2047encode(&Subject, FlatSubject);
+ }
+
+ if (msg->cm_fields['U'] != NULL)
+ free (msg->cm_fields['U']);
+ msg->cm_fields['U'] = SmashStrBuf(&Subject);
- rlen += len + 4;
- pBuff = malloc (rlen * sizeof(char));
+ FreeStrBuf(&FlatSubject);
- snprintf(pBuff, rlen, "[%s] %s", CC->room.QRname, msg->cm_fields['U']);
- free(msg->cm_fields['U']);
- msg->cm_fields['U'] = pBuff;
- }
/* else we won't modify the buffer, since the roomname is already here. */
- /* if we don't already have a 'reply to' field, put our roomname in. */
- if (msg->cm_fields['K'] == NULL) {
- msg->cm_fields['K'] = malloc(256);
- snprintf(msg->cm_fields['K'], 256,
- "room_%s@%s", CC->room.QRname,
- config.c_fqdn);
- for (i=0; msg->cm_fields['K'][i]; ++i) {
- if (isspace(msg->cm_fields['K'][i])) {
- msg->cm_fields['K'][i] = '_';
- }
+ /* Set the recipient of the list message to the
+ * email address of the room itself.
+ * FIXME ... I want to be able to pick any address
+ */
+ if (msg->cm_fields['R'] != NULL) {
+ free(msg->cm_fields['R']);
+ }
+ msg->cm_fields['R'] = malloc(256);
+ snprintf(msg->cm_fields['R'], 256,
+ "room_%s@%s", CC->room.QRname,
+ config.c_fqdn);
+ for (i=0; msg->cm_fields['R'][i]; ++i) {
+ if (isspace(msg->cm_fields['R'][i])) {
+ msg->cm_fields['R'][i] = '_';
}
}
* If shutting down we can exit here and unlink the temp file.
* this shouldn't loose us any messages.
*/
- if (CtdlThreadCheckStop())
+ if (server_shutting_down)
{
fclose(fp);
unlink(tempfilename);
fclose(fp);
/* Last chance for shutdown exit */
- if (CtdlThreadCheckStop())
+ if (server_shutting_down)
{
unlink(tempfilename);
return;
bytes_to_write = plen;
while (bytes_to_write > 0L) {
/* Exit if shutting down */
- if (CtdlThreadCheckStop())
+ if (server_shutting_down)
{
close(fd);
return;
close(fd);
/* Last chance for shutdown exit */
- if(CtdlThreadCheckStop())
+ if(server_shutting_down)
return;
if (sock_puts(sock, "UCLS 1") < 0) return;
}
/* At this point we are authenticated. */
- if (!CtdlThreadCheckStop())
+ if (!server_shutting_down)
receive_spool(&sock, node);
- if (!CtdlThreadCheckStop())
+ if (!server_shutting_down)
transmit_spool(&sock, node);
}
/* Use the string tokenizer to grab one line at a time */
for (i=0; i<num_tokens(working_ignetcfg, '\n'); ++i) {
- if(CtdlThreadCheckStop())
+ if(server_shutting_down)
return;
extract_token(linebuf, working_ignetcfg, i, '\n', sizeof linebuf);
extract_token(node, linebuf, 0, '|', sizeof node);
* Run through the rooms doing various types of network stuff.
*/
void network_do_queue(void) {
+ static int doing_queue = 0;
static time_t last_run = 0L;
struct RoomProcList *ptr;
int full_processing = 1;
/*
* Go ahead and run the queue
*/
- if (full_processing && !CtdlThreadCheckStop()) {
+ if (full_processing && !server_shutting_down) {
syslog(LOG_DEBUG, "network: loading outbound queue\n");
CtdlForEachRoom(network_queue_room, NULL);
}
if (rplist != NULL) {
syslog(LOG_DEBUG, "network: running outbound queue\n");
- while (rplist != NULL && !CtdlThreadCheckStop()) {
+ while (rplist != NULL && !server_shutting_down) {
char spoolroomname[ROOMNAMELEN];
safestrncpy(spoolroomname, rplist->name, sizeof spoolroomname);
begin_critical_section(S_RPLIST);
}
/* If there is anything in the inbound queue, process it */
- if (!CtdlThreadCheckStop()) {
+ if (!server_shutting_down) {
network_do_spoolin();
}
"An unknown Citadel server called \"%s\" attempted to connect from %s [%s].\n",
node, CC->cs_host, CC->cs_addr
);
- syslog(LOG_WARNING, err_buf);
+ syslog(LOG_WARNING, "%s", err_buf);
cprintf("%d authentication failed\n", ERROR + PASSWORD_REQUIRED);
CtdlAideMessage(err_buf, "IGNet Networking.");
return;
"A Citadel server at %s [%s] failed to authenticate as network node \"%s\".\n",
CC->cs_host, CC->cs_addr, node
);
- syslog(LOG_WARNING, err_buf);
+ syslog(LOG_WARNING, "%s", err_buf);
cprintf("%d authentication failed\n", ERROR + PASSWORD_REQUIRED);
CtdlAideMessage(err_buf, "IGNet Networking.");
return;
return 0;
}
-void *ignet_thread(void *arg) {
- struct CitContext ignet_thread_CC;
-
- syslog(LOG_DEBUG, "ignet_thread() initializing\n");
- CtdlFillSystemContext(&ignet_thread_CC, "IGnet Queue");
- citthread_setspecific(MyConKey, (void *)&ignet_thread_CC);
-
- while (!CtdlThreadCheckStop()) {
- network_do_queue();
- CtdlThreadSleep(60);
- }
-
- CtdlClearSystemContext();
- return(NULL);
-}
-
-
-
/*
* Module entry point
CtdlRegisterProtoHook(cmd_nsyn, "NSYN", "Synchronize room to node");
CtdlRegisterRoomHook(network_room_handler);
CtdlRegisterCleanupHook(destroy_network_queue_room);
- CtdlThreadCreate("SMTP Send", CTDLTHREAD_BIGSTACK, ignet_thread, NULL);
+ CtdlRegisterSessionHook(network_do_queue, EVT_TIMER);
}
return "network";
}