void ProcessNew::CheckInput() { auto szID = m_BoxID.Content(); auto szPwd = m_BoxPwd.Content(); auto szPwdConfirm = m_BoxPwdConfirm.Content(); if(CacheFind(true, szID)){ m_CheckID = CHECK_OK; m_LBCheckID.Clear(); }else if(CacheFind(false, szID)){ m_CheckID = CHECK_ERROR; m_LBCheckID.SetFontColor(ColorFunc::RED); m_LBCheckID.SetText("ID has been used by others"); }else{ if(szID.empty()){ m_CheckID = CHECK_NONE; }else{ if(LocalCheckID(szID.c_str())){ m_CheckID = CHECK_PENDING; m_LBCheckID.SetFontColor(ColorFunc::GREEN); m_LBCheckID.SetText("Pending..."); }else{ m_CheckID = CHECK_ERROR; m_LBCheckID.SetFontColor(ColorFunc::RED); m_LBCheckID.SetText("Invalid ID"); } } } if(szPwd.empty()){ m_CheckPwd = CHECK_NONE; }else{ if(LocalCheckPwd(szPwd.c_str())){ m_CheckPwd = CHECK_OK; m_LBCheckPwd.Clear(); }else{ m_CheckPwd = CHECK_ERROR; m_LBCheckPwd.SetFontColor(ColorFunc::RED); m_LBCheckPwd.SetText("Invalid password"); } } if(szPwdConfirm.empty()){ m_CheckPwdConfirm = CHECK_NONE; }else{ if(szPwdConfirm == szPwd){ m_CheckPwdConfirm = CHECK_OK; m_LBCheckPwdConfirm.Clear(); }else{ m_CheckPwdConfirm = CHECK_ERROR; m_LBCheckPwdConfirm.SetFontColor(ColorFunc::RED); m_LBCheckPwdConfirm.SetText("Password doesn't match"); } } }
void * DbIedgeUpdateWorker(void *arg) { char fn[] = "DbIedgeUpdateWorker():"; NetoidSNKey *key = (NetoidSNKey *)arg; CacheTableInfo cacheInfoEntry; if (key == NULL) { NETERROR(MDB, ("%s key is NULL\n", fn)); return NULL; } // Look up the entry in the cache if (CacheFind(regCache, key, &cacheInfoEntry, sizeof(cacheInfoEntry)) >= 0) { // Update the db UpdateNetoidDatabase(&cacheInfoEntry.data); } // free the key free(key); return NULL; }
void * DbCPBUpdateWorker(void *arg) { char fn[] = "DbCPBUpdateWorker():"; CallPlanBindKey *key = (CallPlanBindKey *)arg; CacheCPBEntry cacheCPBEntry; if (key == NULL) { NETERROR(MDB, ("%s key is NULL\n", fn)); return NULL; } // Look up the entry in the cache if (CacheFind(cpbCache, key, &cacheCPBEntry, sizeof(CacheCPBEntry)) >= 0) { // Update the db if (DbUpdateEntry(CALLPLANBIND_DB_FILE, DB_eCallPlanBind, (char*) &cacheCPBEntry.cpbEntry, sizeof(CallPlanBindEntry), (char*) &cacheCPBEntry.cpbEntry, sizeof(CallPlanBindKey))) { NETERROR(MDB, ("%s DbUpdateEntry error\n", fn)); } } // free the key free(key); return NULL; }
int GisPostCliFormatGkRegCmd(PostCmd *cmd, char *tags, char *cmdstr, int cmdlen, int len) { char fn[] = "GisPostCliFormatGkRegCmd():"; CacheGkInfo *cacheGkInfo = NULL, cacheGkInfoEntry; // Look up the entry in the cache if (CacheFind(gkCache, &cmd->key, &cacheGkInfoEntry, sizeof(cacheGkInfoEntry)) < 0) { NETDEBUG(MDB, NETLOG_DEBUG1, ("%s Could not find gk %s/%d\n", fn, cmd->key.regid, cmd->key.uport)); goto _return; } cacheGkInfo = &cacheGkInfoEntry; len += snprintf(CMDSTR, CMDMAX, "gk reg \"%s\" %d ", cmd->key.regid, cmd->key.uport); if (BITA_TEST(tags, TAG_EPID)) { len += snprintf(CMDSTR, CMDMAX, "epid \""); len += hex2chr(CMDSTR, CMDMAX, cacheGkInfo->endpointIDString, cacheGkInfo->endpointIDLen); len += snprintf(CMDSTR, CMDMAX, "\" "); } if (BITA_TEST(tags, TAG_GKREGTTL)) { len += snprintf(CMDSTR, CMDMAX, "ttl %d ", cacheGkInfo->regttl); } if (BITA_TEST(tags, TAG_GKFLAGS)) { len += snprintf(CMDSTR, CMDMAX, "flags %d ", cacheGkInfo->flags); } if (BITA_TEST(tags, TAG_REGSTATUS)) { len += snprintf(CMDSTR, CMDMAX, "reg %s ", (cacheGkInfo->regState == GKREG_REGISTERED)?"active":"inactive"); } _return: return len; }
void * DbRouteUpdateWorker(void *arg) { char fn[] = "DbRouteUpdateWorker():"; RouteKey *key = (RouteKey *)arg; CacheRouteEntry cacheRouteEntry; if (dbpoolid < 0) { return NULL; } if (key == NULL) { NETERROR(MDB, ("%s key is NULL\n", fn)); return NULL; } // Look up the entry in the cache if (CacheFind(cpCache, key, &cacheRouteEntry, sizeof(cacheRouteEntry)) >= 0) { // Update the db if (DbUpdateEntry(CALLROUTE_DB_FILE, DB_eCallRoute, (char*) &cacheRouteEntry.routeEntry, sizeof(RouteEntry), (char*) &cacheRouteEntry.routeEntry, sizeof(RouteKey))) { NETERROR(MDB, ("%s DbUpdateEntry error\n", fn)); } } // free the key free(key); return NULL; }
int HandleNetoidEdit(Command *comm, int argc, char **argv) { char *serNo, *ports, *temps,*ptrptr, *tok; unsigned long port = 0, portH = 0; char *vpnId; NetoidInfoEntry *netInfo = 0; CacheTableInfo cacheInfoEntry; ClientAttribs *clAttribs = 0; NetoidSNKey key = { 0 }; VpnEntry vpnKey = { 0 }, *vpnEntry = NULL; char storeb[1024], oldrealmname[REALM_NAME_LEN]; long portsState = ~CL_REGISTERED, portsStateOr = 0; int rc = xleOk, obtainedRegid = 0; char ch; if (argc <= 2) { /* Here we prompt the user for the rest of the * information */ NetoidEditHelp(comm, argc, argv); //HandleCommandUsage(comm, argc, argv); return -xleInsuffArgs; } /* Registration No */ serNo = argv[0]; ports = temps = strdup(argv[1]); tok = strtok_r(temps, "-", &ptrptr); if (tok) { port = atoi(tok); tok = strtok_r(NULL, "-", &ptrptr); if(tok){ portH = atoi(tok); } else{ portH = port; } } free(ports); argc -= 2; argv += 2; strncpy(key.regid, serNo, REG_ID_LEN); while (port <= portH) { key.uport = port; CacheAttach(); if (!obtainedRegid) { CliGetRegid(serNo, key.regid); obtainedRegid = 1; } // Look up the entry in the cache if (CacheFind(regCache, &key, &cacheInfoEntry, sizeof(cacheInfoEntry)) > 0) { netInfo = &cacheInfoEntry.data; } else if (ExtractIedge ((char *)&key, &cacheInfoEntry.data, sizeof(cacheInfoEntry.data)) > 0) { netInfo = &cacheInfoEntry.data; } CacheDetach(); if (OpenDatabases((DefCommandData *)comm->data) < 0) { return -xleOpNoPerm; } clAttribs = DbFindAttrEntry(GDBMF(comm->data, DB_eAttribs), (char *)&key, sizeof(key)); if (netInfo) { strcpy(vpnKey.vpnName, netInfo->vpnName); } if (strlen(vpnKey.vpnName)) { vpnEntry = DbFindVpnEntry(GDBMF(comm->data, DB_eVpns), (char *)&vpnKey, sizeof(VpnKey)); } CloseDatabases((DefCommandData *)comm->data); if (netInfo == 0) { CLIPRINTF((stdout, "iedge Not found in Cache/Database\n")); return -xleNoEntry; } if (clAttribs == 0) { /* Attributes not found */ clAttribs = (ClientAttribs *)malloc(sizeof(ClientAttribs)); memset(clAttribs, 0, sizeof(ClientAttribs)); } nx_strlcpy(oldrealmname, netInfo->realmName, REALM_NAME_LEN); if (argc > 0) { GetNetoidAttrPairs(comm->name, &argc, &argv, netInfo, clAttribs); goto _storedb; } if (cliLibFlags == 0) { /* we should not be getting here... */ NETERROR(MCLI, ("Invalid arguments passed from jserver\n")); rc = -xleInvalArgs; goto _error; } CLIPRINTF((stdout, "Map ISDN Code Code [%s]: ", (netInfo->ecaps1&ECAPS1_MAPISDNCC)?"enable":"disable")); GetInput(stdin, storeb, 10); if (strlen(storeb) > 0) { if(!strcmp(storeb, "enable")) { netInfo->ecaps1 |= ECAPS1_MAPISDNCC; } else { netInfo->ecaps1 &= ~ECAPS1_MAPISDNCC; } } _storedb: // Flags must be adjusted, if ip address was deleted if (!BIT_TEST(netInfo->sflags, ISSET_IPADDRESS)) { netInfo->stateFlags &= ~CL_ACTIVE; portsState &= ~CL_ACTIVE; } netInfo->stateFlags &= ~CL_REGISTERED; netInfo->mTime = time(0); if (strcmp(oldrealmname, netInfo->realmName)) { netInfo->realmId = realmNameToRealmId(netInfo->realmName); } if (UpdateNetoidInCache(netInfo) < 0) { rc = -xleExists; goto _error; } if (IsSGatekeeper(netInfo)) { // Sgatekeepers no longer allowed to be marked // static netInfo->stateFlags &= ~CL_STATIC; } /* reflect the static bit */ if (netInfo->stateFlags & CL_STATIC) { portsStateOr |= CL_STATIC; } else { portsState &= ~CL_STATIC; } if (netInfo->stateFlags & CL_STATIC) { UpdateNetoidPorts(serNo, UpdateNetoidState, &portsState, &portsStateOr, netInfo->ipaddress.l?&netInfo->ipaddress.l:NULL); } else { UpdateNetoidPorts(serNo, UpdateNetoidState, &portsState, &portsStateOr, NULL); } UpdateNetoidDatabase(netInfo); UpdateNetoidAttrDatabase((NetoidSNKey*)netInfo, clAttribs); _continue: _error: port ++; netInfo = NULL; free(clAttribs); clAttribs = NULL; if (rc < 0) { return rc; } } if (argc > 0) { /* All arguments not exhausted... */ CLIPRINTF((stdout, "%s: Error: Insufficient Arguments \n", comm->name)); return -xleInvalArgs; } return xleOk; }
int HandleNetoidReg(Command *comm, int argc, char **argv) { char *serNo, *ports, *temps,*ptrptr, *tok; unsigned long port = 0, portH = 0; NetoidInfoEntry *netInfo = 0; CacheTableInfo cacheInfoEntry; NetoidSNKey key; char storeb[1024]; long portsState = ~0, portsStateOr = 0; int rc = xleOk, regn, obtainedRegid = 0; if (argc < 2) { /* Here we prompt the user for the rest of the * information */ HandleCommandUsage(comm, argc, argv); return -xleInsuffArgs; } /* Registration No */ serNo = argv[0]; log(LOG_DEBUG, 0, "Ser No is %s\n", serNo); ports = temps = strdup(argv[1]); tok = strtok_r(temps, "-", &ptrptr); if (tok) { port = atoi(tok); tok = strtok_r(NULL, "-", &ptrptr); if(tok){ portH = atoi(tok); } else{ portH = port; } } free(ports); argc -= 2; argv += 2; strncpy(key.regid, serNo, REG_ID_LEN); while (port <= portH) { regn = 0; key.uport = port; CacheAttach(); if (!obtainedRegid) { CliGetRegid(serNo, key.regid); obtainedRegid = 1; } // Look up the entry in the cache if (CacheFind(regCache, &key, &cacheInfoEntry, sizeof(cacheInfoEntry)) > 0) { netInfo = &cacheInfoEntry.data; } else if (ExtractIedge ((char *)&key, &cacheInfoEntry.data, sizeof(cacheInfoEntry.data)) > 0) { netInfo = &cacheInfoEntry.data; } CacheDetach(); // At this point of the entry is not found, its an error // if its found, then we are going to be agnostic to where // it came from if (netInfo == NULL) { CLIPRINTF((stdout, "iedge Not found in Cache/Database\n")); rc = -xleNoEntry; goto _error; } if (argc > 0) { GetNetoidAttrPairs(comm->name, &argc, &argv, netInfo, NULL); goto _storedb; } if (cliLibFlags == 0) { /* we should not be getting here... */ NETERROR(MCLI, ("Invalid arguments passed from jserver\n")); rc = -xleInvalArgs; goto _error; } CLIPRINTF((stdout, "ser # %s port %lu:\n", serNo, port)); // Either the reg ip or the contact should // be sufficient to activate the registration CLIPRINTF((stdout, "Registration IP [%s?none]: ", FormatIpAddress(netInfo->ipaddress.l, storeb))); GetInput(stdin, storeb, CLIENT_ATTR_LEN); if (strlen(storeb) > 0) { if (!strcmp(storeb, "none")) { netInfo->stateFlags &= ~(CL_ACTIVE|CL_REGISTERED); } else /* User entered an ip address */ { netInfo->ipaddress.l = inet_addr(storeb); netInfo->ipaddress.l = ntohl(netInfo->ipaddress.l); regn = 1; netInfo->stateFlags |= CL_ACTIVE; netInfo->stateFlags |= CL_REGISTERED; BIT_SET(netInfo->sflags, ISSET_IPADDRESS); netInfo->rasip = netInfo->ipaddress.l; } time(&netInfo->rTime); } CLIPRINTF((stdout, "SIP Enable? [%s]: ", (BIT_TEST(netInfo->cap, CAP_SIP)?"true":"false"))); GetInput(stdin, storeb, 25); if (strlen(storeb) > 0) { if (!strcmp(storeb, "true")) { BIT_SET(netInfo->cap, CAP_SIP); } else { BIT_RESET(netInfo->cap, CAP_SIP); } } CLIPRINTF((stdout, "H323 Enable? [%s]: ", (BIT_TEST(netInfo->cap, CAP_H323)?"true":"false"))); GetInput(stdin, storeb, 25); if (strlen(storeb) > 0) { if (!strcmp(storeb, "true")) { BIT_SET(netInfo->cap, CAP_H323); } else { BIT_RESET(netInfo->cap, CAP_H323); } } if (BIT_TEST(netInfo->cap, CAP_H323)) { CLIPRINTF((stdout, "Q.931 port [%d]: ", netInfo->callsigport)); GetInput(stdin, storeb, CLIENT_ATTR_LEN); if (strlen(storeb) > 0) { netInfo->callsigport = atoi(storeb); } } if (BIT_TEST(netInfo->cap, CAP_SIP)) { CLIPRINTF((stdout, "Contact [%s]: ", netInfo->contact)); GetInput(stdin, storeb, SIPURL_LEN); if (strlen(storeb) > 0) { if (!strcmp(storeb, "none")) { memset(netInfo->contact, 0, SIPURL_LEN); if (!regn) { netInfo->stateFlags &= ~(CL_ACTIVE|CL_REGISTERED); } } else { strcpy(netInfo->contact, storeb); netInfo->stateFlags |= CL_ACTIVE; netInfo->stateFlags |= CL_REGISTERED; time(&netInfo->rTime); } } } if (netInfo->stateFlags&CL_DND) { CLIPRINTF((stdout, "DND [enable]: ")); } else { CLIPRINTF((stdout, "DND [disable]: ")); } GetInput(stdin, storeb, 25); if (strlen(storeb) > 0) { if (!strcmp(storeb, "enable")) { netInfo->stateFlags |= CL_DND; } else { netInfo->stateFlags &= ~CL_DND; } } if (BIT_TEST(netInfo->cap, CAP_IGATEWAY)) { CLIPRINTF((stdout, "Gateway [enable]: ")); } else { CLIPRINTF((stdout, "Gateway [disable]: ")); } GetInput(stdin, storeb, 25); if (strlen(storeb) > 0) { if (!strcmp(storeb, "enable")) { BIT_SET(netInfo->cap, CAP_IGATEWAY); } else { BIT_RESET(netInfo->cap, CAP_IGATEWAY); } } CLIPRINTF((stdout, "Current Calls [%d]: ", IedgeCalls(netInfo))); GetInput(stdin, storeb, 10); if (strlen(storeb) > 0) { IedgeCalls(netInfo) = atoi(storeb); } _storedb: if (UpdateNetoidInCache(netInfo) < 0) { rc = -xleExists; goto _error; } UpdateNetoidPorts(serNo, UpdateNetoidState, &portsState, &portsStateOr, netInfo->ipaddress.l?&netInfo->ipaddress.l:NULL); UpdateNetoidDatabase(netInfo); _continue: _error: port ++; netInfo = NULL; if (rc < 0) { return rc; } } if (argc > 0) { /* All arguments not exhausted... */ CLIPRINTF((stdout, "%s: Error: Insufficient Arguments \n", comm->name)); return -xleInvalArgs; } return xleOk; }
// Command takes regid/uport, ip4: or phone# as source int ComputeNetoidRoute(Command *comm, int argc, char **argv, int hunt) { char fn[] = "ComputeNetoidRoute():"; char *phone = 0, *url = 0, *tg = 0, *cic = 0, *dtg = NULL; char *regid = NULL, *sphone = NULL; int uport = 0, shmId; PhoNode phonode = { 0 }, fphonode = { 0 }; PhoNode phonodeTmp = { 0 }, fphonodeTmp = { 0 }; CacheTableInfo srcCacheInfoEntry, *srcCacheInfo; char *rPhone, guessPhone[PHONE_NUM_LEN] = { 0 }; InfoEntry *entry = 0x0, fentry, aentry; int rc = -xleInvalArgs, nhunt = 0, xhunt = 0; int checkZone = 0, checkVpnGroup = 0; PhoNode *phonodep = &phonode; PhoNode *fphonodep = &fphonode; ResolveHandle *rhandle,*rhandle2; RouteNode routeNode = { 0 }; ListEntry *rejectList = NULL; char crname[CALLPLAN_ATTR_LEN]; NetoidSNKey key = {0}; CacheTableInfo *info = NULL; eSourceType sourceType = ST_REGID_UPORT; RealmIP realmip; /* Lookup in the LUS's cache and VPNS's cache */ if (argc < 2) { rc = -xleInsuffArgs; goto _error; } if (strncasecmp(argv[1], "ani:", 4) == 0) { sourceType = ST_REGID_ANI; } else if (strncasecmp(argv[1], "dnis:", 5) == 0) { sourceType = ST_REGID_DNIS; } else if (strncasecmp(argv[0], "cid:", 4) == 0) { sourceType = ST_CID; } else if (strncasecmp(argv[0], "realm:", 6) == 0) { sourceType = ST_REALM_IP; } switch (argc) { case 2: if (sourceType == ST_REGID_ANI) { regid = argv[0]; sphone = argv[1] + 4; } else if (sourceType == ST_REGID_DNIS) { regid = argv[0]; phone = argv[1] + 5; } else if (sourceType == ST_CID) { sphone = argv[0] + 4; phone = argv[1]; } else { goto _error; } break; case 3: if (sourceType == ST_REGID_UPORT) { regid = argv[0]; uport = atoi(argv[1]); phone = argv[2]; } else if (sourceType == ST_REALM_IP) { realmip.realmId = realmNameToRealmId(argv[0] + 6); realmip.ipaddress = ntohl(inet_addr(argv[1])); phone = argv[2]; } else if (sourceType == ST_CID) { sphone = argv[0] + 4; phone = argv[1]; dtg = argv[2]; } else { goto _error; } break; case 4: if (sourceType == ST_REGID_UPORT) { regid = argv[0]; uport = atoi(argv[1]); } else if (sourceType == ST_REALM_IP) { realmip.realmId = realmNameToRealmId(argv[0] + 6); realmip.ipaddress = ntohl(inet_addr(argv[1])); } else { goto _error; } phone = argv[2]; dtg = argv[3]; break; #if 0 /* comment it out since it is not supported */ case 5: phonodep->ipaddress.l = ntohl(inet_addr(argv[0])); BIT_SET(phonodep->sflags, ISSET_IPADDRESS); tg = argv[1]; cic = argv[2]; sphone = argv[3]; phone = argv[4]; break; #endif default: goto _error; } checkVpnGroup = 1; checkZone = 1; #ifdef TURN_SYSLOG_LOGGING_ON /* Set the debug modules to appropriate levels */ NetLogInit(); NetLogOpen(NULL, 0, NETLOG_TERMINAL); NETLOG_SETLEVEL(MFIND, NETLOG_DEBUG4); #endif if ((shmId = CacheAttach()) == -1) { CLIPRINTF((stdout, "Unable to attach to GIS cache\n")); rc = -xleNoAccess; } else { InitCfgFromCfgParms(lsMem->cfgParms); /* Call the gis call routing api */ srcCacheInfo = &srcCacheInfoEntry; switch (sourceType) { case ST_REGID_UPORT: strncpy(phonodep->regid, regid, REG_ID_LEN); phonodep->uport = uport; BIT_SET(phonodep->sflags, ISSET_REGID); BIT_SET(phonodep->sflags, ISSET_UPORT); break; case ST_REGID_ANI: case ST_REGID_DNIS: strncpy(key.regid, regid, REG_ID_LEN); CacheGetLocks(regidCache, LOCK_READ, LOCK_BLOCK); info = CacheGet(regidCache, &key); CacheReleaseLocks(regidCache); if (info == NULL) { CLIPRINTF((stdout, "regid not found\n")); goto _return; } phonodep->ipaddress.l = info->data.ipaddress.l; phonodep->realmId = info->data.realmId; BIT_SET(phonodep->sflags, ISSET_IPADDRESS); if (sourceType == ST_REGID_ANI) { strncpy(phonodep->phone, sphone, PHONE_NUM_LEN); BIT_SET(phonodep->sflags, ISSET_PHONE); } break; case ST_REALM_IP: CacheGetLocks(ipCache, LOCK_READ, LOCK_BLOCK); info = CacheGet(ipCache, &realmip); CacheReleaseLocks(ipCache); if (info == NULL) { CLIPRINTF((stdout, "source not found\n")); goto _return; } phonodep->ipaddress.l = info->data.ipaddress.l; phonodep->realmId = info->data.realmId; BIT_SET(phonodep->sflags, ISSET_IPADDRESS); break; case ST_CID: if (CacheFind(phoneCache, sphone, srcCacheInfo, sizeof(CacheTableInfo)) < 0) { CLIPRINTF((stdout, "caller not found\n")); rc = -xleInvalArgs; goto _return; } phonodep->ipaddress.l = srcCacheInfo->data.ipaddress.l; phonodep->realmId = srcCacheInfo->data.realmId; BIT_SET(phonodep->sflags, ISSET_IPADDRESS); strncpy(phonodep->phone, sphone, PHONE_NUM_LEN); BIT_SET(phonodep->sflags, ISSET_PHONE); } if (phone) { strncpy(fphonodep->phone, phone, PHONE_NUM_LEN); BIT_SET(fphonodep->sflags, ISSET_PHONE); } /* Initialize the rhandle */ rhandle = GisAllocRHandle(); rhandle->phonodep = phonodep; rhandle->rfphonodep = fphonodep; rhandle->dtg = dtg; rhandle->crname = crname; memset(&rhandle->sVpn, 0, sizeof(VpnEntry)); memset(rhandle->sZone, 0, ZONE_LEN); /* Get the originator's entry, straight from database. It may * be faster to look him up from the database (not true when there * are lesser netoids */ if (FillSourceCacheForCallerId(phonodep, "", tg, cic, phone, srcCacheInfo) < 0) { if (!allowSrcAll) { CLIPRINTF((stdout, "%s No Src Entry Found\n", fn)); rc = -xleNoEntry; goto _return; } } else { CLIPRINTF((stdout, "\tFound SRC %s/%lu\n", srcCacheInfo->data.regid, srcCacheInfo->data.uport)); SetPhonodeFromDb(phonodep, &srcCacheInfo->data); // copy back whatever the user specified! if (sourceType == ST_CID) { strncpy(phonodep->phone, sphone, PHONE_NUM_LEN); BIT_SET(phonodep->sflags, ISSET_PHONE); } else { nx_strlcpy(phonodep->regid, srcCacheInfo->data.regid, REG_ID_LEN); phonodep->uport = srcCacheInfo->data.uport; BIT_SET(phonodep->sflags, ISSET_REGID); BIT_SET(phonodep->sflags, ISSET_UPORT); } } if (hunt) { xhunt = srcCacheInfo->data.maxHunts; if (xhunt == 0) { xhunt = maxHunts; } else if (xhunt > SYSTEM_MAX_HUNTS) { xhunt = SYSTEM_MAX_HUNTS; } } if(!allowHairPin) { // Hairpin is NOT allowed, add src into reject list. // If src is not found, add the src ip addr // Add it to the resolve handle reject list // and remember to free it up later GwAddPhoNodeToRejectList(phonodep, NULL, &rhandle->destRejectList, malloc); } rc = xleOk; entry = &srcCacheInfo->data; FindIedgeVpn(entry->vpnName, &rhandle->sVpn); nx_strlcpy(rhandle->sZone, entry->zone, ZONE_LEN); rhandle->scpname = entry->cpname; memcpy(&routeNode.xphonode, rhandle->rfphonodep, sizeof(PhoNode)); if (!hunt) { CLIPRINTF((stdout, "\t----------------------\n")); } /* Set policy */ rhandle->checkZone = 1; rhandle->checkVpnGroup = 1; rhandle->reservePort = 0; rhandle->phoneChange = 1; rhandle->primary = 0; if (srcCacheInfo->data.srcEgressTG[0] != '\0') { rhandle->dtg = srcCacheInfo->data.srcEgressTG; } memcpy(&phonodeTmp, rhandle->phonodep, sizeof(PhoNode)); memcpy(&fphonodeTmp, rhandle->rfphonodep, sizeof(PhoNode)); _resolve: memcpy(rhandle->phonodep, &phonodeTmp, sizeof(PhoNode)); memcpy(rhandle->rfphonodep, &fphonodeTmp, sizeof(PhoNode)); memset(crname, 0, CALLPLAN_ATTR_LEN); ResolvePhoneLocally(rhandle, hunt?0:_CliRouteLogFn); switch (rhandle->result) { case CACHE_FOUND: case CACHE_INPROG: memcpy(&routeNode.yphonode, rhandle->rfphonodep, sizeof(PhoNode)); routeNode.branch = rhandle->primary; routeNode.crname = rhandle->crname; if (hunt) { CLIPRINTF((stdout, "\t------- result %d --------\n", nhunt+1)); } else { CLIPRINTF((stdout, "\t------- final result --------\n")); } if (regid) CLIPRINTF((stdout, "\tSRC %s/%lu DEST %s\n", phonodep->regid, phonodep->uport, fphonodep->phone)); else CLIPRINTF((stdout, "\tSRC %s DEST %s\n", phonodep->phone, fphonodep->phone)); _CliRouteLogFn(&routeNode); // make sure we don't get into some infinite loop if (hunt && ++nhunt < xhunt) { GwAddPhoNodeToRejectList(rhandle->rfphonodep, rhandle->crname, &rhandle->destRejectList, malloc); goto _resolve; } break; case CACHE_NOTFOUND: routeNode.branch = rhandle->primary; routeNode.rejectReason = nextoneNoEntry; if (!nhunt) { CLIPRINTF((stdout, "\t-------no result--------\n")); if (regid) CLIPRINTF((stdout, "\tSRC %s/%lu DEST %s\n", phonodep->regid, phonodep->uport, fphonodep->phone)); else CLIPRINTF((stdout, "\tSRC %s DEST %s\n", phonodep->phone, fphonodep->phone)); _CliRouteLogFn(&routeNode); } goto _finish; break; default: break; } _finish: CLIPRINTF((stdout, "\t-------end--------\n")); if (rhandle->destRejectList) { GwFreeRejectList(rhandle->destRejectList, free); } GisFreeRHandle(rhandle); _return: CacheDetach(); } return rc; _error: /* Here we prompt the user for the rest of the * information */ HandleCommandUsage(comm, argc, argv); return rc; }
int HandleNetoidVpns(Command *comm, int argc, char **argv) { char fn[] = "HandleNetoidVpns():"; char *serNo, *ports, *temps,*ptrptr, *tok; unsigned long port = 0, portH = 0; char *vpnName; NetoidSNKey key; NetoidInfoEntry *netInfo = NULL; CacheTableInfo cacheInfoEntry; VpnEntry vpnKey = { 0 }, *vpnEntry = NULL; int shmId; void *addr; long portsState = ~CL_REGISTERED; int rc = xleOk, obtainedRegid = 0; if (argc < 2) { /* Here we prompt the user for the rest of the * information */ HandleCommandUsage(comm, argc, argv); return -xleInsuffArgs; } /* Registration No */ serNo = argv[0]; ports = temps = strdup(argv[1]); tok = strtok_r(temps, "-", &ptrptr); if (tok) { port = atoi(tok); tok = strtok_r(NULL, "-", &ptrptr); if(tok){ portH = atoi(tok); } else{ portH = port; } } free(ports); argc -= 2; argv += 2; strncpy(key.regid, serNo, REG_ID_LEN); while ((port <= portH) && (argc > 0)) { key.uport = port; CacheAttach(); if (!obtainedRegid) { CliGetRegid(serNo, key.regid); obtainedRegid = 1; } // Look up the entry in the cache if (CacheFind(regCache, &key, &cacheInfoEntry, sizeof(cacheInfoEntry)) > 0) { netInfo = &cacheInfoEntry.data; } else if (ExtractIedge ((char *)&key, &cacheInfoEntry.data, sizeof(cacheInfoEntry.data)) > 0) { netInfo = &cacheInfoEntry.data; } CacheDetach(); if (OpenDatabases((DefCommandData *)comm->data) < 0) { return -xleOpNoPerm; } /* This port has a specified vpn */ vpnName = argv[0]; if (strlen(vpnName)) { strcpy(vpnKey.vpnName, vpnName); vpnEntry = DbFindVpnEntry(GDBMF(comm->data, DB_eVpns), (char *)&vpnKey, sizeof(VpnKey)); } CloseDatabases((DefCommandData *)comm->data); if (!netInfo) { CLIPRINTF((stdout, "%s: Unable to find the iedge %s\n", fn, serNo)); rc = -xleNoEntry; goto _error; } strcpy(netInfo->vpnName, vpnName); AssignIedgePhone(netInfo, vpnEntry); netInfo->stateFlags &= ~CL_REGISTERED; netInfo->mTime = time(0); if (UpdateNetoidInCache(netInfo) < 0) { rc = -xleExists; goto _error; } UpdateNetoidPorts(serNo, UpdateNetoidState, &portsState, NULL, NULL); UpdateNetoidDatabase(netInfo); netInfo = NULL; if (vpnEntry) { free(vpnEntry); vpnEntry = NULL; } port ++; } return xleOk; _error: if (netInfo) { free(netInfo); } if (vpnEntry) { free(vpnEntry); } return(rc); }
int HandleNetoidZone(Command *comm, int argc, char **argv) { char fn[] = "HandleNetoidZone():"; char *serNo, *ports, *temps,*ptrptr, *tok; unsigned long port = 0, portH = 0; NetoidSNKey key; NetoidInfoEntry *netInfo = NULL; CacheTableInfo cacheInfoEntry; int rc = xleOk, obtainedRegid = 0; log(LOG_DEBUG, 0, "Entering Netoid Zone with argc=%d\n", argc); if (argc < 2) { /* Here we prompt the user for the rest of the * information */ HandleCommandUsage(comm, argc, argv); return -xleInsuffArgs; } /* Registration No */ serNo = argv[0]; log(LOG_DEBUG, 0, "Ser No is %s\n", serNo); ports = temps = strdup(argv[1]); tok = strtok_r(temps, "-", &ptrptr); if (tok) { port = atoi(tok); tok = strtok_r(NULL, "-", &ptrptr); if(tok){ portH = atoi(tok); } else{ portH = port; } } free(ports); log(LOG_DEBUG, 0, "Ports is (%d..%d)\n", port, portH); argc -= 2; argv += 2; strncpy(key.regid, serNo, REG_ID_LEN); while (port <= portH) { key.uport = port; CacheAttach(); if (!obtainedRegid) { CliGetRegid(serNo, key.regid); obtainedRegid = 1; } // Look up the entry in the cache if (CacheFind(regCache, &key, &cacheInfoEntry, sizeof(cacheInfoEntry)) > 0) { netInfo = &cacheInfoEntry.data; } else if (ExtractIedge ((char *)&key, &cacheInfoEntry.data, sizeof(cacheInfoEntry.data)) > 0) { netInfo = &cacheInfoEntry.data; } CacheDetach(); if (!netInfo) { log(LOG_DEBUG, 0, "%s: Unable to find the iedge %s\n", fn, serNo); return -xleNoEntry; } if (argc -- > 0) { /* This port has a specified zone num */ log(LOG_DEBUG, 0, "Zone is %s\n", argv[0]); strncpy(netInfo->zone, argv[0], ZONE_LEN); argv ++; } netInfo->mTime = time(0); if (OpenDatabases((DefCommandData *)comm->data) < 0) { return -xleOpNoPerm; } /* Read the Vpn information here */ if (DbStoreInfoEntry(GDBMF(comm->data, DB_eNetoids), netInfo, (char *)netInfo, sizeof(NetoidSNKey)) < 0) { log(LOG_ERR, errno, "database store error \n"); } CloseDatabases((DefCommandData *)comm->data); /* If this netoid is in the cache, delete it */ UpdateNetoidInCache(netInfo); port ++; } return xleOk; }
int HandleNetoidEmail(Command *comm, int argc, char **argv) { char fn[] = "HandleNetoidEmail():"; char *serNo, *ports, *temps,*ptrptr, *tok; unsigned long port = 0, portH = 0; NetoidSNKey key; NetoidInfoEntry *netInfo = NULL; CacheTableInfo cacheInfoEntry; int rc = xleOk, obtainedRegid = 0; if (argc < 2) { /* Here we prompt the user for the rest of the * information */ HandleCommandUsage(comm, argc, argv); return -xleInsuffArgs; } /* Registration No */ serNo = argv[0]; ports = temps = strdup(argv[1]); tok = strtok_r(temps, "-", &ptrptr); if (tok) { port = atoi(tok); tok = strtok_r(NULL, "-", &ptrptr); if(tok){ portH = atoi(tok); } else{ portH = port; } } free(ports); argc -= 2; argv += 2; strncpy(key.regid, serNo, REG_ID_LEN); while (port <= portH) { key.uport = port; CacheAttach(); if (!obtainedRegid) { CliGetRegid(serNo, key.regid); obtainedRegid = 1; } // Look up the entry in the cache if (CacheFind(regCache, &key, &cacheInfoEntry, sizeof(cacheInfoEntry)) > 0) { netInfo = &cacheInfoEntry.data; } else if (ExtractIedge ((char *)&key, &cacheInfoEntry.data, sizeof(cacheInfoEntry.data)) > 0) { netInfo = &cacheInfoEntry.data; } CacheDetach(); if (!netInfo) { CLIPRINTF((stdout, "%s: Unable to find the iedge %s\n", fn, serNo)); return -xleNoEntry; } if (argc -- > 0) { /* This port has a specified phone num */ strncpy(netInfo->email, argv[0], EMAIL_LEN); if (strlen(netInfo->email)) { BIT_SET(netInfo->sflags, ISSET_EMAIL); } else { BIT_RESET(netInfo->sflags, ISSET_EMAIL); } argv ++; } netInfo->stateFlags &= ~CL_REGISTERED; netInfo->mTime = time(0); /* If this netoid is in the cache, delete it */ if (UpdateNetoidInCache(netInfo) < 0) { rc = -xleExists; goto _error; } if (OpenDatabases((DefCommandData *)comm->data) < 0) { return -xleOpNoPerm; } /* Read the Vpn information here */ if (DbStoreInfoEntry(GDBMF(comm->data, DB_eNetoids), netInfo, (char *)netInfo, sizeof(NetoidSNKey)) < 0) { NETERROR(MCLI, ("database store error\n")); } CloseDatabases((DefCommandData *)comm->data); _error: netInfo = NULL; port ++; if (rc < 0) { return rc; } } return rc; }
int HandleNetoidPhones(Command *comm, int argc, char **argv) { char fn[] = "HandleNetoidPhones():"; char *serNo, *ports, *temps,*ptrptr, *tok; unsigned long port = 0, portH = 0; NetoidSNKey key; NetoidInfoEntry *netInfo = NULL; CacheTableInfo cacheInfoEntry; VpnEntry vpnKey = { 0 }, *vpnEntry = NULL; int rc = xleOk, obtainedRegid = 0; long portsState = ~CL_REGISTERED; if (argc < 2) { /* Here we prompt the user for the rest of the * information */ HandleCommandUsage(comm, argc, argv); return -xleInsuffArgs; } /* Registration No */ serNo = argv[0]; ports = temps = strdup(argv[1]); tok = strtok_r(temps, "-", &ptrptr); if (tok) { port = atoi(tok); tok = strtok_r(NULL, "-", &ptrptr); if(tok){ portH = atoi(tok); } else{ portH = port; } } free(ports); argc -= 2; argv += 2; strncpy(key.regid, serNo, REG_ID_LEN); while (port <= portH) { key.uport = port; CacheAttach(); if (!obtainedRegid) { CliGetRegid(serNo, key.regid); obtainedRegid = 1; } // Look up the entry in the cache if (CacheFind(regCache, &key, &cacheInfoEntry, sizeof(cacheInfoEntry)) > 0) { netInfo = &cacheInfoEntry.data; } else if (ExtractIedge ((char *)&key, &cacheInfoEntry.data, sizeof(cacheInfoEntry.data)) > 0) { netInfo = &cacheInfoEntry.data; } CacheDetach(); if (OpenDatabases((DefCommandData *)comm->data) < 0) { return -xleOpNoPerm; } if (netInfo) { strcpy(vpnKey.vpnName, netInfo->vpnName); } if (strlen(vpnKey.vpnName)) { vpnEntry = DbFindVpnEntry(GDBMF(comm->data, DB_eVpns), (char *)&vpnKey, sizeof(VpnKey)); } CloseDatabases((DefCommandData *)comm->data); if (!netInfo) { /* vpn entry exists only if netInfo existed!! */ return -xleNoEntry; } if (argc -- > 0) { strcpy(netInfo->vpnPhone, argv[0]); if (strlen(netInfo->vpnPhone)) { BIT_SET(netInfo->sflags, ISSET_VPNPHONE); netInfo->vpnExtLen = strlen(netInfo->vpnPhone); } else { BIT_RESET(netInfo->sflags, ISSET_VPNPHONE); netInfo->vpnExtLen = 0; } AssignIedgePhone(netInfo, vpnEntry); argv ++; } netInfo->stateFlags &= ~CL_REGISTERED; netInfo->mTime = time(0); /* If this netoid is in the cache, delete it */ if (UpdateNetoidInCache(netInfo) < 0) { rc = -xleExists; goto _error; } UpdateNetoidPorts(serNo, UpdateNetoidState, &portsState, NULL, NULL); UpdateNetoidDatabase(netInfo); netInfo = NULL; if (vpnEntry) { free(vpnEntry); vpnEntry = NULL; } port ++; } return xleOk; _error: if (netInfo) { free(netInfo); } if (vpnEntry) { free(vpnEntry); } return rc; }
int GisPostCliFormatCRCmd(PostCmd *cmd, char *tags, char *cmdstr, int cmdlen, int len) { char fn[] = "GisPostCliFormatCRCmd():"; CacheRouteEntry *route = NULL, cacheRouteEntry; // Look up the entry in the cache if (CacheFind(cpCache, cmd->crname, &cacheRouteEntry, sizeof(CacheRouteEntry)) < 0) { NETDEBUG(MDB, NETLOG_DEBUG1, ("%s Could not find route %s\n", fn, cmd->crname)); goto _return; } route = &cacheRouteEntry; if (cmd->command == POSTCMD_CR_ADD) { len += snprintf(CMDSTR, CMDMAX, "cr add \"%s\" ", cmd->crname); } else if(cmd->command == POSTCMD_CR_EDIT) { len += snprintf(CMDSTR, CMDMAX, "cr edit \"%s\" ", cmd->crname); } if (!BITA_TEST(tags, TAG_CRMRU)) { len += snprintf(CMDSTR, CMDMAX, "dest \"%s\" ", route->routeEntry.dest); len += snprintf(CMDSTR, CMDMAX, "destlen %d ", route->routeEntry.destlen); len += snprintf(CMDSTR, CMDMAX, "prefix \"%s\" ", route->routeEntry.prefix); len += snprintf(CMDSTR, CMDMAX, "src \"%s\" ", route->routeEntry.src); len += snprintf(CMDSTR, CMDMAX, "srclen %d ", route->routeEntry.srclen); len += snprintf(CMDSTR, CMDMAX, "srcprefix \"%s\" ", route->routeEntry.srcprefix); len += snprintf(CMDSTR, CMDMAX, "calltype \"%s\" ", RouteFlagsString(route->routeEntry.crflags & (CRF_CALLORIGIN|CRF_CALLDEST|CRF_TRANSIT))); len += snprintf(CMDSTR, CMDMAX, "type \"%s\" ", (route->routeEntry.crflags & CRF_REJECT)? "reject":"normal"); len += snprintf(CMDSTR, CMDMAX, "dnisdefault \"%s\" ", (route->routeEntry.crflags & CRF_DNISDEFAULT)? "enable":"disable"); len += snprintf(CMDSTR, CMDMAX, "template \"%s\" ", (route->routeEntry.crflags & CRF_TEMPLATE)? "enable":"disable"); len += snprintf(CMDSTR, CMDMAX, "template \"%s\" ", (route->routeEntry.crflags & CRF_STICKY)? "enable":"disable"); len += snprintf(CMDSTR, CMDMAX, "cpname \"%s\" ", route->routeEntry.cpname); } _return: return len; }
int GisPostCliFormatIedgeRegCmd(PostCmd *cmd, char *tags, char *cmdstr, int cmdlen, int len) { char fn[] = "GisPostCliFormatIedgeRegCmd():"; CacheTableInfo cacheInfoEntry; NetoidInfoEntry *netInfo; struct in_addr in; char buf[INET_ADDRSTRLEN]; // Look up the entry in the cache if (CacheFind(regCache, &cmd->key, &cacheInfoEntry, sizeof(cacheInfoEntry)) < 0) { NETDEBUG(MDB, NETLOG_DEBUG1, ("%s Could not find iedge %s/%d\n", fn, cmd->key.regid, cmd->key.uport)); goto _return; } netInfo = &cacheInfoEntry.data; len += snprintf(CMDSTR, CMDMAX, "iedge reg \"%s\" %d ", cmd->key.regid, cmd->key.uport); if (BITA_TEST(tags, TAG_IPADDRESS)) { in.s_addr = htonl(netInfo->ipaddress.l); len += snprintf(CMDSTR, CMDMAX, "ip %s ", inet_ntop( AF_INET, &in, buf, INET_ADDRSTRLEN)); } if (BITA_TEST(tags, TAG_H323SIGPT)) { len += snprintf(CMDSTR, CMDMAX, "q931port %d ", netInfo->callsigport); } if (BITA_TEST(tags, TAG_GATEWAY)) { len += snprintf(CMDSTR, CMDMAX, "gateway %s ", BIT_TEST(netInfo->cap, CAP_IGATEWAY)?"enable":"disable"); } if (BITA_TEST(tags, TAG_SIP)) { len += snprintf(CMDSTR, CMDMAX, "sip %s ", BIT_TEST(netInfo->cap, CAP_SIP)?"enable":"disable"); } if (BITA_TEST(tags, TAG_H323)) { len += snprintf(CMDSTR, CMDMAX, "h323 %s ", BIT_TEST(netInfo->cap, CAP_H323)?"enable":"disable"); } if (BITA_TEST(tags, TAG_DND)) { len += snprintf(CMDSTR, CMDMAX, "dnd %s ", (netInfo->stateFlags& CL_DND)?"enable":"disable"); } // Use the same TAG, as we will bundle up all three // pieces of info using the same tag if (BITA_TEST(tags, TAG_NCALLS)) { len += snprintf(CMDSTR, CMDMAX, "ncalls %d ", IedgeCalls(netInfo)); len += snprintf(CMDSTR, CMDMAX, "nincalls %d ", IedgeInCalls(netInfo)); len += snprintf(CMDSTR, CMDMAX, "noutcalls %d ", IedgeOutCalls(netInfo)); } if (BITA_TEST(tags, TAG_CONTACT)) { len += snprintf(CMDSTR, CMDMAX, "contact \"%s\" ", netInfo->contact); } if (BITA_TEST(tags, TAG_REGSTATUS)) { len += snprintf(CMDSTR, CMDMAX, "reg %s ", (netInfo->stateFlags& CL_ACTIVE)?"active":"inactive"); } _return: return len; }