Write lastsent back to netconfig after sending list messages
authorArt Cancro <ajc@citadel.org>
Wed, 10 Feb 2021 19:56:30 +0000 (14:56 -0500)
committerArt Cancro <ajc@citadel.org>
Wed, 10 Feb 2021 19:56:30 +0000 (14:56 -0500)
citadel/ctdl_module.h
citadel/modules/listdeliver/serv_listdeliver.c
citadel/netconfig.c

index 9c6a90f22744fdb541c5bcb9e4122209ab30e6d9..0ddfc6970a6341a0516d8b36fd54f5bab786bea3 100644 (file)
@@ -136,13 +136,9 @@ void CtdlUnregisterServiceHook(int tcp_port,
                         void (*h_async_function) (void)
 );
 
-void CtdlRegisterFixedOutputHook(char *content_type,
-                       void (*output_function) (char *supplied_data, int len)
-);
+void CtdlRegisterFixedOutputHook(char *content_type, void (*output_function) (char *supplied_data, int len));
 void CtdlUnRegisterFixedOutputHook(char *content_type);
-
 void CtdlRegisterMaintenanceThread(char *name, void *(*thread_proc) (void *arg));
-
 void CtdlRegisterSearchFuncHook(void (*fcn_ptr)(int *, long **, const char *), char *name);
 
 /*
@@ -152,20 +148,6 @@ void CtdlRegisterSearchFuncHook(void (*fcn_ptr)(int *, long **, const char *), c
 void CtdlDisableHouseKeeping(void);
 void CtdlEnableHouseKeeping(void);
 
-/*
- * Directory services hooks for LDAP etc
- */
-
-#define DIRECTORY_USER_DEL 1   // Delete a user entry
-#define DIRECTORY_CREATE_HOST 2        // Create a host entry if not already there.
-#define DIRECTORY_CREATE_OBJECT 3      // Create a new object for directory entry
-#define DIRECTORY_ATTRIB_ADD 4 // Add an attribute to the directory entry object
-#define DIRECTORY_SAVE_OBJECT 5        // Save the object to the directory service
-#define DIRECTORY_FREE_OBJECT 6        // Free the object and its attributes
-
-int CtdlRegisterDirectoryServiceFunc(int (*func)(char *cn, char *ou, void **object), int cmd, char *module);
-int CtdlDoDirectoryServiceFunc(char *cn, char *ou, void **object, char *module, int cmd);
-
 /* TODODRW: This needs to be changed into a hook type interface
  * for now we have this horrible hack
  */
@@ -220,9 +202,8 @@ void CtdlRoomAccess(struct ctdlroom *roombuf, struct ctdluser *userbuf, int *res
 void CtdlPutRoomLock(struct ctdlroom *qrbuf);
 typedef void (*ForEachRoomCallBack)(struct ctdlroom *EachRoom, void *out_data);
 void CtdlForEachRoom(ForEachRoomCallBack CB, void *in_data);
-typedef void (*ForEachRoomNetCfgCallBack)(struct ctdlroom *EachRoom, void *out_data, char *cfg);
 char *LoadRoomNetConfigFile(long roomnum);
-void SaveChangedConfigs(void);
+void SaveRoomNetConfigFile(long roomnum, const char *raw_netconfig);
 void CtdlDeleteRoom(struct ctdlroom *qrbuf);
 int CtdlRenameRoom(char *old_name, char *new_name, int new_floor);
 void CtdlUserGoto (char *where, int display_result, int transiently, int *msgs, int *new, long *oldest, long *newest);
index 7591822bd7784f3b1af31820848078b3d82eb5c0..039937e678cda81c0f176b587c14b73b6b4c2495 100644 (file)
@@ -104,6 +104,7 @@ void listdeliver_do_msg(long msgnum, void *userdata) {
  */
 void listdeliver_sweep_room(char *roomname) {
        char *netconfig = NULL;
+       char *newnetconfig = NULL;
        long lastsent = 0;
        char buf[SIZ];
        int config_lines;
@@ -145,16 +146,30 @@ void listdeliver_sweep_room(char *roomname) {
                if (number_of_messages_processed > 0) {
                        syslog(LOG_DEBUG, "listdeliver: new lastsent is %ld", ld.msgnum);
 
-                       // FIXME write lastsent back to netconfig
-                       syslog(LOG_DEBUG, "\033[31mBEFORE:<%s>\033[0m", netconfig);
-                       syslog(LOG_DEBUG, "\033[32mAFTER:<%s>\033[0m", netconfig);
-
+                       // Update this room's netconfig with the updated lastsent
+                       netconfig = LoadRoomNetConfigFile(CC->room.QRnumber);
+                       if (!netconfig) {
+                               netconfig = strdup("");
+                       }
 
+                       // The new netconfig begins with the new lastsent directive
+                       newnetconfig = malloc(strlen(netconfig) + 1024);
+                       sprintf(newnetconfig, "lastsent|%ld\n", ld.msgnum);
 
+                       // And then we append all of the old netconfig, minus the old lastsent.  Also omit blank lines.
+                       config_lines = num_tokens(netconfig, '\n');
+                       for (i=0; i<config_lines; ++i) {
+                               extract_token(buf, netconfig, i, '\n', sizeof buf);
+                               if ( (!IsEmptyStr(buf)) && (strncasecmp(buf, "lastsent|", 9)) ) {
+                                       sprintf(&newnetconfig[strlen(newnetconfig)], "%s\n", buf);
+                               }
+                       }
 
+                       // Write the new netconfig back to disk
+                       SaveRoomNetConfigFile(CC->room.QRnumber, newnetconfig);
+                       free(newnetconfig);
                }
        }
-
        free(netconfig);
 }
 
index ff60c1027ee3369eceb6e255eedf26bf1c82411c..93b18cb2ac2af6f74802498d028e8385af229de9 100644 (file)
@@ -47,7 +47,7 @@ void netcfg_keyname(char *keybuf, long roomnum) {
 /*
  * Given a room number and a textual netconfig, convert to base64 and write to the configdb
  */
-void write_netconfig_to_configdb(long roomnum, const char *raw_netconfig) {
+void SaveRoomNetConfigFile(long roomnum, const char *raw_netconfig) {
        char keyname[25];
        char *enc;
        int enc_len;
@@ -133,7 +133,7 @@ void cmd_snet(char *argbuf) {
        }
        FreeStrBuf(&Line);
 
-       write_netconfig_to_configdb(CC->room.QRnumber, ChrPtr(TheConfig));
+       SaveRoomNetConfigFile(CC->room.QRnumber, ChrPtr(TheConfig));
        FreeStrBuf(&TheConfig);
 }
 
@@ -169,7 +169,7 @@ void convert_legacy_netcfg_files(void)
                                        if (v) {
                                                rewind(fp);
                                                if (fread(v, len, 1, fp)) {
-                                                       write_netconfig_to_configdb(roomnum, v);
+                                                       SaveRoomNetConfigFile(roomnum, v);
                                                        unlink(filename);
                                                }
                                                free(v);