NETCFG: make basic parsing
[citadel.git] / citadel / include / ctdl_module.h
index 9b7f8e2f96ae460f671a8cddfb8c39561987abfb..25a00fa70d250eaef5e6cad520ebcf4e0144493c 100644 (file)
 #endif
 #include <limits.h>
 
-
-#ifndef HAVE_SNPRINTF
-#include "snprintf.h"
-#endif
-
-
 #include <libcitadel.h>
 
 #include "server.h"
 
 #define CTDL_UPGRADE_CALL(module_name) ctdl_module_##module_name##_upgrade ()
 
-#define CtdlAideMessage(TEXT, SUBJECT) quickie_message("Citadel",NULL,NULL,AIDEROOM,TEXT,FMT_CITADEL,SUBJECT) 
+#define CtdlAideMessage(TEXT, SUBJECT)         \
+       quickie_message(                        \
+               "Citadel",                      \
+               NULL,                           \
+               NULL,                           \
+               AIDEROOM,                       \
+               TEXT,                           \
+               FMT_CITADEL,                    \
+               SUBJECT) 
+
+
+#define CtdlAideFPMessage(TEXT, SUBJECT, N, STR, STRLEN) \
+       flood_protect_quickie_message(                   \
+               "Citadel",                               \
+               NULL,                                    \
+               NULL,                                    \
+               AIDEROOM,                                \
+               TEXT,                                    \
+               FMT_CITADEL,                             \
+               SUBJECT,                                 \
+               N,                                       \
+               STR,                                     \
+               STRLEN)
 /*
  * Hook functions available to modules.
  */
@@ -362,6 +378,90 @@ struct config {
 extern struct config config;
 
 
+typedef struct CfgLineType CfgLineType;
+typedef struct RoomNetCfgLine RoomNetCfgLine;
+typedef struct OneRoomNetCfg OneRoomNetCfg;
+
+typedef void (*CfgLineParser)(const CfgLineType *ThisOne, StrBuf *Line, const char *LinePos, OneRoomNetCfg *rncfg);
+typedef void (*CfgLineSerializer)(const CfgLineType *ThisOne, StrBuf *OuptputBuffer, OneRoomNetCfg *rncfg, RoomNetCfgLine *data);
+typedef void (*CfgLineDeAllocator)(const CfgLineType *ThisOne, RoomNetCfgLine **data);
+
+struct CfgLineType {
+       RoomNetCfg C;
+       CfgLineParser Parser;
+       CfgLineSerializer Serializer;
+       CfgLineDeAllocator DeAllocator;
+       ConstStr Str;
+       int IsSingleLine;
+       int nSegments;
+};
+
+struct RoomNetCfgLine {
+       RoomNetCfgLine *next;
+       int nValues;
+       StrBuf **Value;
+};
+
+struct OneRoomNetCfg {
+       long lastsent;
+       StrBuf *Sender;
+       StrBuf *RoomInfo;
+       RoomNetCfgLine *NetConfigs[maxRoomNetCfg];
+       StrBuf *misc;
+};
+
+
+#define CtdlREGISTERRoomCfgType(a, p, uniq, nSegs, s, d) RegisterRoomCfgType(#a, sizeof(#a) - 1, a, p, uniq, nSegs, s, d);
+void RegisterRoomCfgType(const char* Name, long len, RoomNetCfg eCfg, CfgLineParser p, int uniq, int nSegments, CfgLineSerializer s, CfgLineDeAllocator d);
+void ParseGeneric(const CfgLineType *ThisOne, StrBuf *Line, const char *LinePos, OneRoomNetCfg *sc);
+void SerializeGeneric(const CfgLineType *ThisOne, StrBuf *OutputBuffer, OneRoomNetCfg *sc, RoomNetCfgLine *data);
+void DeleteGenericCfgLine(const CfgLineType *ThisOne, RoomNetCfgLine **data);
+
+
+typedef struct _nodeconf {
+       int DeleteMe;
+       StrBuf *NodeName;
+       StrBuf *Secret;
+       StrBuf *Host;
+       StrBuf *Port;
+}CtdlNodeConf;
+
+HashList* CtdlLoadIgNetCfg(void);
+
+
+int CtdlNetconfigCheckRoomaccess(char *errmsgbuf, 
+                                size_t n,
+                                const char* RemoteIdentifier);
+
+
+typedef struct __NetMap {
+       StrBuf *NodeName;
+       time_t lastcontact;
+       StrBuf *NextHop;
+}CtdlNetMap;
+
+HashList* CtdlReadNetworkMap(void);
+StrBuf *CtdlSerializeNetworkMap(HashList *Map);
+void NetworkLearnTopology(char *node, char *path, HashList *the_netmap, int *netmap_changed);
+int CtdlIsValidNode(const StrBuf **nexthop,
+                   const StrBuf **secret,
+                   StrBuf *node,
+                   HashList *IgnetCfg,
+                   HashList *the_netmap);
+
+
+
+
+int CtdlNetworkTalkingTo(const char *nodename, long len, int operation);
+
+/*
+ * Operations that can be performed by network_talking_to()
+ */
+enum {
+        NTT_ADD,
+        NTT_REMOVE,
+        NTT_CHECK
+};
 
 /*
  * Expose API calls from user_ops.c