Use the new data format for RoomInfo in spoolcontrol (what is this for?)
[citadel.git] / citadel / modules / network / serv_netspool.c
index 3b53305b153eb074c5295541af4dd312de09e801..b13f1b8ff1f4827a91e50a7114476b72abf89962 100644 (file)
@@ -271,7 +271,6 @@ void InspectQueuedRoom(SpoolControl **pSC,
 
        sc = (SpoolControl*)malloc(sizeof(SpoolControl));
        memset(sc, 0, sizeof(SpoolControl));
-       sc->lastsent = room_to_spool->lastsent;
        sc->working_ignetcfg = working_ignetcfg;
        sc->the_netmap = the_netmap;
 
@@ -294,7 +293,7 @@ void InspectQueuedRoom(SpoolControl **pSC,
        if ( (!HaveSpoolConfig(sc->RNCfg)) || (sc->room.QRhighest <= sc->RNCfg->lastsent) ) 
        {
                // There is nothing to send from this room.
-               syslog(LOG_DEBUG, "nothing to do for <%s>", room_to_spool->name);
+               MARK_syslog(LOG_DEBUG, "Nothing to do for <%s>", room_to_spool->name);
                FreeRoomNetworkStruct(&sc->RNCfg);
                sc->RNCfg = NULL;
                free(sc);
@@ -302,6 +301,7 @@ void InspectQueuedRoom(SpoolControl **pSC,
        }
 
        sc->lastsent = sc->RNCfg->lastsent;
+       room_to_spool->lastsent = sc->lastsent;
 
        /* Now lets remember whats needed for the actual work... */
 
@@ -325,27 +325,23 @@ void InspectQueuedRoom(SpoolControl **pSC,
 void CalcListID(SpoolControl *sc)
 {
        StrBuf *RoomName;
-       const char *err;
-       int fd;
        struct CitContext *CCC = CC;
-       char filename[PATH_MAX];
 #define MAX_LISTIDLENGTH 150
 
-       assoc_file_name(filename, sizeof filename, &sc->room, ctdl_info_dir);
-       fd = open(filename, 0);
-
-       if (fd > 0) {
-               struct stat stbuf;
-
-               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);
-               }
-               close(fd);
+       // Load the room banner as the list description
+       struct CtdlMessage *msg = CtdlFetchMessage(sc->room.msgnum_info, 1, 1);
+        if (msg != NULL) {
+               CC->redirect_buffer = NewStrBufPlain(NULL, SIZ);
+                CtdlOutputPreLoadedMsg(msg, MT_CITADEL, HEADERS_NONE, 0, 0, 0);
+                CM_Free(msg);
+               sc->RoomInfo = CC->redirect_buffer;
+               CC->redirect_buffer = NULL;
+        }
+       else {
+               sc->RoomInfo = NewStrBufPlain(NULL, SIZ);
        }
 
+       // Calculate the List ID
        sc->ListID = NewStrBufPlain(NULL, 1024);
        if (StrLength(sc->RoomInfo) > 0)
        {
@@ -433,7 +429,7 @@ void network_spoolout_room(SpoolControl *sc)
         */
        memcpy (&CCC->room, &sc->room, sizeof(ctdlroom));
 
-       syslog(LOG_INFO, "network_spoolout_room(%s)", CCC->room.QRname);
+       syslog(LOG_INFO, "network_spoolout_room(room=%s, lastsent=%ld)", CCC->room.QRname, sc->lastsent);
 
        CalcListID(sc);
 
@@ -441,8 +437,7 @@ void network_spoolout_room(SpoolControl *sc)
        lastsent = sc->lastsent;
 
        /* Fetch the messages we ought to send & prepare them. */
-       CtdlForEachMessage(MSGS_GT, sc->lastsent, NULL, NULL, NULL,
-               network_spool_msg, sc);
+       CtdlForEachMessage(MSGS_GT, sc->lastsent, NULL, NULL, NULL, network_spool_msg, sc);
 
        if (StrLength(sc->Users[roommailalias]) > 0)
        {
@@ -504,19 +499,14 @@ void network_spoolout_room(SpoolControl *sc)
        }
 
        /* Now rewrite the netconfig */
-
-       // THIS IS THE ONLY PLACE WHERE WE HAVE TO REWRITE THE NETCONFIG.
-
-
+       syslog(LOG_DEBUG, "lastsent was %ld , now it is %ld", lastsent, sc->lastsent);
        if (sc->lastsent != lastsent)
        {
                OneRoomNetCfg *r;
 
                begin_critical_section(S_NETCONFIGS);
                r = CtdlGetNetCfgForRoom(sc->room.QRnumber);
-
-               r->lastsent = sc->lastsent;             // FIXME we have to do something here !!!!!!!
-
+               r->lastsent = sc->lastsent;
                SaveRoomNetConfigFile(r, sc->room.QRnumber);
                FreeRoomNetworkStruct(&r);
                end_critical_section(S_NETCONFIGS);
@@ -851,11 +841,11 @@ void network_do_spoolin(HashList *working_ignetcfg, HashList *the_netmap, int *n
         */
        if (stat(ctdl_netin_dir, &statbuf)) return;
        if (statbuf.st_mtime == last_spoolin_mtime) {
-               syslog(LOG_DEBUG, "network: nothing in inbound queue");
+               MARKM_syslog(LOG_DEBUG, "network: nothing in inbound queue");
                return;
        }
        last_spoolin_mtime = statbuf.st_mtime;
-       syslog(LOG_DEBUG, "network: processing inbound queue");
+       MARKM_syslog(LOG_DEBUG, "network: processing inbound queue");
 
        /*
         * Ok, there's something interesting in there, so scan it.