- FreeStrBuf(&Buf);
- CM_Free(msg);
-}
-
-void network_process_ignetpush(SpoolControl *sc, struct CtdlMessage *omsg, long *delete_after_send)
-{
- StrBuf *Recipient;
- StrBuf *RemoteRoom;
- const char *Pos = NULL;
- struct CtdlMessage *msg = NULL;
- struct CitContext *CCC = CC;
- struct ser_ret sermsg;
- char buf[SIZ];
- char filename[PATH_MAX];
- FILE *fp;
- StrBuf *Buf = NULL;
- int i;
- int bang = 0;
- int send = 1;
-
- if (sc->Users[ignet_push_share] == NULL)
- return;
-
- /*
- * Process IGnet push shares
- */
- msg = CM_Duplicate(omsg);
-
- /* Prepend our node name to the Path field whenever
- * sending a message to another IGnet node
- */
- Netmap_AddMe(msg, HKEY("username"));
-
- /*
- * Determine if this message is set to be deleted
- * after sending out on the network
- */
- if (!CM_IsEmpty(msg, eSpecialField)) {
- if (!strcasecmp(msg->cm_fields[eSpecialField], "CANCEL")) {
- *delete_after_send = 1;
- }
- }
-
- /* Now send it to every node */
- Recipient = NewStrBufPlain(NULL, StrLength(sc->Users[ignet_push_share]));
- RemoteRoom = NewStrBufPlain(NULL, StrLength(sc->Users[ignet_push_share]));
- while ((Pos != StrBufNOTNULL) &&
- StrBufExtract_NextToken(Recipient, sc->Users[ignet_push_share], &Pos, ','))
- {
- StrBufExtract_NextToken(RemoteRoom, sc->Users[ignet_push_share], &Pos, ',');
- send = 1;
- NewStrBufDupAppendFlush(&Buf, Recipient, NULL, 1);
-
- /* Check for valid node name */
- if (CtdlIsValidNode(NULL,
- NULL,
- Buf,
- sc->working_ignetcfg,
- sc->the_netmap) != 0)
- {
- QN_syslog(LOG_ERR,
- "Invalid node <%s>\n",
- ChrPtr(Recipient));
-
- send = 0;
- }
-
- /* Check for split horizon */
- QN_syslog(LOG_DEBUG, "Path is %s\n", msg->cm_fields[eMessagePath]);
- bang = num_tokens(msg->cm_fields[eMessagePath], '!');
- if (bang > 1) {
- for (i=0; i<(bang-1); ++i) {
- extract_token(buf,
- msg->cm_fields[eMessagePath],
- i, '!',
- sizeof buf);
-
- QN_syslog(LOG_DEBUG, "Compare <%s> to <%s>\n",
- buf, ChrPtr(Recipient)) ;
- if (!strcasecmp(buf, ChrPtr(Recipient))) {
- send = 0;
- break;
- }
- }
-
- QN_syslog(LOG_INFO,
- " %sSending to %s\n",
- (send)?"":"Not ",
- ChrPtr(Recipient));
- }
-
- /* 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 (StrLength(RemoteRoom) > 0) {
- CM_SetField(msg, eRemoteRoom, SKEY(RemoteRoom));
- }
- else {
- CM_SetField(msg, eRemoteRoom, CCC->room.QRname, strlen(CCC->room.QRname));
- }
-
- /* serialize it for transmission */
- CtdlSerializeMessage(&sermsg, msg);
- if (sermsg.len > 0) {
-
- /* write it to a spool file */
- snprintf(filename,
- sizeof(filename),
- "%s/%s@%lx%x",
- ctdl_netout_dir,
- ChrPtr(Recipient),
- time(NULL),
- rand()
- );
-
- QN_syslog(LOG_DEBUG,
- "Appending to %s\n",
- filename);
-
- fp = fopen(filename, "ab");
- if (fp != NULL) {
- fwrite(sermsg.ser,
- sermsg.len, 1, fp);
- fclose(fp);
- }
- else {
- QN_syslog(LOG_ERR,
- "%s: %s\n",
- filename,
- strerror(errno));
- }
-
- /* free the serialized version */
- free(sermsg.ser);
- }
- }
- }
- FreeStrBuf(&Buf);
- FreeStrBuf(&Recipient);
- FreeStrBuf(&RemoteRoom);