/** * LANHostConfigManagement:1 Action: SetDHCPServerConfigurable. * * Set dhcp server configuration flag. * It fails if CheckLanHostConfigFiles fails. * * @param ca_event Upnp event struct. * @return Upnp error code. */ int SetDHCPServerConfigurable( struct Upnp_Action_Request *ca_event ) { char *configurable; int config; if ( ( configurable = GetFirstDocumentItem( ca_event->ActionRequest, "NewDHCPServerConfigurable" ) ) && ( GetNbSoapParameters( ca_event->ActionRequest ) == 1 ) ) { config = resolveBoolean( configurable ); // if user is setting configurable to true, check that all necessary files are installed if ( config && CheckLanHostConfigFiles() ) { // init failed, send action failed response ca_event->ErrCode = 501; strcpy( ca_event->ErrStr, "Action Failed" ); ca_event->ActionResult = NULL; } else { lanHostConfig.DHCPServerConfigurable = config; ParseResult( ca_event, "" ); } } else InvalidArgs( ca_event ); free( configurable ); return ca_event->ErrCode; }
void UpdaterPrivate::UpdaterReady(int exit_code, QProcess::ExitStatus exit_status) { if (main_process == nullptr) { return; } if (exit_status != QProcess::NormalExit) { UpdaterError(QProcess::Crashed); return; } normal_exit = true; last_error_code = exit_code; last_error_log = main_process->readAllStandardError(); const auto update_out = main_process->readAllStandardOutput(); main_process->deleteLater(); main_process = nullptr; running = false; emit parent->RunningChanged(false); QList<Updater::UpdateInfo> update_info; auto err = ParseResult(update_out, update_info); bool has_error = false; if (err == XMLParseResult::Success) { if (!update_info.isEmpty()) emit parent->UpdateInfoChanged(update_info); } else if (err == XMLParseResult::InvalidXML) { has_error = true; } emit parent->CheckUpdatesDone(!update_info.isEmpty(), has_error); }
/** * LANHostConfigManagement:1 Action: DeleteIPRouter. * * Deletes the default router. * This action only affects the default router, not all routers like defined in the spec. * * @param ca_event Upnp event struct. * @return Upnp error code. */ int DeleteIPRouter( struct Upnp_Action_Request *ca_event ) { char *parmList[] = { ROUTE_COMMAND, "del", "default", "gw", NULL, NULL }; int status; if ( ( parmList[4] = GetFirstDocumentItem( ca_event->ActionRequest, "NewIPRouters" ) ) && ( GetNbSoapParameters( ca_event->ActionRequest ) == 1 ) ) { if ( CheckDHCPServerConfigurable( ca_event ) ) return ca_event->ErrCode; // run route del command status = RunCommand( ROUTE_COMMAND, parmList ); if ( !status ) ParseResult( ca_event, "" ); else { trace( 2, "DeleteIPRouter: Route command returned error: %d", status ); addErrorData( ca_event, 702, "ValueSpecifiedIsInvalid" ); } } else InvalidArgs( ca_event ); free( parmList[4] ); return ca_event->ErrCode; }
void CGuildManager::Initialize() { char szQuery[1024]; snprintf(szQuery, sizeof(szQuery), "SELECT id, name, ladder_point, win, draw, loss, gold, level FROM guild%s", GetTablePostfix()); std::auto_ptr<SQLMsg> pmsg(CDBManager::instance().DirectQuery(szQuery)); if (pmsg->Get()->uiNumRows) ParseResult(pmsg->Get()); char str[128 + 1]; if (!CConfig::instance().GetValue("POLY_POWER", str, sizeof(str))) *str = '\0'; if (!polyPower.Analyze(str)) sys_err("cannot set power poly: %s", str); else sys_log(0, "POWER_POLY: %s", str); if (!CConfig::instance().GetValue("POLY_HANDICAP", str, sizeof(str))) *str = '\0'; if (!polyHandicap.Analyze(str)) sys_err("cannot set handicap poly: %s", str); else sys_log(0, "HANDICAP_POLY: %s", str); QueryRanking(); }
void Execute() override try { const auto status = ((*osrm).*(service))(*params, result); ParseResult(status, result); } catch (const std::exception &e) { SetErrorMessage(e.what()); }
BOOL DBXinFaList::Save(VOID* pSource) { __ENTER_FUNCTION enum { DB_CharGuid = 1, DB_XinFaID, DB_XinFaLvl, }; INT Result; if(!Delete()) return FALSE; ParseResult(&Result); FULLUSERDATA* pCharFullData = static_cast<FULLUSERDATA*>(pSource); Assert(pCharFullData); INT XinFaCount = pCharFullData->m_Skill.m_Count / 2; if( pCharFullData->m_Skill.m_Count % 2 ) //奇数 XinFaCount ++; for(INT i =0;i<XinFaCount;i++) { DB_QUERY* pQuery = GetInternalQuery(); if(!pQuery) { Assert(FALSE); } pQuery->Clear(); if(m_CharGuid==INVALID_ID) { return FALSE; } pQuery->Parse(NewCharXinFa, XINFA_TABLE, m_CharGuid, pCharFullData->m_XinFa.m_aXinFa[i].m_nXinFaID, pCharFullData->m_XinFa.m_aXinFa[i].m_nXinFaLevel, m_DBVersion ); if(!ODBCBase::Save(pCharFullData)) return FALSE; } return TRUE; __LEAVE_FUNCTION return FALSE; }
BOOL DBSkillList::Save(VOID* pSource) { __ENTER_FUNCTION enum { DB_CharGuid = 1, DB_SkillID, DB_DBVersion, }; INT Result; if(!Delete()) return FALSE; ParseResult(&Result); FULLUSERDATA* pCharFullData = static_cast<FULLUSERDATA*>(pSource); Assert(pCharFullData); INT SkillCount = pCharFullData->m_Skill.m_Count; for(INT i=0;i<SkillCount;i++) { DB_QUERY* pQuery = GetInternalQuery(); if(!pQuery) { Assert(FALSE); } pQuery->Clear(); if(m_CharGuid==INVALID_ID) { return FALSE; } pQuery->Parse(NewCharSkill, SKILL_TABLE, m_CharGuid, pCharFullData->m_Skill.m_aSkill[i].m_nSkillID, pCharFullData->m_Skill.m_aSkill[i].m_nSkillTime, m_DBVersion); if(!ODBCBase::Save(pCharFullData)) return FALSE; } return TRUE; __LEAVE_FUNCTION return FALSE; }
void CGuildManager::Load(DWORD dwGuildID) { char szQuery[1024]; snprintf(szQuery, sizeof(szQuery), "SELECT id, name, ladder_point, win, draw, loss, gold, level FROM guild%s WHERE id=%u", GetTablePostfix(), dwGuildID); std::auto_ptr<SQLMsg> pmsg(CDBManager::instance().DirectQuery(szQuery)); if (pmsg->Get()->uiNumRows) ParseResult(pmsg->Get()); }
// Public entry point to parsing. ParseResult Parser::parse(ParseNamedDefinition* start) { if (start->numArguments() != 0) { parseError(SourceLocation()) << "Start rule must have no arguments"; return ParseResult(); } parseError_ = false; resultStack_.clear(); parseRule(start); return resultStack_.getBack(); }
/** * LANHostConfigManagement:1 Action: SetIPRouter. * * Sets the default router. * This action only affects the default router, not all routers like defined in the spec. * * @param ca_event Upnp event struct. * @return Upnp error code. */ int SetIPRouter( struct Upnp_Action_Request *ca_event ) { char *parmList[] = { ROUTE_COMMAND, NULL, "default", "gw", NULL, NULL }; char addr[LINE_LEN]; char *new_router; int status; if ( ( new_router = GetFirstDocumentItem( ca_event->ActionRequest, "NewIPRouters" ) ) && ( GetNbSoapParameters( ca_event->ActionRequest ) == 1 ) ) { if ( CheckDHCPServerConfigurable( ca_event ) ) return ca_event->ErrCode; // if default gateway already exists, delete it if ( GetDefaultGateway( addr ) ) { // check that new gateway is different than current if ( strcmp( new_router, addr ) == 0 ) { addErrorData( ca_event, 701, "ValueAlreadySpecified" ); trace( 2, "SetIPRouter: new default gw '%s' is the same as current one '%s'", new_router, addr ); free( new_router ); return ca_event->ErrCode; } parmList[1] = "del"; parmList[4] = addr; RunCommand( ROUTE_COMMAND, parmList ); } // add new default gw parmList[1] = "add"; parmList[4] = new_router; status = RunCommand( ROUTE_COMMAND, parmList ); if ( !status ) ParseResult( ca_event, "" ); else { trace( 2, "SetIPRouter: Route command returned error: %d", status ); addErrorData( ca_event, 501, "Action Failed" ); } } else InvalidArgs( ca_event ); free( new_router ); return ca_event->ErrCode; }
/** * LANHostConfigManagement:1 Action: GetDHCPRelay. * * Returns the state of dhcrelay server. * * @param ca_event Upnp event struct. * @return Upnp error code. */ int GetDHCPRelay( struct Upnp_Action_Request *ca_event ) { if( GetNbSoapParameters( ca_event->ActionRequest ) != 0 ) { trace( 1, "GetDHCPRelay invalid number of parameters" ); addErrorData( ca_event, UPNP_SOAP_E_INVALID_ARGS, "Invalid Args" ); return ca_event->ErrCode; } ParseResult( ca_event, "<NewDHCPRelay>%d</NewDHCPRelay>\n", ( lanHostConfig.dhcrelay ? 1 : 0 ) ); return ca_event->ErrCode; }
bool CWOBackendReq::Issue() { SAFE_DELETE(resp_); float t1 = r3dGetTime(); resp_ = http.SynchronousRequest(g_api_ip->GetString(), gDomainPort, gDomainUseSSL, req); #ifndef FINAL_BUILD //r3dOutToLog("WOApi: %s NETWORK time: %.4f\n", savedUrl_, r3dGetTime()-t1); #endif resultCode_ = ParseResult(resp_); return resultCode_ == 0; }
/** * LANHostConfigManagement:1 Action: GetDNSServers. * * Returns all dns servers as a comma separated list. * * @param ca_event Upnp event struct. * @return Upnp error code. */ int GetDNSServers( struct Upnp_Action_Request *ca_event ) { FILE *file; char dns_servers[RESULT_LEN]; char line[MAX_CONFIG_LINE]; char dns[INET6_ADDRSTRLEN]; regex_t nameserver; regmatch_t submatch[SUB_MATCH]; int dns_place = 0; dns_servers[0] = 0; if( GetNbSoapParameters( ca_event->ActionRequest ) != 0 ) { trace( 1, "GetDNSServers invalid number of parameters" ); addErrorData( ca_event, UPNP_SOAP_E_INVALID_ARGS, "Invalid Args" ); return ca_event->ErrCode; } regcomp( &nameserver, REGEX_NAMESERVER, REG_EXTENDED ); file = fopen( g_vars.resolvConf, "r" ); if ( file == NULL ) { trace( 1, "Failed to open resolv.conf at: %s.", g_vars.resolvConf ); addErrorData( ca_event, 501, "Action Failed" ); return ca_event->ErrCode; } while ( fgets( line, MAX_CONFIG_LINE, file ) != NULL ) { if ( regexec( &nameserver, line, SUB_MATCH, submatch, 0 ) == 0 ) { // nameserver found, get it and add to list // if this is not the first dns server, add comma if ( dns_place > 0 ) dns_place += snprintf( &dns_servers[dns_place], RESULT_LEN - dns_place, "," ); strncpy( dns, &line[submatch[1].rm_so], min( submatch[1].rm_eo-submatch[1].rm_so, INET6_ADDRSTRLEN ) ); dns[min( submatch[1].rm_eo-submatch[1].rm_so, INET6_ADDRSTRLEN-1 )] = 0; dns_place += snprintf( &dns_servers[dns_place], RESULT_LEN - dns_place, "%s", dns ); } } ParseResult( ca_event, "<NewDNSServers>%s</NewDNSServers>\n", dns_servers ); regfree( &nameserver ); fclose( file ); return ca_event->ErrCode; }
ParseResult Parser::parse(std::string input) { ParseResult result = ParseResult(); std::vector<std::string> parts = split(input); if (parts.size == 0) { result.success = false; return result; } std::vector<std::string> args = range(parts, 1, parts.size - 1); for (int i = 0; i < args.size; i++) { for each (EnvironmentVariables var in ENV_VAR) { replace(args[i], "%" + var.name + "%", var.value); } }
/** * LANHostConfigManagement:1 Action: SetDomainName. * * Uses uci option dhcp.@dnsmasq[0].domain * * @param ca_event Upnp event struct. * @return Upnp error code. */ int SetDomainName( struct Upnp_Action_Request *ca_event ) { FILE *cmd = NULL; char *domainName; char setdomain_cmd[LINE_LEN]; regex_t reg_domain; if ( ( domainName = GetFirstDocumentItem( ca_event->ActionRequest, "NewDomainName" ) ) && ( GetNbSoapParameters( ca_event->ActionRequest ) == 1 ) ) { if ( CheckDHCPServerConfigurable( ca_event ) ) return ca_event->ErrCode; // sanitize input regcomp(®_domain, REGEX_DOMAIN_NAME, REG_EXTENDED); if( regexec( ®_domain, domainName, 0, 0, 0 ) != 0 ) { trace( 1, "SetDomainName: Domain Name contains invalid characters: '%s'.", domainName ); InvalidArgs( ca_event ); regfree(®_domain); return ca_event->ErrCode; } regfree(®_domain); snprintf( setdomain_cmd, LINE_LEN, "uci set dhcp.@dnsmasq[0].domain=%s", domainName ); cmd = popen( setdomain_cmd, "r" ); if ( cmd == NULL ) { trace( 1, "SetDomainName: setting Domain Name failed." ); addErrorData( ca_event, 501, "Action Failed" ); return ca_event->ErrCode; } UciCommit(); NetworkCommand( SERVICE_RESTART ); ParseResult( ca_event, "" ); } else InvalidArgs( ca_event ); if ( cmd ) pclose( cmd ); free( domainName ); return ca_event->ErrCode; }
bool CChangeArgumentsAction::ActionPerformed(CEntity* pEntity) { CString command; CString results; bool bRes = false; if(CImpactAction::ActionPerformed(pEntity)==true) { CString command = "args " + PrepareQuery(pEntity->GetEtag()); results = m_pCtrl->ExecCommand(command); CArguments Args; Args.Parse(results); CArgumentsInfoDlg dlg(m_pCtrl); dlg.SetArguments(&Args); int nRes = dlg.DoModal(); if(nRes == IDOK) { CString szArguments = "("; CArguments* pArgs = dlg.GetArguments(); POSITION nPos = pArgs->GetHeadPosition(); while(nPos!=NULL) { CArgument* pArg = pArgs->GetNext(nPos); szArguments += pArg->GetType(); szArguments += " "; szArguments += pArg->GetName(); if(nPos!=NULL) szArguments += ","; } szArguments += ")"; CString description = GetName(); description += " to " + szArguments; SetDescription(description); command = "Impact:ChangeFunctionArguments " + PrepareQuery(pEntity->GetEtag()) + " " + PrepareQuery(szArguments); results = m_pCtrl->ExecPrint(command); ParseResult(results); bRes = true; } else { SetExecuted(false); } } return bRes; }
bool CWOBackendReq::Issue() { SAFE_DELETE(resp_); //http.SynchronousRequest("127.0.0.1", 443, "/WarZ/api/", req) float t1 = r3dGetTime(); if (!g_api_ip) // IP of MSSQL if fail get 127.0.0.1 resp_ = http.SynchronousRequest("167.114.32.63", gDomainPort, gDomainUseSSL, req); else resp_ = http.SynchronousRequest(g_api_ip->GetString(), gDomainPort, gDomainUseSSL, req); #ifndef FINAL_BUILD //r3dOutToLog("WOApi: %s NETWORK time: %.4f\n", savedUrl_, r3dGetTime()-t1); #endif resultCode_ = ParseResult(resp_); return resultCode_ == 0; }
bool CChangeTypeAction::ActionPerformed(CEntity* pEntity) { CString command; CString results; bool bRes = false; if(CImpactAction::ActionPerformed(pEntity)==true) { CString type; command = "set CURRENT_TYPE [type " + PrepareQuery(pEntity->GetEtag()) + "]"; results = m_pCtrl->ExecCommand(command); CAttributesQueryResult typeResult; typeResult.parse(results); if(typeResult.getRecordsCount()>0) { POSITION iter = typeResult.getStartPos(); if(iter!=NULL) { TRecord* pRecord = typeResult.getNext(iter); type = *(*pRecord)[0]; } } CNewTypeDlg dlg(m_pCtrl); dlg.SetType(type); int nRes = dlg.DoModal(); if(nRes == IDOK) { CString szType = dlg.GetType(); CString szNewType = dlg.GetNewType(); CString description = GetName(); description += " from " + szType; description += " to " + szNewType; SetDescription(description); command = GetCommand(pEntity,szNewType); results = m_pCtrl->ExecPrint(command); ParseResult(results); bRes = true; } else { SetExecuted(false); } } return bRes; }
/** * this function implements the WANIPv6FirewallControl:getFirewallStatus action * * @param ca_event The UPnP action request from the control point * @return UPnP error code */ int upnp_wanipv6_getFirewallStatus(struct Upnp_Action_Request *ca_event) { if(GetNbSoapParameters(ca_event->ActionRequest) == 0) { ParseResult( ca_event, "<FirewallEnabled>%i</FirewallEnabled>\n" "<InboundPinholeAllowed>%i</InboundPinholeAllowed>\n", g_vars.ipv6firewallEnabled, g_vars.ipv6inboundPinholeAllowed ); } else { trace(1, "GetFirewallStatus invalid number of parameters"); errorManagement(UPNP_SOAP_E_INVALID_ARGS, ca_event); } return(ca_event->ErrCode); }
/** * LANHostConfigManagement:1 Action: GetAddressRange. * * Gets the address range dhcp server will give out. * * @param ca_event Upnp event struct. * @return Upnp error code. */ int GetAddressRange( struct Upnp_Action_Request *ca_event ) { FILE *cmd = NULL, *cmd_2 = NULL; char start[INET6_ADDRSTRLEN] = {0}, limit[INET6_ADDRSTRLEN] = {0}; if( GetNbSoapParameters( ca_event->ActionRequest ) != 0 ) { trace( 1, "GetAddressRange invalid number of parameters" ); addErrorData( ca_event, UPNP_SOAP_E_INVALID_ARGS, "Invalid Args" ); return ca_event->ErrCode; } if ( CheckDHCPServerConfigurable( ca_event ) ) return ca_event->ErrCode; // try to run uci commands cmd = popen( "uci get dhcp.lan.start", "r" ); cmd_2 = popen( "uci get dhcp.lan.limit", "r" ); if ( cmd == NULL || cmd_2 == NULL ) { trace( 1, "GetAddressRange: uci command failed." ); addErrorData( ca_event, 501, "Action Failed" ); } else { // get result /** @todo add error checking, if uci returns something invalid */ if ( fgets( start, INET6_ADDRSTRLEN, cmd ) == NULL || fgets( limit, INET6_ADDRSTRLEN, cmd_2 ) == NULL ) { trace( 1, "GetAddressRange: error reading values." ); addErrorData( ca_event, 501, "Action Failed" ); } } if ( ca_event->ErrCode == 0 ) ParseResult( ca_event, "<NewMinAddress>%s</NewMinAddress>\n<NewMaxAddress>%s</NewMaxAddress>\n", start, limit ); if ( cmd ) pclose( cmd ); if ( cmd_2 ) pclose( cmd_2 ); return ca_event->ErrCode; }
/** * LANHostConfigManagement:1 Action: SetAddressRange. * * Sets the address range dhcp server will give out. * * @todo Maybe we should use the 3 first parts of the ip address to set the ip address of this router? * Now they are just ignored. * * @param ca_event Upnp event struct. * @return Upnp error code. */ int SetAddressRange( struct Upnp_Action_Request *ca_event ) { char *parmList[] = { g_vars.uciCmd, "set", NULL, NULL }; char *start_addr, *limit_addr; char command[MAX_IP_LAST_PART+15]; char start[MAX_IP_LAST_PART], limit[MAX_IP_LAST_PART]; start_addr = GetFirstDocumentItem( ca_event->ActionRequest, "NewMinAddress" ); limit_addr = GetFirstDocumentItem( ca_event->ActionRequest, "NewMaxAddress" ); if ( start_addr && limit_addr && ( GetNbSoapParameters( ca_event->ActionRequest ) == 2 ) ) { if ( CheckDHCPServerConfigurable( ca_event ) ) return ca_event->ErrCode; // parse last part of both ip addresses if ( ParseAddressRange( ca_event, start, limit, start_addr, limit_addr ) ) return ca_event->ErrCode; snprintf( command, MAX_IP_LAST_PART+15, "dhcp.lan.start=%s", start ); parmList[2] = command; RunCommand( g_vars.uciCmd, parmList ); snprintf( command, MAX_IP_LAST_PART+15, "dhcp.lan.limit=%s", limit ); parmList[2] = command; RunCommand( g_vars.uciCmd, parmList ); UciCommit(); DnsmasqRestart(); } else InvalidArgs( ca_event ); if ( ca_event->ErrCode == 0 ) ParseResult( ca_event, "" ); free( start_addr ); free( limit_addr ); return ca_event->ErrCode; }
void Execute() override try { osrm::json::Object r; const auto status = ((*osrm).*(service))(*params, r); ParseResult(status, r); if (pluginParams.renderJSONToBuffer) { std::ostringstream buf; osrm::util::json::render(buf, r); result = buf.str(); } else { result = r; } } catch (const std::exception &e) { SetErrorMessage(e.what()); }
bool CDeleteEntityAction::ActionPerformed(CEntity* pEntity) { CString command; CString results; bool bRes = false; if(CImpactAction::ActionPerformed(pEntity)==true) { CString kind = pEntity->GetKind(); kind.MakeLower(); CString id = PrepareQuery(pEntity->GetEtag()); SetWait(true); if ( kind == "package" ) { if(MessageBox(NULL,"Running impact queries on packages may take a long time.\nWould you like to proceed?", "QA Warning", MB_ICONQUESTION|MB_OKCANCEL)!=IDOK) { SetExecuted(false); bRes = false; return false; } command = "Impact:DeleteEntity " + id; } else if ( kind == "var" ) { command = "oo_member " + id; results = m_pCtrl->ExecCommand(command); if (results == "1") { command = "Impact:DeleteVariableFromClass " + id; } else { command = "Impact:DeleteVariable " + id + " [ where defined " + id + " ] "; } } else { command = "Impact:DeleteEntity " + id; } results = m_pCtrl->ExecPrint(command); ParseResult(results); bRes = true; SetWait(false); } SetExecuted(bRes); return bRes; }
/** * LANHostConfigManagement:1 Action: GetIPRoutersList. * * Returns the default router. * This action returns only the default router, not all routers like defined in the spec. * * @param ca_event Upnp event struct. * @return Upnp error code. */ int GetIPRoutersList( struct Upnp_Action_Request *ca_event ) { char addr[LINE_LEN]; int gw_found = FALSE; if( GetNbSoapParameters( ca_event->ActionRequest ) != 0 ) { trace( 1, "GetIPRoutersLists invalid number of parameters" ); addErrorData( ca_event, UPNP_SOAP_E_INVALID_ARGS, "Invalid Args" ); return ca_event->ErrCode; } gw_found = GetDefaultGateway( addr ); if ( gw_found ) ParseResult( ca_event, "<NewIPRouters>%s</NewIPRouters>\n", addr ); else addErrorData( ca_event, 501, "Invalid Args" ); return ca_event->ErrCode; }
/** * LANHostConfigManagement:1 Action: SetDHCPRelay. * * Change dhcp mode between relay server and normal dhcp server. * Start / Stop dhcrelay and dnsmasq accordingly. * * @todo check that dhcrelay is installed in the system * * @param ca_event Upnp event struct. * @return Upnp error code. */ int SetDHCPRelay( struct Upnp_Action_Request *ca_event ) { char *dhcrelay; int b_dhcrelay; if ( ( dhcrelay = GetFirstDocumentItem( ca_event->ActionRequest, "NewDHCPRelay" ) ) && ( GetNbSoapParameters( ca_event->ActionRequest ) == 1 ) ) { if ( CheckDHCPServerConfigurable( ca_event ) ) return ca_event->ErrCode; b_dhcrelay = resolveBoolean( dhcrelay ); if ( b_dhcrelay != lanHostConfig.dhcrelay ) { if ( b_dhcrelay ) { DnsmasqCommand( SERVICE_STOP ); DhcrelayStart(); } else { DhcrelayStop(); DnsmasqCommand( SERVICE_START ); } lanHostConfig.dhcrelay = b_dhcrelay; } } else InvalidArgs( ca_event ); if ( ca_event->ErrCode == 0 ) ParseResult( ca_event, "" ); free( dhcrelay ); return ca_event->ErrCode; }
/** * LANHostConfigManagement:1 Action: SetSubnetMask. * * Set the subnet mask of the LAN. * Uses uci option network.lan.netmask. * After setting the parameter network is restarted. * * @param ca_event Upnp event struct. * @return Upnp error code. */ int SetSubnetMask( struct Upnp_Action_Request *ca_event ) { char *subnet_mask; char command[INET6_ADDRSTRLEN]; char *args[] = { g_vars.uciCmd, "set", NULL, NULL }; regex_t reg_ip; if ( ( subnet_mask = GetFirstDocumentItem( ca_event->ActionRequest, "NewSubnetMask" ) ) && ( GetNbSoapParameters( ca_event->ActionRequest ) == 1 ) ) { if ( CheckDHCPServerConfigurable( ca_event ) ) return ca_event->ErrCode; // sanitize input regcomp(®_ip, REGEX_IP_LASTBYTE, REG_EXTENDED); if( regexec( ®_ip, subnet_mask, 0, 0, 0 ) != 0 ) { trace( 1, "SetDomainName: subnet mask contains invalid characters: '%s'.", subnet_mask ); InvalidArgs( ca_event ); regfree( ®_ip ); return ca_event->ErrCode; } regfree( ®_ip ); snprintf( command, INET6_ADDRSTRLEN, "network.lan.netmask=%s", subnet_mask ); args[2] = command; RunCommand( g_vars.uciCmd, args ); UciCommit(); NetworkCommand( SERVICE_RESTART ); } else InvalidArgs( ca_event ); if ( ca_event->ErrCode == 0 ) ParseResult( ca_event, "" ); return ca_event->ErrCode; }
/** * LANHostConfigManagement:1 Action: GetSubnetMask. * * Returns subnet mask using uci option * network.lan.netmask. * * @param ca_event Upnp event struct. * @return Upnp error code. */ int GetSubnetMask( struct Upnp_Action_Request *ca_event ) { FILE *cmd; char subnet_mask[INET6_ADDRSTRLEN]; if( GetNbSoapParameters( ca_event->ActionRequest ) != 0 ) { trace( 1, "GetSubnetMask invalid number of parameters" ); addErrorData( ca_event, UPNP_SOAP_E_INVALID_ARGS, "Invalid Args" ); return ca_event->ErrCode; } if ( CheckDHCPServerConfigurable( ca_event ) ) return ca_event->ErrCode; // try to run uci command cmd = popen( "uci get network.lan.netmask", "r" ); if ( cmd == NULL ) { trace( 1, "GetSubnetMask: getting subnet mask failed." ); addErrorData( ca_event, 501, "Action Failed" ); return ca_event->ErrCode; } // get result if ( fgets( subnet_mask, INET6_ADDRSTRLEN, cmd ) != NULL ) ParseResult( ca_event, "<NewSubnetMask>%s</NewSubnetMask>\n", subnet_mask ); else { trace( 1, "GetSubnetMask: uci command returned null." ); addErrorData( ca_event, 501, "Action Failed" ); } pclose( cmd ); return ca_event->ErrCode; }
/** * LANHostConfigManagement:1 Action: GetDomainName. * * @param ca_event Upnp event struct. * @return Upnp error code. */ int GetDomainName( struct Upnp_Action_Request *ca_event ) { FILE *cmd; char domain_name[LINE_LEN]; if( GetNbSoapParameters( ca_event->ActionRequest ) != 0 ) { trace( 1, "GetDomainName invalid number of parameters" ); addErrorData( ca_event, UPNP_SOAP_E_INVALID_ARGS, "Invalid Args" ); return ca_event->ErrCode; } if ( CheckDHCPServerConfigurable( ca_event ) ) return ca_event->ErrCode; // try to run uci command cmd = popen( "uci get -q dhcp.@dnsmasq[0].domain", "r" ); if ( cmd == NULL ) { trace( 1, "GetDomainName: getting Domain Name failed." ); addErrorData( ca_event, 501, "Action Failed" ); return ca_event->ErrCode; } // get result if ( fgets( domain_name, LINE_LEN, cmd ) != NULL ) ParseResult( ca_event, "<NewDomainName>%s</NewDomainName>\n", domain_name ); else { trace( 1, "GetDomainName: uci command returned null." ); addErrorData( ca_event, 501, "Action Failed" ); } pclose( cmd ); return ca_event->ErrCode; }
/** * LANHostConfigManagement:1 Action: DeleteReservedAddress. * * Deletes specified ip-address from reserved addresses if it can be found. * This action only takes one ip-address at a time, not a comma separated list. * * @param ca_event Upnp event struct. * @return Upnp error code. */ int DeleteReservedAddress( struct Upnp_Action_Request *ca_event ) { char command[COMMAND_LEN]; char *del_addr; FILE *cmd; char line[MAX_CONFIG_LINE]; int i = 0; int deleted = FALSE; if ( ( ( del_addr = GetFirstDocumentItem( ca_event->ActionRequest, "NewReservedAddresses" ) ) == NULL ) || ( GetNbSoapParameters( ca_event->ActionRequest ) != 1 ) ) { InvalidArgs( ca_event ); return ca_event->ErrCode; } if ( CheckDHCPServerConfigurable( ca_event ) ) return ca_event->ErrCode; // added MAX_RESERVED_ADDRESS as precaution, if under some conditions uci returns always something // if that is reached, give internal error while ( i < MAX_RESERVED_ADDRESS ) { sprintf( command, "uci -q get dhcp.@host[%d].ip", i ); cmd = popen( command, "r" ); if ( cmd == NULL ) { trace( 1, "DeleteReservedAddress: Error running command: '%s'", command ); addErrorData( ca_event, 501, "Action Failed" ); break; } if ( fgets( line, MAX_CONFIG_LINE, cmd ) == NULL ) { // returned nothing, no more hosts defined pclose( cmd ); break; } pclose( cmd ); if ( strncmp( line, del_addr, strlen( del_addr ) ) == 0 ) { sprintf( command, "uci -q delete dhcp.@host[%d]", i ); cmd = popen( command, "r" ); if ( cmd == NULL ) { trace( 1, "DeleteReservedAddress: Error running command: '%s'", command ); addErrorData( ca_event, 501, "Action Failed" ); } else { // entry successfully deleted deleted = TRUE; UciCommit(); DnsmasqRestart(); pclose( cmd ); } break; } i++; } if ( i == MAX_RESERVED_ADDRESS ) { trace( 1, "DeleteReservedAddress: Internal error in function." ); addErrorData( ca_event, 501, "Action Failed" ); } if ( deleted == FALSE ) { trace( 2, "DeleteReservedAddress: Can't find address to delete: '%s'.", del_addr ); addErrorData( ca_event, 702, "ValueSpecifiedIsInvalid" ); } if ( ca_event->ErrCode == 0 ) ParseResult( ca_event, "" ); if ( cmd ) pclose( cmd ); free( del_addr ); return ca_event->ErrCode; }
/** * LANHostConfigManagement:1 Action: SetReservedAddress. * * Sets the reserved addesses, that dhcp server won't give to clients. * Old values will be deleted before the new list is applied. * * @param ca_event Upnp event struct. * @return Upnp error code. */ int SetReservedAddress( struct Upnp_Action_Request *ca_event ) { char command[COMMAND_LEN]; FILE *cmd; char line[MAX_CONFIG_LINE]; char *all_addr, *addr; char *add_args[] = { g_vars.uciCmd, "-q", "add", "dhcp", "host", NULL }; char *set_args[] = { g_vars.uciCmd, "-q", "set", NULL, NULL }; char *del_args[] = { g_vars.uciCmd, "-q", "delete", "dhcp.@host[0]", NULL }; int i=0; if ( ( ( all_addr = GetFirstDocumentItem( ca_event->ActionRequest, "NewReservedAddresses" ) ) == NULL ) || ( GetNbSoapParameters( ca_event->ActionRequest ) != 1 ) ) { InvalidArgs( ca_event ); return ca_event->ErrCode; } if ( CheckDHCPServerConfigurable( ca_event ) ) return ca_event->ErrCode; // delete all hosts while ( i < MAX_RESERVED_ADDRESS ) { sprintf( command, "uci -q get dhcp.@host[0]" ); cmd = popen( command, "r" ); if ( cmd == NULL ) { trace( 1, "SetReservedAddress: Error running command: '%s'", command ); addErrorData( ca_event, 501, "Action Failed" ); break; } // if nothing is returned, we have removed all hosts if ( fgets( line, MAX_CONFIG_LINE, cmd ) == NULL ) { pclose( cmd ); break; } pclose( cmd ); RunCommand( g_vars.uciCmd, del_args ); i++; } // if deleting was successful then add new hosts if ( ca_event->ErrCode == 0 ) { addr = strtok( all_addr, "," ); while ( addr != NULL ) { // add new host RunCommand( g_vars.uciCmd, add_args ); // set host values set_args[3] = "dhcp.@host[-1].name=IGDv2"; RunCommand( g_vars.uciCmd, set_args ); set_args[3] = "dhcp.@host[-1].mac=00:00:00:00:00:00"; RunCommand( g_vars.uciCmd, set_args ); sprintf( command, "dhcp.@host[-1].ip=%s", addr ); set_args[3] = command; RunCommand( g_vars.uciCmd, set_args ); addr = strtok( NULL, "," ); } } if ( ca_event->ErrCode == 0 ) ParseResult( ca_event, "" ); free( all_addr ); return ca_event->ErrCode; }