#include "serv_network.h"
#include "clientsocket.h"
#include "file_ops.h"
+#include "citadel_dirs.h"
#ifndef HAVE_SNPRINTF
#include "snprintf.h"
FILE *fp;
if (CtdlAccessCheck(ac_room_aide)) return;
- assoc_file_name(filename, sizeof filename, &CC->room, "netconfigs");
+ assoc_file_name(filename, sizeof filename, &CC->room, ctdl_netcfg_dir);
cprintf("%d Network settings for room #%ld <%s>\n",
LISTING_FOLLOWS,
CC->room.QRnumber, CC->room.QRname);
if (CtdlAccessCheck(ac_room_aide)) return;
CtdlMakeTempFileName(tempfilename, sizeof tempfilename);
- assoc_file_name(filename, sizeof filename, &CC->room, "netconfigs");
+ assoc_file_name(filename, sizeof filename, &CC->room, ctdl_netcfg_dir);
fp = fopen(tempfilename, "w");
if (fp == NULL) {
/*
* Process IGnet push shares
*/
- if (sc->ignet_push_shares != NULL) {
-
- msg = CtdlFetchMessage(msgnum, 1);
- if (msg != NULL) {
- size_t newpath_len;
+ msg = CtdlFetchMessage(msgnum, 1);
+ if (msg != NULL) {
+ size_t newpath_len;
- /* Prepend our node name to the Path field whenever
- * sending a message to another IGnet node
- */
- if (msg->cm_fields['P'] == NULL) {
- msg->cm_fields['P'] = strdup("username");
- }
- newpath_len = strlen(msg->cm_fields['P']) +
- strlen(config.c_nodename) + 2;
- newpath = malloc(newpath_len);
- snprintf(newpath, newpath_len, "%s!%s",
- config.c_nodename, msg->cm_fields['P']);
- free(msg->cm_fields['P']);
- msg->cm_fields['P'] = newpath;
-
- /*
- * Determine if this message is set to be deleted
- * after sending out on the network
- */
- if (msg->cm_fields['S'] != NULL) {
- if (!strcasecmp(msg->cm_fields['S'],
- "CANCEL")) {
- delete_after_send = 1;
- }
+ /* Prepend our node name to the Path field whenever
+ * sending a message to another IGnet node
+ */
+ if (msg->cm_fields['P'] == NULL) {
+ msg->cm_fields['P'] = strdup("username");
+ }
+ newpath_len = strlen(msg->cm_fields['P']) +
+ strlen(config.c_nodename) + 2;
+ newpath = malloc(newpath_len);
+ snprintf(newpath, newpath_len, "%s!%s",
+ config.c_nodename, msg->cm_fields['P']);
+ free(msg->cm_fields['P']);
+ msg->cm_fields['P'] = newpath;
+
+ /*
+ * Determine if this message is set to be deleted
+ * after sending out on the network
+ */
+ if (msg->cm_fields['S'] != NULL) {
+ if (!strcasecmp(msg->cm_fields['S'], "CANCEL")) {
+ delete_after_send = 1;
}
+ }
- /* Now send it to every node */
- for (mptr = sc->ignet_push_shares; mptr != NULL;
- mptr = mptr->next) {
+ /* Now send it to every node */
+ if (sc->ignet_push_shares != NULL)
+ for (mptr = sc->ignet_push_shares; mptr != NULL;
+ mptr = mptr->next) {
- send = 1;
+ send = 1;
- /* Check for valid node name */
- if (is_valid_node(NULL, NULL, mptr->remote_nodename) != 0) {
- lprintf(CTDL_ERR, "Invalid node <%s>\n",
- mptr->remote_nodename);
- send = 0;
- }
+ /* Check for valid node name */
+ if (is_valid_node(NULL, NULL, mptr->remote_nodename) != 0) {
+ lprintf(CTDL_ERR, "Invalid node <%s>\n",
+ mptr->remote_nodename);
+ send = 0;
+ }
- /* Check for split horizon */
- lprintf(CTDL_DEBUG, "Path is %s\n", msg->cm_fields['P']);
- bang = num_tokens(msg->cm_fields['P'], '!');
- if (bang > 1) for (i=0; i<(bang-1); ++i) {
- extract_token(buf, msg->cm_fields['P'],
- i, '!', sizeof buf);
- if (!strcasecmp(buf, mptr->remote_nodename)) {
- send = 0;
- }
+ /* Check for split horizon */
+ lprintf(CTDL_DEBUG, "Path is %s\n", msg->cm_fields['P']);
+ bang = num_tokens(msg->cm_fields['P'], '!');
+ if (bang > 1) for (i=0; i<(bang-1); ++i) {
+ extract_token(buf, msg->cm_fields['P'],
+ i, '!', sizeof buf);
+ if (!strcasecmp(buf, mptr->remote_nodename)) {
+ send = 0;
}
+ }
- /* Send the message */
- if (send == 1) {
+ /* Send the message */
+ if (send == 1) {
- /*
- * Force the message to appear in the correct room
- * on the far end by setting the C field correctly
- */
- if (msg->cm_fields['C'] != NULL) {
- free(msg->cm_fields['C']);
- }
- if (strlen(mptr->remote_roomname) > 0) {
- msg->cm_fields['C'] = strdup(mptr->remote_roomname);
- }
- else {
- msg->cm_fields['C'] = strdup(CC->room.QRname);
- }
+ /*
+ * Force the message to appear in the correct room
+ * on the far end by setting the C field correctly
+ */
+ if (msg->cm_fields['C'] != NULL) {
+ free(msg->cm_fields['C']);
+ }
+ if (strlen(mptr->remote_roomname) > 0) {
+ msg->cm_fields['C'] = strdup(mptr->remote_roomname);
+ }
+ else {
+ msg->cm_fields['C'] = strdup(CC->room.QRname);
+ }
- /* serialize it for transmission */
- serialize_message(&sermsg, msg);
+ /* serialize it for transmission */
+ serialize_message(&sermsg, msg);
+ if (sermsg.len > 0) {
/* write it to the spool file */
- snprintf(filename, sizeof filename,
-#ifndef HAVE_SPOOL_DIR
- "."
-#else
- SPOOL_DIR
-#endif /* HAVE_SPOOL_DIR */
- "/network/spoolout/%s",
- mptr->remote_nodename);
+ snprintf(filename, sizeof filename,"%s/%s",
+ ctdl_netout_dir,
+ mptr->remote_nodename);
lprintf(CTDL_DEBUG, "Appending to %s\n", filename);
fp = fopen(filename, "ab");
if (fp != NULL) {
else {
lprintf(CTDL_ERR, "%s: %s\n", filename, strerror(errno));
}
-
+
/* free the serialized version */
free(sermsg.ser);
}
+
}
- CtdlFreeMessage(msg);
}
+ CtdlFreeMessage(msg);
}
/* update lastsent */
/* Delete this message if delete-after-send is set */
if (delete_after_send) {
- CtdlDeleteMessages(CC->room.QRname, msgnum, "", 0);
+ CtdlDeleteMessages(CC->room.QRname, &msgnum, 1, "", 0);
}
}
}
memset(&sc, 0, sizeof(struct SpoolControl));
- assoc_file_name(filename, sizeof filename, &CC->room, "netconfigs");
+ assoc_file_name(filename, sizeof filename, &CC->room, ctdl_netcfg_dir);
begin_critical_section(S_NETCONFIGS);
}
/* Do something useful */
- CtdlForEachMessage(MSGS_GT, sc.lastsent, NULL, NULL,
+ CtdlForEachMessage(MSGS_GT, sc.lastsent, NULL, NULL, NULL,
network_spool_msg, &sc);
/* If we wrote a digest, deliver it and then close it */
FILE *fp;
/* Grab the configuration line we're looking for */
- assoc_file_name(filename, sizeof filename, &CC->room, "netconfigs");
+ assoc_file_name(filename, sizeof filename, &CC->room, ctdl_netcfg_dir);
begin_critical_section(S_NETCONFIGS);
fp = fopen(filename, "r");
if (fp == NULL) {
if (!found_node) return(-1);
/* Send ALL messages */
- num_spooled = CtdlForEachMessage(MSGS_ALL, 0L, NULL, NULL,
+ num_spooled = CtdlForEachMessage(MSGS_ALL, 0L, NULL, NULL, NULL,
network_spool_msg, &sc);
/* Concise cleanup because we know there's only one node in the sc */
if (strlen(nexthop) == 0) {
strcpy(nexthop, msg->cm_fields['D']);
}
- snprintf(filename, sizeof filename,
-#ifndef HAVE_SPOOL_DIR
- "."
-#else
- SPOOL_DIR
-#endif /* HAVE_SPOOL_DIR */
- "/network/spoolout/%s", nexthop);
+ snprintf(filename,
+ sizeof filename,
+ "%s/%s",
+ ctdl_netout_dir,
+ nexthop);
lprintf(CTDL_DEBUG, "Appending to %s\n", filename);
fp = fopen(filename, "ab");
if (fp != NULL) {
struct stat statbuf;
char filename[256];
static time_t last_spoolin_mtime = 0L;
- const char *spoolin_dirname =
-#ifndef HAVE_SPOOL_DIR
- "."
-#else
- SPOOL_DIR
-#endif /* HAVE_SPOOL_DIR */
- "/network/spoolin";
/*
* Check the spoolin directory's modification time. If it hasn't
* been touched, we don't need to scan it.
*/
- if (stat(spoolin_dirname, &statbuf)) return;
+ if (stat(ctdl_netin_dir, &statbuf)) return;
if (statbuf.st_mtime == last_spoolin_mtime) {
lprintf(CTDL_DEBUG, "network: nothing in inbound queue\n");
return;
/*
* Ok, there's something interesting in there, so scan it.
*/
- dp = opendir(spoolin_dirname);
+ dp = opendir(ctdl_netin_dir);
if (dp == NULL) return;
while (d = readdir(dp), d != NULL) {
if ((strcmp(d->d_name, ".")) && (strcmp(d->d_name, ".."))) {
- snprintf(filename, sizeof filename,
-#ifndef HAVE_SPOOL_DIR
- "."
-#else
- SPOOL_DIR
-#endif /* HAVE_SPOOL_DIR */
- "/network/spoolin/%s", d->d_name);
+ snprintf(filename,
+ sizeof filename,
+ "%s/%s",
+ ctdl_netin_dir,
+ d->d_name);
network_process_file(filename);
}
}
char nexthop[256];
int i;
- dp = opendir(
-#ifndef HAVE_SPOOL_DIR
- "."
-#else
- SPOOL_DIR
-#endif /* HAVE_SPOOL_DIR */
- "/network/spoolout");
+ dp = opendir(ctdl_netout_dir);
if (dp == NULL) return;
while (d = readdir(dp), d != NULL) {
if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, ".."))
continue;
- snprintf(filename, sizeof filename,
-#ifndef HAVE_SPOOL_DIR
- "."
-#else
- SPOOL_DIR
-#endif /* HAVE_SPOOL_DIR */
- "/network/spoolout/%s", d->d_name);
+ snprintf(filename,
+ sizeof filename,
+ "%s/%s",
+ ctdl_netout_dir,
+ d->d_name);
strcpy(nexthop, "");
i = is_valid_node(nexthop, NULL, d->d_name);
download_len, remote_nodename);
lprintf(CTDL_DEBUG, "%s", buf);
/* TODO: make move inline. forking is verry expensive. */
- snprintf(buf, sizeof buf, "mv %s "
-#ifndef HAVE_SPOOL_DIR
- "."
-#else
- SPOOL_DIR
-#endif /* HAVE_SPOOL_DIR */
- "/network/spoolin/%s.%ld",
- tempfilename, remote_nodename, (long) getpid());
+ snprintf(buf,
+ sizeof buf,
+ "mv %s %s/%s.%ld",
+ tempfilename,
+ ctdl_netin_dir,
+ remote_nodename,
+ (long) getpid());
system(buf);
}
}
snprintf(sfname, sizeof sfname,
-#ifndef HAVE_SPOOL_DIR
- "."
-#else
- SPOOL_DIR
-#endif /* HAVE_SPOOL_DIR */
- "/network/spoolout/%s", remote_nodename);
+ "%s/%s",
+ ctdl_netout_dir,
+ remote_nodename);
fd = open(sfname, O_RDONLY);
if (fd < 0) {
if (errno != ENOENT) {
&& (strlen(host) > 0) && strlen(port) > 0) {
poll = full_poll;
if (poll == 0) {
- snprintf(spoolfile, sizeof spoolfile,
-#ifndef HAVE_SPOOL_DIR
- "."
-#else
- SPOOL_DIR
-#endif
- "/network/spoolout/%s", node);
+ snprintf(spoolfile,
+ sizeof spoolfile,
+ "%s/%s",
+ ctdl_netout_dir,
+ node);
if (access(spoolfile, R_OK) == 0) {
poll = 1;
}
* It's ok if these directories already exist. Just fail silently.
*/
void create_spool_dirs(void) {
-#ifndef HAVE_SPOOL_DIR
- mkdir("./network", 0700);
- chown("./network", CTDLUID, (-1));
- mkdir("./network/spoolin", 0700);
- chown("./network/spoolin", CTDLUID, (-1));
- mkdir("./network/spoolout", 0700);
- chown("./network/spoolout", CTDLUID, (-1));
-#else
- mkdir(SPOOL_DIR "/network", 0700);
- chown(SPOOL_DIR "./network", CTDLUID, (-1));
- mkdir(SPOOL_DIR "/network/spoolin", 0700);
- chown(SPOOL_DIR "./network/spoolin", CTDLUID, (-1));
- mkdir(SPOOL_DIR "/network/spoolout", 0700);
- chown(SPOOL_DIR "./network/spoolout", CTDLUID, (-1));
-#endif /* HAVE_SPOOL_DIR */
+ mkdir(ctdl_spool_dir, 0700);
+ chown(ctdl_spool_dir, CTDLUID, (-1));
+ mkdir(ctdl_netin_dir, 0700);
+ chown(ctdl_netin_dir, CTDLUID, (-1));
+ mkdir(ctdl_netout_dir, 0700);
+ chown(ctdl_netout_dir, CTDLUID, (-1));
}