]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/network/serv_netspool.c
fix dnamlen, they missed the e, so we need to follow.
[citadel.git] / citadel / modules / network / serv_netspool.c
index ed79adb8b5316ea1c6a547abc37ccbfe6a8e0a86..8a8a1e401c439a2454b0a7fc319431c0f6179b01 100644 (file)
@@ -106,12 +106,11 @@ void ParseLastSent(const CfgLineType *ThisOne, StrBuf *Line, const char *LinePos
 
 void ParseRoomAlias(const CfgLineType *ThisOne, StrBuf *Line, const char *LinePos, OneRoomNetCfg *rncfg)
 {
-/*
-       if (rncfg->RNCfg->sender != NULL)
-               continue; / * just one alowed... * /
-       extract_token(nptr->name, buf, 1, '|', sizeof nptr->name);
-       rncfg->RNCfg->sender = nptr;
-*/
+       if (rncfg->Sender != NULL)
+               return;
+
+       ParseGeneric(ThisOne, Line, LinePos, rncfg);
+       rncfg->Sender = NewStrBufDup(rncfg->NetConfigs[roommailalias]->Value[0]);
 }
 
 void ParseSubPendingLine(const CfgLineType *ThisOne, StrBuf *Line, const char *LinePos, OneRoomNetCfg *OneRNCFG)
@@ -225,6 +224,7 @@ void InspectQueuedRoom(SpoolControl **pSC,
 
 void CalcListID(SpoolControl *sc)
 {
+       StrBuf *RoomName;
        const char *err;
        int fd;
        struct CitContext *CCC = CC;
@@ -234,11 +234,11 @@ void CalcListID(SpoolControl *sc)
        assoc_file_name(filename, sizeof filename, &sc->room, ctdl_info_dir);
        fd = open(filename, 0);
 
-       if (fd != 0) {
+       if (fd > 0) {
                struct stat stbuf;
 
-               fstat(fd, &stbuf);
-               if (stbuf.st_size > 0)
+               if ((fstat(fd, &stbuf) == 0) &&
+                   (stbuf.st_size > 0))
                {
                        sc->RoomInfo = NewStrBufPlain(NULL, stbuf.st_size + 1);
                        StrBufReadBLOB(sc->RoomInfo, &fd, 0, stbuf.st_size, &err);
@@ -265,6 +265,9 @@ void CalcListID(SpoolControl *sc)
        }
 
        StrBufAppendBufPlain(sc->ListID, HKEY("<"), 0);
+       RoomName = NewStrBufPlain (sc->room.QRname, -1);
+       StrBufAsciify(RoomName, '_');
+       StrBufReplaceChars(RoomName, ' ', '_');
 
        if (StrLength(sc->Users[roommailalias]) > 0)
        {
@@ -283,7 +286,7 @@ void CalcListID(SpoolControl *sc)
        else
        {
                StrBufAppendBufPlain(sc->ListID, HKEY("room_"), 0);
-               StrBufAppendBufPlain(sc->ListID, sc->room.QRname, -1, 0);
+               StrBufAppendBuf(sc->ListID, RoomName, 0);
                StrBufAppendBufPlain(sc->ListID, HKEY("."), 0);
                StrBufAppendBufPlain(sc->ListID, config.c_fqdn, -1, 0);
                /*
@@ -300,15 +303,15 @@ void CalcListID(SpoolControl *sc)
        {
                sc->Users[roommailalias] = NewStrBuf();
                
-               StrBufPrintf(sc->Users[roommailalias],
-                            "room_%s@%s",
-                            CCC->room.QRname,
-                            config.c_fqdn);
+               StrBufAppendBufPlain(sc->Users[roommailalias], HKEY("room_"), 0);
+               StrBufAppendBuf(sc->Users[roommailalias], RoomName, 0);
+               StrBufAppendBufPlain(sc->Users[roommailalias], HKEY("@"), 0);
+               StrBufAppendBufPlain(sc->Users[roommailalias], config.c_fqdn, -1, 0);
 
-               StrBufAsciify(sc->Users[roommailalias], '_');
                StrBufLowerCase(sc->Users[roommailalias]);
        }
 
+       FreeStrBuf(&RoomName);
 }
 
 
@@ -396,6 +399,7 @@ void network_spoolout_room(SpoolControl *sc)
  */
 void network_process_buffer(char *buffer, long size, HashList *working_ignetcfg, HashList *the_netmap, int *netmap_changed)
 {
+       long len;
        struct CitContext *CCC = CC;
        StrBuf *Buf = NULL;
        struct CtdlMessage *msg = NULL;
@@ -434,8 +438,10 @@ void network_process_buffer(char *buffer, long size, HashList *working_ignetcfg,
 
        for (pos = 3; pos < size; ++pos) {
                field = buffer[pos];
-               msg->cm_fields[field] = strdup(&buffer[pos+1]);
-               pos = pos + strlen(&buffer[(int)pos]);
+               len = strlen(buffer + pos + 1);
+               msg->cm_fields[field] = malloc(len + 1);
+               memcpy (msg->cm_fields[field], buffer+ pos + 1, len + 1);
+               pos = pos + len + 1;
        }
 
        /* Check for message routing */
@@ -622,7 +628,7 @@ void network_process_file(char *filename,
        long msgend = (-1L);
        long msgcur = 0L;
        int ch;
-
+       int nMessages = 0;
 
        fp = fopen(filename, "rb");
        if (fp == NULL) {
@@ -651,6 +657,7 @@ void network_process_file(char *filename,
                }
 
                ++msgcur;
+               nMessages ++;
        }
 
        msgend = msgcur - 1;
@@ -661,8 +668,15 @@ void network_process_file(char *filename,
                                        working_ignetcfg,
                                        the_netmap,
                                        netmap_changed);
+               nMessages ++;
        }
 
+       if (nMessages > 0)
+               QN_syslog(LOG_INFO,
+                         "network: processed %d messages in %s\n",
+                         nMessages,
+                         filename);
+
        fclose(fp);
        unlink(filename);
 }
@@ -711,7 +725,7 @@ void network_do_spoolin(HashList *working_ignetcfg, HashList *the_netmap, int *n
               (filedir_entry != NULL))
        {
 #ifdef _DIRENT_HAVE_D_NAMLEN
-               d_namelen = filedir_entry->d_namelen;
+               d_namelen = filedir_entry->d_namlen;
 
 #else
                d_namelen = strlen(filedir_entry->d_name);
@@ -815,7 +829,7 @@ void network_consolidate_spoolout(HashList *working_ignetcfg, HashList *the_netm
               (filedir_entry != NULL))
        {
 #ifdef _DIRENT_HAVE_D_NAMLEN
-               d_namelen = filedir_entry->d_namelen;
+               d_namelen = filedir_entry->d_namlen;
 
 #else
                d_namelen = strlen(filedir_entry->d_name);
@@ -924,6 +938,11 @@ void network_consolidate_spoolout(HashList *working_ignetcfg, HashList *the_netm
                        do {} while ((FileMoveChunked(&FDIO, &err) > 0) && (err == NULL));
                        if (err == NULL) {
                                unlink(filename);
+                               QN_syslog(LOG_DEBUG,
+                                         "Spoolfile %s now "SIZE_T_FMT" k\n",
+                                         spooloutfilename,
+                                         (dsize + fsize)/1024
+                                       );                              
                        }
                        else {
                                nFailed++;
@@ -1017,6 +1036,21 @@ void network_consolidate_spoolout(HashList *working_ignetcfg, HashList *the_netm
        closedir(dp);
 }
 
+void free_spoolcontrol_struct(SpoolControl **sc)
+{
+       free_spoolcontrol_struct_members(*sc);
+       free(*sc);
+       *sc = NULL;
+}
+
+void free_spoolcontrol_struct_members(SpoolControl *sc)
+{
+       int i;
+       FreeStrBuf(&sc->RoomInfo);
+       FreeStrBuf(&sc->ListID);
+       for (i = 0; i < maxRoomNetCfg; i++)
+               FreeStrBuf(&sc->Users[i]);
+}