X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Fnetconfig.c;h=a6dd412874a7e96d907a431c6c8c9842c2f4b5eb;hb=f131d85177c6dd27138061d8be7c078030906b7c;hp=1f68fe3ba0af8faa04d51fde5303f11987bde1d8;hpb=2807ad968981de0aae10473ee5fbd7a4c0d513bd;p=citadel.git diff --git a/citadel/netconfig.c b/citadel/netconfig.c index 1f68fe3ba..a6dd41287 100644 --- a/citadel/netconfig.c +++ b/citadel/netconfig.c @@ -1,8 +1,7 @@ /* - * This module handles shared rooms, inter-Citadel mail, and outbound - * mailing list processing. + * This module handles loading, saving, and parsing of room network configurations. * - * Copyright (c) 2000-2016 by the citadel.org team + * Copyright (c) 2000-2017 by the citadel.org team * * This program is open source software; you can redistribute it and/or modify * it under the terms of the GNU General Public License, version 3. @@ -27,6 +26,7 @@ # endif #endif #include +#include #include @@ -57,8 +57,9 @@ void RegisterRoomCfgType(const char* Name, long len, RoomNetCfg eCfg, CfgLinePar pCfg->Str.len = len; pCfg->IsSingleLine = uniq; pCfg->nSegments = nSegments; - if (CfgTypeHash == NULL) + if (CfgTypeHash == NULL) { CfgTypeHash = NewHash(1, NULL); + } Put(CfgTypeHash, Name, len, pCfg, NULL); } @@ -77,6 +78,7 @@ const CfgLineType *GetCfgTypeByStr(const char *Key, long len) } } + const CfgLineType *GetCfgTypeByEnum(RoomNetCfg eCfg, HashPos *It) { const char *Key; @@ -94,6 +96,7 @@ const CfgLineType *GetCfgTypeByEnum(RoomNetCfg eCfg, HashPos *It) return NULL; } + void ParseGeneric(const CfgLineType *ThisOne, StrBuf *Line, const char *LinePos, OneRoomNetCfg *OneRNCfg) { RoomNetCfgLine *nptr; @@ -120,6 +123,7 @@ void ParseGeneric(const CfgLineType *ThisOne, StrBuf *Line, const char *LinePos, OneRNCfg->NetConfigs[ThisOne->C] = nptr; } + void SerializeGeneric(const CfgLineType *ThisOne, StrBuf *OutputBuffer, OneRoomNetCfg *OneRNCfg, RoomNetCfgLine *data) { int i; @@ -135,6 +139,7 @@ void SerializeGeneric(const CfgLineType *ThisOne, StrBuf *OutputBuffer, OneRoomN StrBufAppendBufPlain(OutputBuffer, HKEY("\n"), 0); } + void DeleteGenericCfgLine(const CfgLineType *ThisOne, RoomNetCfgLine **data) { int i; @@ -151,6 +156,7 @@ void DeleteGenericCfgLine(const CfgLineType *ThisOne, RoomNetCfgLine **data) *data = NULL; } + RoomNetCfgLine *DuplicateOneGenericCfgLine(const RoomNetCfgLine *data) { int i; @@ -180,7 +186,6 @@ void netcfg_keyname(char *keybuf, long roomnum) } - /* * Given a room number and a textual netconfig, convert to base64 and write to the configdb */ @@ -191,7 +196,6 @@ void write_netconfig_to_configdb(long roomnum, const char *raw_netconfig) int enc_len; int len; - syslog(LOG_DEBUG, "\033[32m--- START WRITE ---\033[0m\n\033[31m%s\033[0m\n\033[32m---- END WRITE ----\033[0m", raw_netconfig); len = strlen(raw_netconfig); netcfg_keyname(keyname, roomnum); enc = malloc(len * 2); @@ -208,7 +212,6 @@ void write_netconfig_to_configdb(long roomnum, const char *raw_netconfig) } - /* * Given a room number, attempt to load the netconfig configdb entry for that room. * If it returns NULL, there is no netconfig. @@ -236,12 +239,13 @@ char *LoadRoomNetConfigFile(long roomnum) OneRoomNetCfg *ParseRoomNetConfigFile(char *serialized_data) { const char *Pos = NULL; - const char *CPos = NULL; const CfgLineType *pCfg = NULL; StrBuf *Line = NULL; StrBuf *InStr = NULL; StrBuf *Cfg = NULL; OneRoomNetCfg *OneRNCfg = NULL; + int num_lines = 0; + int i = 0; OneRNCfg = malloc(sizeof(OneRoomNetCfg)); memset(OneRNCfg, 0, sizeof(OneRoomNetCfg)); @@ -249,11 +253,10 @@ OneRoomNetCfg *ParseRoomNetConfigFile(char *serialized_data) Line = NewStrBuf(); InStr = NewStrBuf(); Cfg = NewStrBufPlain(serialized_data, -1); + num_lines = num_tokens(ChrPtr(Cfg), '\n'); - syslog(LOG_DEBUG, "\033[32m--- START READ ---\033[0m"); - while (StrBufSipLine(Line, Cfg, &CPos)) { - syslog(LOG_DEBUG, "READ NET CONFIG LINE: '\033[31m%s\033[0m'", ChrPtr(Line)); - + for (i=0; i 0) { Pos = NULL; StrBufExtract_NextToken(InStr, Line, &Pos, '|'); @@ -279,7 +282,6 @@ OneRoomNetCfg *ParseRoomNetConfigFile(char *serialized_data) } } } - syslog(LOG_DEBUG, "\033[32m---- END READ ----\033[0m"); FreeStrBuf(&InStr); FreeStrBuf(&Line); FreeStrBuf(&Cfg); @@ -301,20 +303,21 @@ void SaveRoomNetConfigFile(OneRoomNetCfg *OneRNCfg, long roomnum) { const CfgLineType *pCfg; pCfg = GetCfgTypeByEnum(eCfg, CfgIt); - if (pCfg->IsSingleLine) + if (pCfg) { - pCfg->Serializer(pCfg, OutBuffer, OneRNCfg, NULL); - } - else - { - RoomNetCfgLine *pName = OneRNCfg->NetConfigs[pCfg->C]; - while (pName != NULL) + if (pCfg->IsSingleLine) + { + pCfg->Serializer(pCfg, OutBuffer, OneRNCfg, NULL); + } + else { - pCfg->Serializer(pCfg, OutBuffer, OneRNCfg, pName); - pName = pName->next; + RoomNetCfgLine *pName = OneRNCfg->NetConfigs[pCfg->C]; + while (pName != NULL) + { + pCfg->Serializer(pCfg, OutBuffer, OneRNCfg, pName); + pName = pName->next; + } } - - } } @@ -331,7 +334,6 @@ void SaveRoomNetConfigFile(OneRoomNetCfg *OneRNCfg, long roomnum) } - void AddRoomCfgLine(OneRoomNetCfg *OneRNCfg, struct ctdlroom *qrbuf, RoomNetCfg LineType, RoomNetCfgLine *Line) { RoomNetCfgLine **pLine; @@ -433,7 +435,11 @@ void cmd_gnet(char *argbuf) char *c = LoadRoomNetConfigFile(CC->room.QRnumber); if (c) { - cprintf("%s\n", c); + int len = strlen(c); + client_write(c, len); // Can't use cprintf() here, it has a limit of 1024 bytes + if (c[len] != '\n') { + client_write(HKEY("\n")); + } free(c); } cprintf("000\n"); @@ -480,6 +486,7 @@ void DeleteCtdlNodeConf(void *vNode) free(Node); } + CtdlNodeConf *NewNode(StrBuf *SerializedNode) { const char *Pos = NULL; @@ -580,11 +587,7 @@ int is_recipient(OneRoomNetCfg *RNCfg, const char *Name) } - -int CtdlNetconfigCheckRoomaccess( - char *errmsgbuf, - size_t n, - const char* RemoteIdentifier) +int CtdlNetconfigCheckRoomaccess(char *errmsgbuf, size_t n, const char* RemoteIdentifier) { OneRoomNetCfg *RNCfg; int found; @@ -605,6 +608,7 @@ int CtdlNetconfigCheckRoomaccess( return (ERROR + NO_SUCH_USER); } found = is_recipient (RNCfg, RemoteIdentifier); + FreeRoomNetworkStruct(&RNCfg); end_critical_section(S_NETCONFIGS); if (found) { @@ -618,7 +622,6 @@ int CtdlNetconfigCheckRoomaccess( } - /* * cmd_netp() - authenticate to the server as another Citadel node polling * for network traffic @@ -631,8 +634,6 @@ void cmd_netp(char *cmdbuf) StrBuf *NodeStr; long nodelen; int v; - long lens[2]; - const char *strs[2]; const StrBuf *secret = NULL; const StrBuf *nexthop = NULL; @@ -652,20 +653,7 @@ void cmd_netp(char *cmdbuf) ); syslog(LOG_WARNING, "%s", err_buf); cprintf("%d authentication failed\n", ERROR + PASSWORD_REQUIRED); - - strs[0] = CCC->cs_addr; - lens[0] = strlen(CCC->cs_addr); - - strs[1] = "SRV_UNKNOWN"; - lens[1] = sizeof("SRV_UNKNOWN") - 1; - - CtdlAideFPMessage( - err_buf, - "IGNet Networking.", - 2, strs, (long*) &lens, - CCC->cs_pid, 0, - time(NULL)); - + CtdlAideMessage(err_buf, "IGNet Networking"); DeleteHash(&working_ignetcfg); FreeStrBuf(&NodeStr); return; @@ -680,20 +668,7 @@ void cmd_netp(char *cmdbuf) syslog(LOG_WARNING, "%s", err_buf); cprintf("%d authentication failed\n", ERROR + PASSWORD_REQUIRED); - strs[0] = CCC->cs_addr; - lens[0] = strlen(CCC->cs_addr); - - strs[1] = "SRV_PW"; - lens[1] = sizeof("SRV_PW") - 1; - - CtdlAideFPMessage( - err_buf, - "IGNet Networking.", - 2, strs, - (long*) &lens, - CCC->cs_pid, 0, - time(NULL)); - + CtdlAideMessage(err_buf, "IGNet Networking"); DeleteHash(&working_ignetcfg); FreeStrBuf(&NodeStr); return; @@ -729,6 +704,7 @@ void DeleteNetMap(void *vNetMap) free(TheNetMap); } + CtdlNetMap *NewNetMap(StrBuf *SerializedNetMap) { const char *Pos = NULL; @@ -750,6 +726,7 @@ CtdlNetMap *NewNetMap(StrBuf *SerializedNetMap) return NM; } + HashList* CtdlReadNetworkMap(void) { const char *LinePos; @@ -783,6 +760,7 @@ HashList* CtdlReadNetworkMap(void) return Hash; } + StrBuf *CtdlSerializeNetworkMap(HashList *Map) { void *vMap; @@ -930,14 +908,19 @@ void convert_legacy_netcfg_files(void) if (fp) { fseek(fp, 0L, SEEK_END); len = ftell(fp); - v = malloc(len); - if (v) { - rewind(fp); - if (fread(v, len, 1, fp)) { - write_netconfig_to_configdb(roomnum, v); - unlink(filename); + if (len > 0) { + v = malloc(len); + if (v) { + rewind(fp); + if (fread(v, len, 1, fp)) { + write_netconfig_to_configdb(roomnum, v); + unlink(filename); + } + free(v); } - free(v); + } + else { + unlink(filename); // zero length netconfig, just delete it } fclose(fp); } @@ -949,7 +932,6 @@ void convert_legacy_netcfg_files(void) } - /* * Module entry point */