X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Fnetconfig.c;h=1b2e974aa6b42ad137397438dec0c7f620fbf27d;hb=a5e759daa03e43dfdd940e96c13cded7ba8de39c;hp=46d0d960d7df424a228be1e55fd1958f72b01a5b;hpb=a6b82fe0d2a5b38201d21320f94d235a1c0290ad;p=citadel.git diff --git a/citadel/netconfig.c b/citadel/netconfig.c index 46d0d960d..1b2e974aa 100644 --- a/citadel/netconfig.c +++ b/citadel/netconfig.c @@ -29,6 +29,11 @@ #include #include "include/ctdl_module.h" +#include "serv_extensions.h" + +void vFreeRoomNetworkStruct(void *vOneRoomNetCfg); +void FreeRoomNetworkStructContent(OneRoomNetCfg *OneRNCfg); + HashList *CfgTypeHash = NULL; HashList *RoomConfigs = NULL; /*-----------------------------------------------------------------------------* @@ -114,6 +119,7 @@ void SerializeGeneric(const CfgLineType *ThisOne, StrBuf *OutputBuffer, OneRoomN int i; StrBufAppendBufPlain(OutputBuffer, CKEY(ThisOne->Str), 0); + StrBufAppendBufPlain(OutputBuffer, HKEY("|"), 0); for (i = 0; i < ThisOne->nSegments; i++) { StrBufAppendBuf(OutputBuffer, data->Value[i], 0); @@ -127,7 +133,10 @@ void DeleteGenericCfgLine(const CfgLineType *ThisOne, RoomNetCfgLine **data) { int i; - for (i = 0; i < ThisOne->nSegments; i++) + if (*data == NULL) + return; + + for (i = 0; i < (*data)->nValues; i++) { FreeStrBuf(&(*data)->Value[i]); } @@ -137,16 +146,19 @@ void DeleteGenericCfgLine(const CfgLineType *ThisOne, RoomNetCfgLine **data) } RoomNetCfgLine *DuplicateOneGenericCfgLine(const RoomNetCfgLine *data) { + int i; RoomNetCfgLine *NewData; NewData = (RoomNetCfgLine*)malloc(sizeof(RoomNetCfgLine)); - int i; + memset(NewData, 0, sizeof(RoomNetCfgLine)); NewData->Value = (StrBuf **)malloc(sizeof(StrBuf*) * data->nValues); + memset(NewData->Value, 0, sizeof(StrBuf*) * data->nValues); for (i = 0; i < data->nValues; i++) { NewData->Value[i] = NewStrBufDup(data->Value[i]); } + NewData->nValues = data->nValues; return NewData; } int ReadRoomNetConfigFile(OneRoomNetCfg **pOneRNCfg, char *filename) @@ -157,7 +169,7 @@ int ReadRoomNetConfigFile(OneRoomNetCfg **pOneRNCfg, char *filename) const CfgLineType *pCfg; StrBuf *Line; StrBuf *InStr; - OneRoomNetCfg *OneRNCfg; + OneRoomNetCfg *OneRNCfg = NULL; fd = open(filename, O_NONBLOCK|O_RDONLY); if (fd == -1) { @@ -165,18 +177,21 @@ int ReadRoomNetConfigFile(OneRoomNetCfg **pOneRNCfg, char *filename) return 0; } if (*pOneRNCfg != NULL) + { OneRNCfg = *pOneRNCfg; + FreeRoomNetworkStructContent (OneRNCfg); + } else OneRNCfg = malloc(sizeof(OneRoomNetCfg)); memset(OneRNCfg, 0, sizeof(OneRoomNetCfg)); *pOneRNCfg = OneRNCfg; Line = NewStrBuf(); + InStr = NewStrBuf(); while (StrBufTCP_read_line(Line, &fd, 0, &ErrStr) >= 0) { if (StrLength(Line) == 0) continue; Pos = NULL; - InStr = NewStrBufPlain(NULL, StrLength(Line)); StrBufExtract_NextToken(InStr, Line, &Pos, '|'); pCfg = GetCfgTypeByStr(SKEY(InStr)); @@ -312,6 +327,34 @@ void SaveChangedConfigs(void) NULL, maxRoomNetCfg); } + + +void AddRoomCfgLine(OneRoomNetCfg *OneRNCfg, struct ctdlroom *qrbuf, RoomNetCfg LineType, RoomNetCfgLine *Line) +{ + int new = 0; + RoomNetCfgLine **pLine; + char filename[PATH_MAX]; + + if (OneRNCfg == NULL) + { + new = 1; + OneRNCfg = (OneRoomNetCfg*) malloc(sizeof(OneRoomNetCfg)); + memset(OneRNCfg, 0, sizeof(OneRoomNetCfg)); + } + pLine = &OneRNCfg->NetConfigs[LineType]; + + while(*pLine != NULL) pLine = &((*pLine)->next); + *pLine = Line; + + assoc_file_name(filename, sizeof filename, qrbuf, ctdl_netcfg_dir); + SaveRoomNetConfigFile(OneRNCfg, filename); + OneRNCfg->changed = 0; + if (new) + { + Put(RoomConfigs, LKEY(qrbuf->QRnumber), OneRNCfg, vFreeRoomNetworkStruct); + } +} + void FreeRoomNetworkStructContent(OneRoomNetCfg *OneRNCfg) { RoomNetCfg eCfg; @@ -324,11 +367,18 @@ void FreeRoomNetworkStructContent(OneRoomNetCfg *OneRNCfg) RoomNetCfgLine *pNext, *pName; pCfg = GetCfgTypeByEnum(eCfg, CfgIt); - pName= OneRNCfg->NetConfigs[pCfg->C]; + pName= OneRNCfg->NetConfigs[eCfg]; while (pName != NULL) { pNext = pName->next; - pCfg->DeAllocator(pCfg, &pName); + if (pCfg != NULL) + { + pCfg->DeAllocator(pCfg, &pName); + } + else + { + DeleteGenericCfgLine(NULL, &pName); + } pName = pNext; } } @@ -337,6 +387,7 @@ void FreeRoomNetworkStructContent(OneRoomNetCfg *OneRNCfg) FreeStrBuf(&OneRNCfg->Sender); FreeStrBuf(&OneRNCfg->RoomInfo); FreeStrBuf(&OneRNCfg->misc); + memset(OneRNCfg, 0, sizeof(OneRoomNetCfg)); } void vFreeRoomNetworkStruct(void *vOneRoomNetCfg) { @@ -525,7 +576,6 @@ const ConstStr ForceAliases[nForceAliases] = { {HKEY("postmaster,")}, {HKEY("abuse,")} }; - void cmd_snet(char *argbuf) { struct CitContext *CCC = CC; @@ -668,7 +718,6 @@ void cmd_snet(char *argbuf) RNCfg = CtdlGetNetCfgForRoom(CCC->room.QRnumber); if (RNCfg != NULL) { - FreeRoomNetworkStructContent(RNCfg); ReadRoomNetConfigFile(&RNCfg, filename); } else @@ -676,6 +725,8 @@ void cmd_snet(char *argbuf) ReadRoomNetConfigFile(&RNCfg, filename); Put(RoomConfigs, LKEY(CCC->room.QRnumber), RNCfg, vFreeRoomNetworkStruct); } + + PerformRoomHooks(&CCC->room); } end_critical_section(S_NETCONFIGS); } @@ -800,7 +851,6 @@ int CtdlNetconfigCheckRoomaccess( const char* RemoteIdentifier) { OneRoomNetCfg *RNCfg; - char filename[SIZ]; int found; if (RemoteIdentifier == NULL) @@ -809,18 +859,18 @@ int CtdlNetconfigCheckRoomaccess( return (ERROR + USERNAME_REQUIRED); } - assoc_file_name(filename, sizeof filename, &CC->room, ctdl_netcfg_dir); begin_critical_section(S_NETCONFIGS); - if (!ReadRoomNetConfigFile(&RNCfg, filename)) + RNCfg = CtdlGetNetCfgForRoom (CC->room.QRnumber); + if (RNCfg == NULL) { end_critical_section(S_NETCONFIGS); snprintf(errmsgbuf, n, "This mailing list only accepts posts from subscribers."); return (ERROR + NO_SUCH_USER); } - end_critical_section(S_NETCONFIGS); found = is_recipient (RNCfg, RemoteIdentifier); - vFreeRoomNetworkStruct(&RNCfg); + end_critical_section(S_NETCONFIGS); + if (found) { return (0); }