#include "support.h"
#include "config.h"
#include "user_ops.h"
-#include "policy.h"
#include "database.h"
#include "msgbase.h"
#include "internet_addressing.h"
fprintf(sc->digestfp, "Subject: %s\n", msg->cm_fields['U']);
}
- CC->redirect_buffer = malloc(SIZ);
- CC->redirect_len = 0;
- CC->redirect_alloc = SIZ;
-
+ CC->redirect_buffer = NewStrBufPlain(NULL, SIZ);
+
safestrncpy(CC->preferred_formats, "text/plain", sizeof CC->preferred_formats);
CtdlOutputPreLoadedMsg(msg, MT_CITADEL, HEADERS_NONE, 0, 0, 0);
- striplt(CC->redirect_buffer);
- fprintf(sc->digestfp, "\n%s\n", CC->redirect_buffer);
+ StrBufTrim(CC->redirect_buffer);
+ fwrite(HKEY("\n"), 1, sc->digestfp);
+ fwrite(SKEY(CC->redirect_buffer), 1, sc->digestfp);
+ fwrite(HKEY("\n"), 1, sc->digestfp);
- free(CC->redirect_buffer);
- CC->redirect_buffer = NULL;
- CC->redirect_len = 0;
- CC->redirect_alloc = 0;
+ FreeStrBuf(&CC->redirect_buffer);
sc->num_msgs_spooled += 1;
free(msg);
buf[strlen(buf)-1] = 0;
extract_token(instr, buf, 0, '|', sizeof instr);
- if (!strcasecmp(instr, "lastsent")) {
+ if (!strcasecmp(instr, strof(lastsent))) {
sc->lastsent = extract_long(buf, 1);
}
- else if (!strcasecmp(instr, "listrecp")) {
+ else if (!strcasecmp(instr, strof(listrecp))) {
nptr = (namelist *)
malloc(sizeof(namelist));
nptr->next = sc->listrecps;
extract_token(nptr->name, buf, 1, '|', sizeof nptr->name);
sc->listrecps = nptr;
}
- else if (!strcasecmp(instr, "participate")) {
+ else if (!strcasecmp(instr, strof(participate))) {
nptr = (namelist *)
malloc(sizeof(namelist));
nptr->next = sc->participates;
extract_token(nptr->name, buf, 1, '|', sizeof nptr->name);
sc->participates = nptr;
}
- else if (!strcasecmp(instr, "digestrecp")) {
+ else if (!strcasecmp(instr, strof(digestrecp))) {
nptr = (namelist *)
malloc(sizeof(namelist));
nptr->next = sc->digestrecps;
extract_token(nptr->name, buf, 1, '|', sizeof nptr->name);
sc->digestrecps = nptr;
}
- else if (!strcasecmp(instr, "ignet_push_share")) {
+ else if (!strcasecmp(instr, strof(ignet_push_share))) {
extract_token(nodename, buf, 1, '|', sizeof nodename);
extract_token(roomname, buf, 2, '|', sizeof roomname);
mptr = (maplist *) malloc(sizeof(maplist));
* timestamps.
*/
skipthisline = 0;
- if (!strncasecmp(buf, "subpending|", 11)) {
+ if (!strncasecmp(buf, strof(subpending)"|", 11)) {
if (time(NULL) - extract_long(buf, 4) > EXP) {
skipthisline = 1;
}
}
- if (!strncasecmp(buf, "unsubpending|", 13)) {
+ if (!strncasecmp(buf, strof(unsubpending)"|", 13)) {
if (time(NULL) - extract_long(buf, 3) > EXP) {
skipthisline = 1;
}
/*
* receive network spool from the remote system
*/
-void receive_spool(int sock, char *remote_nodename) {
+void receive_spool(int *sock, char *remote_nodename) {
size_t siz;
long download_len = 0L;
long bytes_received = 0L;
/*
* transmit network spool to the remote system
*/
-void transmit_spool(int sock, char *remote_nodename)
+void transmit_spool(int *sock, char *remote_nodename)
{
char buf[SIZ];
char pbuf[4096];
char buf[SIZ];
char err_buf[SIZ];
char connected_to[SIZ];
+ CitContext *CCC=CC;
if (network_talking_to(node, NTT_CHECK)) return;
network_talking_to(node, NTT_ADD);
+ CtdlLogPrintf(CTDL_DEBUG, "network: polling <%s>\n", node);
CtdlLogPrintf(CTDL_NOTICE, "Connecting to <%s> at %s:%s\n", node, host, port);
sock = sock_connect(host, port, "tcp");
}
CtdlLogPrintf(CTDL_DEBUG, "Connected!\n");
+ CCC->sReadBuf = NewStrBuf();
+ CCC->sMigrateBuf = NewStrBuf();
+ CCC->sPos = NULL;
/* Read the server greeting */
- if (sock_getln(sock, buf, sizeof buf) < 0) goto bail;
+ if (sock_getln(&sock, buf, sizeof buf) < 0) goto bail;
CtdlLogPrintf(CTDL_DEBUG, ">%s\n", buf);
/* Check that the remote is who we think it is and warn the Aide if not */
extract_token (connected_to, buf, 1, ' ', sizeof connected_to);
if (strcmp(connected_to, node))
{
- snprintf (err_buf, sizeof(err_buf), "Connected to node \"%s\" but I was expecting to connect to node \"%s\".", connected_to, node);
+ snprintf(err_buf, sizeof(err_buf),
+ "Connected to node \"%s\" but I was expecting to connect to node \"%s\".",
+ connected_to, node
+ );
CtdlLogPrintf(CTDL_ERR, "%s\n", err_buf);
CtdlAideMessage(err_buf, "Network error");
}
/* We're talking to the correct node. Now identify ourselves. */
snprintf(buf, sizeof buf, "NETP %s|%s", config.c_nodename, secret);
CtdlLogPrintf(CTDL_DEBUG, "<%s\n", buf);
- if (sock_puts(sock, buf) <0) goto bail;
- if (sock_getln(sock, buf, sizeof buf) < 0) goto bail;
+ if (sock_puts(&sock, buf) <0) goto bail;
+ if (sock_getln(&sock, buf, sizeof buf) < 0) goto bail;
CtdlLogPrintf(CTDL_DEBUG, ">%s\n", buf);
- if (buf[0] != '2') goto bail;
+ if (buf[0] != '2') {
+ goto bail;
+ }
/* At this point we are authenticated. */
if (!CtdlThreadCheckStop())
- receive_spool(sock, node);
+ receive_spool(&sock, node);
if (!CtdlThreadCheckStop())
- transmit_spool(sock, node);
+ transmit_spool(&sock, node);
}
- sock_puts(sock, "QUIT");
-bail: sock_close(sock);
+ sock_puts(&sock, "QUIT");
+bail:
+ FreeStrBuf(&CCC->sReadBuf);
+ FreeStrBuf(&CCC->sMigrateBuf);
+ if (sock != -1)
+ sock_close(sock);
network_talking_to(node, NTT_REMOVE);
}
char spoolfile[256];
if (working_ignetcfg == NULL) {
- CtdlLogPrintf(CTDL_DEBUG, "No nodes defined - not polling\n");
+ CtdlLogPrintf(CTDL_DEBUG, "network: no neighbor nodes are configured - not polling.\n");
return;
}
poll = full_poll;
if (poll == 0) {
snprintf(spoolfile,
- sizeof spoolfile,
- "%s/%s",
- ctdl_netout_dir,
- node);
+ sizeof spoolfile,
+ "%s/%s",
+ ctdl_netout_dir,
+ node
+ );
if (access(spoolfile, R_OK) == 0) {
poll = 1;
}
CtdlLogPrintf(CTDL_EMERG, "unable to create directory [%s]: %s", ctdl_netin_dir, strerror(errno));
if (chown(ctdl_netin_dir, CTDLUID, (-1)) != 0)
CtdlLogPrintf(CTDL_EMERG, "unable to set the access rights for [%s]: %s", ctdl_netin_dir, strerror(errno));
+ if ((mkdir(ctdl_nettmp_dir, 0700) != 0) && (errno != EEXIST))
+ CtdlLogPrintf(CTDL_EMERG, "unable to create directory [%s]: %s", ctdl_nettmp_dir, strerror(errno));
+ if (chown(ctdl_nettmp_dir, CTDLUID, (-1)) != 0)
+ CtdlLogPrintf(CTDL_EMERG, "unable to set the access rights for [%s]: %s", ctdl_nettmp_dir, strerror(errno));
if ((mkdir(ctdl_netout_dir, 0700) != 0) && (errno != EEXIST))
CtdlLogPrintf(CTDL_EMERG, "unable to create directory [%s]: %s", ctdl_netout_dir, strerror(errno));
if (chown(ctdl_netout_dir, CTDLUID, (-1)) != 0)
*/
if ( (time(NULL) - last_run) < config.c_net_freq ) {
full_processing = 0;
- CtdlLogPrintf(CTDL_DEBUG, "Network full processing in %ld seconds.\n", config.c_net_freq - (time(NULL)- last_run));
+ CtdlLogPrintf(CTDL_DEBUG, "Network full processing in %ld seconds.\n",
+ config.c_net_freq - (time(NULL)- last_run)
+ );
}
/*
* don't really require extremely fine granularity here, we'll do it
* with a static variable instead.
*/
- if (doing_queue) return NULL;
+ if (doing_queue) {
+ return NULL;
+ }
doing_queue = 1;
/* Load the IGnet Configuration into memory */
}
/* If there is anything in the inbound queue, process it */
- if (!CtdlThreadCheckStop())
+ if (!CtdlThreadCheckStop()) {
network_do_spoolin();
+ }
/* Save the network map back to disk */
write_network_map();
}
doing_queue = 0;
- if (!CtdlThreadCheckStop()) // Only reschedule if system is not stopping
- CtdlThreadSchedule("IGnet Network", CTDLTHREAD_BIGSTACK, network_do_queue, NULL, time(NULL) + 60);
- else
+
+ /* Reschedule this task to happen again periodically, unless the thread system indicates
+ * that the server is shutting down.
+ */
+ if (!CtdlThreadCheckStop()) {
+ CtdlThreadSchedule("IGnet Network", CTDLTHREAD_BIGSTACK,
+ network_do_queue, NULL, time(NULL) + 60
+ );
+ }
+ else {
CtdlLogPrintf(CTDL_DEBUG, "network: Task STOPPED.\n");
+ }
return NULL;
}