-/*-----------------------------------------------------------------------------*
- * Per node network configs *
- *-----------------------------------------------------------------------------*/
-void DeleteCtdlNodeConf(void *vNode)
-{
- CtdlNodeConf *Node = (CtdlNodeConf*) vNode;
- FreeStrBuf(&Node->NodeName);
- FreeStrBuf(&Node->Secret);
- FreeStrBuf(&Node->Host);
- FreeStrBuf(&Node->Port);
- free(Node);
-}
-
-
-CtdlNodeConf *NewNode(StrBuf *SerializedNode)
-{
- const char *Pos = NULL;
- CtdlNodeConf *Node;
-
- /* we need at least 4 pipes and some other text so its invalid. */
- if (StrLength(SerializedNode) < 8)
- return NULL;
- Node = (CtdlNodeConf *) malloc(sizeof(CtdlNodeConf));
-
- Node->DeleteMe = 0;
-
- Node->NodeName=NewStrBuf();
- StrBufExtract_NextToken(Node->NodeName, SerializedNode, &Pos, '|');
-
- Node->Secret=NewStrBuf();
- StrBufExtract_NextToken(Node->Secret, SerializedNode, &Pos, '|');
-
- Node->Host=NewStrBuf();
- StrBufExtract_NextToken(Node->Host, SerializedNode, &Pos, '|');
-
- Node->Port=NewStrBuf();
- StrBufExtract_NextToken(Node->Port, SerializedNode, &Pos, '|');
- return Node;
-}
-
-
-/*
- * Load or refresh the Citadel network (IGnet) configuration for this node.
- */
-HashList* CtdlLoadIgNetCfg(void)
-{
- const char *LinePos;
- char *Cfg;
- StrBuf *Buf;
- StrBuf *LineBuf;
- HashList *Hash;
- CtdlNodeConf *Node;
-
- Cfg = CtdlGetSysConfig(IGNETCFG);
- if ((Cfg == NULL) || IsEmptyStr(Cfg)) {
- if (Cfg != NULL)
- free(Cfg);
- return NULL;
- }
-
- Hash = NewHash(1, NULL);
- Buf = NewStrBufPlain(Cfg, -1);
- free(Cfg);
- LineBuf = NewStrBufPlain(NULL, StrLength(Buf));
- LinePos = NULL;
- do
- {
- StrBufSipLine(LineBuf, Buf, &LinePos);
- if (StrLength(LineBuf) != 0) {
- Node = NewNode(LineBuf);
- if (Node != NULL) {
- Put(Hash, SKEY(Node->NodeName), Node, DeleteCtdlNodeConf);
- }
- }
- } while (LinePos != StrBufNOTNULL);
- FreeStrBuf(&Buf);
- FreeStrBuf(&LineBuf);
- return Hash;
-}
-
-
-int is_recipient(OneRoomNetCfg *RNCfg, const char *Name)
-{
- const RoomNetCfg RecipientCfgs[] = {
- listrecp,
- digestrecp,
- participate,
- maxRoomNetCfg
- };
- int i;
- RoomNetCfgLine *nptr;
- size_t len;
-
- len = strlen(Name);
- i = 0;
- while (RecipientCfgs[i] != maxRoomNetCfg)
- {
- nptr = RNCfg->NetConfigs[RecipientCfgs[i]];
-
- while (nptr != NULL)
- {
- if ((StrLength(nptr->Value[0]) == len) &&
- (!strcmp(Name, ChrPtr(nptr->Value[0]))))
- {
- return 1;
- }
- nptr = nptr->next;
- }
- i++;
- }
- return 0;
-}
-
-
-int CtdlNetconfigCheckRoomaccess(char *errmsgbuf, size_t n, const char* RemoteIdentifier)
-{
- OneRoomNetCfg *RNCfg;
- int found;
-
- if (RemoteIdentifier == NULL)
- {
- snprintf(errmsgbuf, n, "Need sender to permit access.");
- return (ERROR + USERNAME_REQUIRED);
- }
-
- begin_critical_section(S_NETCONFIGS);
- 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);
- }
- found = is_recipient (RNCfg, RemoteIdentifier);
- FreeRoomNetworkStruct(&RNCfg);
- end_critical_section(S_NETCONFIGS);
-
- if (found) {
- return (0);
- }
- else {
- snprintf(errmsgbuf, n,
- "This mailing list only accepts posts from subscribers.");
- return (ERROR + NO_SUCH_USER);
- }
-}
-
-
-/*-----------------------------------------------------------------------------*
- * Network maps: evaluate other nodes *
- *-----------------------------------------------------------------------------*/
-
-void DeleteNetMap(void *vNetMap)
-{
- CtdlNetMap *TheNetMap = (CtdlNetMap*) vNetMap;
- FreeStrBuf(&TheNetMap->NodeName);
- FreeStrBuf(&TheNetMap->NextHop);
- free(TheNetMap);
-}
-
-
-CtdlNetMap *NewNetMap(StrBuf *SerializedNetMap)
-{
- const char *Pos = NULL;
- CtdlNetMap *NM;
-
- /* we need at least 3 pipes and some other text so its invalid. */
- if (StrLength(SerializedNetMap) < 6)
- return NULL;
- NM = (CtdlNetMap *) malloc(sizeof(CtdlNetMap));
-
- NM->NodeName=NewStrBuf();
- StrBufExtract_NextToken(NM->NodeName, SerializedNetMap, &Pos, '|');
-
- NM->lastcontact = StrBufExtractNext_long(SerializedNetMap, &Pos, '|');
-
- NM->NextHop=NewStrBuf();
- StrBufExtract_NextToken(NM->NextHop, SerializedNetMap, &Pos, '|');
-
- return NM;
-}
-
-
-HashList* CtdlReadNetworkMap(void)
-{
- const char *LinePos;
- char *Cfg;
- StrBuf *Buf;
- StrBuf *LineBuf;
- HashList *Hash;
- CtdlNetMap *TheNetMap;
-
- Hash = NewHash(1, NULL);
- Cfg = CtdlGetSysConfig(IGNETMAP);
- if ((Cfg == NULL) || IsEmptyStr(Cfg)) {
- if (Cfg != NULL)
- free(Cfg);
- return Hash;
- }
-
- Buf = NewStrBufPlain(Cfg, -1);
- free(Cfg);
- LineBuf = NewStrBufPlain(NULL, StrLength(Buf));
- LinePos = NULL;
- while (StrBufSipLine(Buf, LineBuf, &LinePos))
- {
- TheNetMap = NewNetMap(LineBuf);
- if (TheNetMap != NULL) { /* TODO: is the NodeName Uniq? */
- Put(Hash, SKEY(TheNetMap->NodeName), TheNetMap, DeleteNetMap);
- }
- }
- FreeStrBuf(&Buf);
- FreeStrBuf(&LineBuf);
- return Hash;
-}
-
-
-StrBuf *CtdlSerializeNetworkMap(HashList *Map)
-{
- void *vMap;
- const char *key;
- long len;
- StrBuf *Ret = NewStrBuf();
- HashPos *Pos = GetNewHashPos(Map, 0);
-
- while (GetNextHashPos(Map, Pos, &len, &key, &vMap))
- {
- CtdlNetMap *pMap = (CtdlNetMap*) vMap;
- StrBufAppendBuf(Ret, pMap->NodeName, 0);
- StrBufAppendBufPlain(Ret, HKEY("|"), 0);
-
- StrBufAppendPrintf(Ret, "%ld", pMap->lastcontact, 0);
- StrBufAppendBufPlain(Ret, HKEY("|"), 0);
-
- StrBufAppendBuf(Ret, pMap->NextHop, 0);
- StrBufAppendBufPlain(Ret, HKEY("\n"), 0);
- }
- DeleteHashPos(&Pos);
- return Ret;
-}
-
-