int main(int argc, const char* argv[]) { int rval = -1; struct Arguments args; if (!args.parseArguments(argc, argv)) { return rval; } if (args.api_mode == ApiMode::PROCESS) { rval = android_setprocnetwork(args.nethandle); if (rval != 0) { int errnum = errno; std::cerr << "android_setprocnetwork(" << args.nethandle << ") failed;" << " errno: " << errnum << " [" << strerror(errnum) << "]" << std::endl; return rval; } } struct Parameters parameters; if (!parseUrl(args, ¶meters)) { return -1; } // TODO: Fall back from IPv6 to IPv4 if ss.ss_family is AF_UNSPEC. // This will involve changes to parseUrl() as well. struct FdAutoCloser closer = makeTcpSocket( parameters.ss.ss_family, (args.api_mode == ApiMode::EXPLICIT) ? args.nethandle : NETWORK_UNSPECIFIED); if (closer.fd < 0) { return closer.fd; } return doHttpQuery(closer.fd, parameters); }
/* **************************************************************************** * * Reference::check - */ std::string Reference::check ( RequestType requestType, const std::string& indent, const std::string& predetectedError, int counter ) { if (string == "") { if ((requestType == SubscribeContextAvailability) || (requestType == SubscribeContext)) { return "Empty Reference"; } } std::string url = string; std::string host; int port; std::string path; std::string protocol; if (parseUrl(url, host, port, path, protocol) == false) { return "Invalid URL"; } return "OK"; }
void Parser::parseTag(const char* tag, size_t len) { bool hasAttributes; //printf("tag: %i %.*s\n", tagState, (int)len, tag); FORMATTING_TAG("b", BOLD); FORMATTING_TAG("i", ITALIC); FORMATTING_TAG("small", SMALL); FORMATTING_TAG("s", SMALL); FORMATTING_TAG("u", UNDERLINED); SIMPLE_TAG("table", TABLE); SIMPLE_TAG("tr", TR); SIMPLE_TAG("td", TD); //SIMPLE_TAG("li", LIST_ITEM); SPECIAL_TAG("li", addListItem()); SPECIAL_TAG("code", addCodeTag()); SPECIAL_TAG("quote", addQuoteTag()); SIMPLE_TAG("ul", LIST); SIMPLE_TAG("ol", LIST); if(!strncasecmp("url=", tag, 4) || !strncasecmp("url:", tag, 4) || !strncasecmp("url ", tag, 4)) { //printf("url tag: %i %.*s\n", tagState, (int)len, tag); const char* url = tag + 4; size_t urlLen = len - 4; parseUrl(url, urlLen); return; } //C_TAG("url", ANCHOR, "a", "/a"); COMPARE_TAG("url", return;); // get rid of empty [url] tags.
RPCSub::RPCSub (const std::string& strUrl, const std::string& strUsername, const std::string& strPassword) : mUrl (strUrl), mSSL (false), mUsername (strUsername), mPassword (strPassword), mSending (false) { std::string strScheme; if (!parseUrl (strUrl, strScheme, mIp, mPort, mPath)) { throw std::runtime_error ("Failed to parse url."); } else if (strScheme == "https") { mSSL = true; } else if (strScheme != "http") { throw std::runtime_error ("Only http and https is supported."); } mSeq = 1; if (mPort < 0) mPort = mSSL ? 443 : 80; WriteLog (lsINFO, RPCSub) << boost::str (boost::format ("callRPC sub: ip='%s' port=%d ssl=%d path='%s'") % mIp % mPort % mSSL % mPath); }
void dl_vlive_live(std::string url) { streamInfo currentInfo; vidUrlInfo currentLiveInfo; m3u8Info currentMediaInfo; std::string v_title; std::string strUrl; int cnt = 0; float time = 0; getStreamInfo(retrievePage((char *)url.c_str()), ¤tInfo, NULL, TYPE_VLIVE); getStreamInfo(retrievePage((char *)url.c_str()), NULL, ¤tLiveInfo, TYPE_VLIVE_LIVE); for (int i = 0; i <= currentLiveInfo.num_list; i++) modifyUrl(¤tLiveInfo.url[i], TYPE_VLIVE_LIVE); printLine(3); getline(cin, v_title); printLine(5); while (strcmp(currentInfo.v_stat.c_str(), "LIVE_END") != 0) { parseStream(retrievePage((char*)currentLiveInfo.url[currentLiveInfo.num_list].c_str()), ¤tMediaInfo); for (int i = 0; i <= currentMediaInfo.list_num; i++) { strUrl = "http://vlive.hls.edgesuite.net/" + parseUrl(currentLiveInfo.url[currentLiveInfo.num_list]) + currentMediaInfo.fname[i]; retrieveFileFromUrl(strUrl, v_title, TYPE_VLIVE_LIVE, cnt, &time); std::this_thread::sleep_for(std::chrono::milliseconds((int)(currentMediaInfo.sec_sleep[i] - time) - 250)); cnt++; } getStreamInfo(retrievePage((char *)url.c_str()), ¤tInfo, NULL, TYPE_VLIVE); } cout << v_title; printLine(6); }
/* * Parse an external acl helper line. * * Squid can be configured to pass various formats, we assume something * similar to the normal redirector format: * * %URI %SRC %LOGIN * * For example: * external_acl_type foo ttl=60 children=1 %URI %SRC %LOGIN /path/to/sg */ int parseAuthzLine(char *line, struct SquidInfo *s) { char *field = NULL; sgLogDebug("got authz line %s", line); resetSquidInfo(s); /* get the URL and parse */ if ((field = strtok(line, "\t ")) == NULL) return 0; HTUnEscape(field); if (!parseUrl(field, s)) return 0; /* get the source address and parse */ if ((field = strtok(NULL, " \t\n")) == NULL) return 0; HTUnEscape(field); /* just in case, IPs should not need escaping */ strcpy(s->src, field); /* get the login and parse */ if ((field = strtok(NULL, " \t\n")) == NULL) return 0; if (!parseIdent(field,s)) return 0; sgLogDebug("parsed authz line: furl='%s' domain='%s' surl='%s' src=%s ident='%s'", s->furl, s->domain, s->surl, s->src, s->ident); return 1; }
/* * When we come here, we've already matched either a location block or an extension */ static bool matchEjs(MaConn *conn, MaStage *handler, cchar *url) { MaRequest *req; MaLocation *loc; EjsWeb *web; cchar *ext; char urlbuf[MPR_MAX_FNAME]; loc = conn->request->location; #if UNUSED if (!(loc->flags & (MA_LOC_APP | MA_LOC_APP_DIR))) { return 1; } #endif /* * Send non-ejs content under web to another handler, typically the file handler. */ req = conn->request; ext = conn->response->extension; if (ext && strcmp(ext, "mod") == 0) { maFormatBody(conn, "Bad Request", "Can't serve *.mod files"); maFailRequest(conn, MPR_HTTP_CODE_BAD_REQUEST, "Can't server *.mod files"); return 1; } if (parseUrl(conn) < 0) { return 1; } web = (EjsWeb*) conn->response->handlerData; /* * TODO - need a more general way of handling these routes. Push back into the Ejscript framework */ url = web->url; if (*url == '\0' || strcmp(url, "/") == 0) { mprSprintf(urlbuf, sizeof(urlbuf), "%s/web/index.ejs", web->appUrl); maSetRequestUri(conn, urlbuf); return 0; } else if (strcmp(url, "/favicon.ico") == 0) { mprSprintf(urlbuf, sizeof(urlbuf), "%s/web/favicon.ico", web->appUrl); maSetRequestUri(conn, urlbuf); return 0; } else if (strncmp(url, "/web/", 5) == 0 || *url == '\0') { if (!(ext && strcmp(ext, "ejs") == 0)) { return 0; } } else { if (loc->flags & (MA_LOC_APP | MA_LOC_APP_DIR) && ext && strcmp(ext, "ejs") == 0) { maFormatBody(conn, "Bad Request", "Can't serve *.ejs files outside web directory"); maFailRequest(conn, MPR_HTTP_CODE_BAD_REQUEST, "Can't server *.ejs files outside web directory"); } } return 1; }
bool parseUrl(const std::string& spec, std::string& protocol, std::string& hostname, int& port) { std::string path; std::string query; bool rv = parseUrl(spec, protocol, hostname, port, path, query); return rv && query.empty() && (path.empty() || path == "/"); }
WinINetRequest::WinINetRequest(const String& url) : m_session(NULL), m_connect(NULL), m_request(NULL), m_used(false), m_url(parseUrl(url)) { }
void testParseUrl () { testcase ("parseUrl"); std::string strScheme; std::string strDomain; int iPort; std::string strPath; unexpected (!parseUrl ("lower://domain", strScheme, strDomain, iPort, strPath), "parseUrl: lower://domain failed"); unexpected (strScheme != "lower", "parseUrl: lower://domain : scheme failed"); unexpected (strDomain != "domain", "parseUrl: lower://domain : domain failed"); unexpected (iPort != -1, "parseUrl: lower://domain : port failed"); unexpected (strPath != "", "parseUrl: lower://domain : path failed"); unexpected (!parseUrl ("UPPER://domain:234/", strScheme, strDomain, iPort, strPath), "parseUrl: UPPER://domain:234/ failed"); unexpected (strScheme != "upper", "parseUrl: UPPER://domain:234/ : scheme failed"); unexpected (iPort != 234, boost::str (boost::format ("parseUrl: UPPER://domain:234/ : port failed: %d") % iPort)); unexpected (strPath != "/", "parseUrl: UPPER://domain:234/ : path failed"); unexpected (!parseUrl ("Mixed://domain/path", strScheme, strDomain, iPort, strPath), "parseUrl: Mixed://domain/path failed"); unexpected (strScheme != "mixed", "parseUrl: Mixed://domain/path tolower failed"); unexpected (strPath != "/path", "parseUrl: Mixed://domain/path path failed"); }
bool UPNPNAT::add_port_mapping(const char * _description, const char * _destination_ip, unsigned short int _port_ex, unsigned short int _port_in, char * _protocal) { int ret; std::string host,path; unsigned short int port; ret=parseUrl(control_url.c_str(),host,&port,path); if(!ret) { status=NAT_ERROR; last_error="Fail to parseURl: "+describe_url+"\n"; return false; } //connect ret=tcp_connect(host.c_str(),port); if(!ret) return false; char buff[MAX_BUFF_SIZE+1]; sprintf(buff,ADD_PORT_MAPPING_PARAMS,_port_ex,_protocal,_port_in,_destination_ip,_description); std::string action_params=buff; sprintf(buff,SOAP_ACTION,ACTION_ADD,service_type.c_str(),action_params.c_str(),ACTION_ADD); std::string soap_message=buff; sprintf(buff,HTTP_HEADER_ACTION,path.c_str(),host.c_str(),port,service_type.c_str(),ACTION_ADD,soap_message.size()); std::string action_message=buff; std::string http_request=action_message+soap_message; //send request ret=send(tcp_socket_fd,http_request.c_str(),(int) http_request.size(),0); //wait for response std::string response; memset(buff, 0, sizeof(buff)); while (ret=recv(tcp_socket_fd,buff,MAX_BUFF_SIZE,0) >0) { response+=buff; memset(buff, 0, sizeof(buff)); } if(response.find(HTTP_OK)==std::string::npos) { status=NAT_ERROR; char temp[100]; sprintf(temp,"Fail to add port mapping (%s/%s)\n",_description,_protocal); last_error=temp; printf(response.c_str()); return false; } closesocket(tcp_socket_fd); status=NAT_ADD; return true; }
void IconServerSession::parseData(const std::vector<char>& data) { static const char* const beginUrl = "GET "; static const char* const endHeader = "\r\n\r\n"; const char* begin = &data[0]; const char* end = &data[0] + data.size(); for(const char* p = begin; p < end; p++) { if(status == WaitStatusLine) { if(*p == beginUrl[nextByteToMatch]) { nextByteToMatch++; if(nextByteToMatch >= 4) { status = RetrievingStatusLine; nextByteToMatch = 0; } } else { nextByteToMatch = 0; } } else if(status == RetrievingStatusLine) { if(*p == '\r' || *p == '\n') { status = WaitEndOfHeaders; } else if(*p >= 32 && *p <= 126 && urlLength < 255) { url.put(*p); urlLength++; } else { status = WaitStatusLine; nextByteToMatch = 0; url.str(std::string()); url.clear(); urlLength = 0; } } if(status == RetrievingStatusLine || status == WaitEndOfHeaders) { if(*p == endHeader[nextByteToMatch]) { nextByteToMatch++; if(nextByteToMatch >= 4) { status = WaitStatusLine; nextByteToMatch = 0; std::string urlString = url.str(); if(!urlString.compare(urlString.size() - 9, std::string::npos, " HTTP/1.1")) { urlString.resize(urlString.size() - 9); parseUrl(urlString); } url.str(std::string()); url.clear(); urlLength = 0; } } else { nextByteToMatch = 0; } } } }
/* **************************************************************************** * * Notifier::sendNotifyContextAvailabilityRequest - * * FIXME: this method is very similar to sendNotifyContextRequest and probably * they could be refactored in the future to have a common part using a parent * class for both types of notifications and using it as first argument */ void Notifier::sendNotifyContextAvailabilityRequest ( NotifyContextAvailabilityRequest* ncar, const std::string& url, const std::string& tenant, const std::string& fiwareCorrelator, RenderFormat renderFormat ) { /* Render NotifyContextAvailabilityRequest */ std::string payload = ncar->render(NotifyContextAvailability, ""); /* Parse URL */ std::string host; int port; std::string uriPath; std::string protocol; if (!parseUrl(url, host, port, uriPath, protocol)) { std::string details = std::string("sending NotifyContextAvailabilityRequest: malformed URL: '") + url + "'"; alarmMgr.badInput(clientIp, details); return; } /* Set Content-Type */ std::string content_type = "application/json"; /* Send the message (without awaiting response, in a separate thread to avoid blocking) */ pthread_t tid; SenderThreadParams* params = new SenderThreadParams(); params->ip = host; params->port = port; params->verb = "POST"; params->tenant = tenant; params->resource = uriPath; params->content_type = content_type; params->content = payload; params->mimeType = JSON; params->fiwareCorrelator = fiwareCorrelator; params->renderFormat = renderFormatToString(renderFormat); strncpy(params->transactionId, transactionId, sizeof(params->transactionId)); int ret = pthread_create(&tid, NULL, startSenderThread, params); if (ret != 0) { LM_E(("Runtime Error (error creating thread: %d)", ret)); return; } pthread_detach(tid); }
HttpBackend* HttpDirector::createBackend(const std::string& name, const std::string& url) { std::string protocol, hostname, path, query; int port = 0; if (!parseUrl(url, protocol, hostname, port, path, query)) { TRACE("invalid URL: %s", url.c_str()); return false; } return createBackend(name, protocol, hostname, port, path, query); }
/* **************************************************************************** * * parseMalformedUrl2 - */ TEST(string, parseMalformedUrl2) { std::string url = "http://20:host:8080/my/path"; std::string host; int port; std::string path; bool result = parseUrl(url, host, port, path); EXPECT_FALSE(result) << "wrong result (shall be false)"; }
/* **************************************************************************** * * parseEmptyUrl - */ TEST(string, parseEmptyUrl) { std::string url = ""; std::string host; int port; std::string path; bool result = parseUrl(url, host, port, path); EXPECT_FALSE(result) << "wrong result (shall be false)"; }
/////////////////////////////////////////////////////////////////////////// // // Parsing Interface // Token *tokenizer_next( Tokenizer *tokenizer ) { wchar_t c, next; Token *token = NULL; next = ss_peek( tokenizer->ss_ ); while ( next != WEOF && !token ) { // Whitespace if ( isWhitespaceStart( tokenizer->ss_, 0 ) ) { token = parseWhitespace( tokenizer ); } // Strings else if ( isStringStart( tokenizer->ss_, 0 ) ) { token = parseString( tokenizer ); } // Comments else if ( isCommentStart( tokenizer->ss_, 0 ) ) { token = parseComment( tokenizer ); } // URL else if ( isUrlStart( tokenizer->ss_, 0 ) ) { token = parseUrl( tokenizer ); } // SGML Comments else if ( isSGMLCommentStart( tokenizer->ss_, 0 ) ) { token = parseSGMLComment( tokenizer ); } // Identifier else if ( isIdentifierStart( tokenizer->ss_, 0 ) ) { token = parseIdentifier( tokenizer ); } // @keyword else if ( isAtkeywordStart( tokenizer->ss_, 0 ) ) { token = parseAtkeyword( tokenizer ); } // #keyword else if ( isHashkeywordStart( tokenizer->ss_, 0 ) ) { token = parseHashkeyword( tokenizer ); } // Number else if ( isNumberStart( tokenizer->ss_, 0 ) ) { token = parseNumber( tokenizer ); } // Operators & Delims (everything else) else { token = parseEverythingElse( tokenizer ); } } if ( token ) { return token; } else { return NULL; } }
// Load the dynamic library. // Create the test player. // Call setDataSource on the test player with the url in param. status_t TestPlayerStub::setDataSource( const char *url, const KeyedVector<String8, String8> *headers) { if (!isTestUrl(url) || NULL != mHandle) { return INVALID_OPERATION; } mUrl = strdup(url); status_t status = parseUrl(); if (OK != status) { resetInternal(); return status; } ::dlerror(); // Clears any pending error. // Load the test player from the url. dlopen will fail if the lib // is not there. dls are under /system/lib // None of the entry points should be NULL. mHandle = ::dlopen(mFilename, RTLD_NOW | RTLD_GLOBAL); if (!mHandle) { ALOGE("dlopen failed: %s", ::dlerror()); resetInternal(); return UNKNOWN_ERROR; } // Load the 2 entry points to create and delete instances. const char *err; mNewPlayer = reinterpret_cast<NEW_PLAYER>(dlsym(mHandle, "newPlayer")); err = ::dlerror(); if (err || mNewPlayer == NULL) { // if err is NULL the string <null> is inserted in the logs => // mNewPlayer was NULL. ALOGE("dlsym for newPlayer failed %s", err); resetInternal(); return UNKNOWN_ERROR; } mDeletePlayer = reinterpret_cast<DELETE_PLAYER>(dlsym(mHandle, "deletePlayer")); err = ::dlerror(); if (err || mDeletePlayer == NULL) { ALOGE("dlsym for deletePlayer failed %s", err); resetInternal(); return UNKNOWN_ERROR; } mPlayer = (*mNewPlayer)(); return mPlayer->setDataSource(mContentUrl, headers); }
void HippoGridManager::loadFromFile() { // load user grid info parseFile(gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, "grid_info.xml"), false); // merge default grid info, if newer. Force load, if list of grids is empty. parseFile(gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "default_grids.xml"), !mGridInfo.empty()); // merge grid info from web site, if newer. Force load, if list of grids is empty. if (gSavedSettings.getBOOL("CheckForGridUpdates")) parseUrl("http://opensim-viewer.sourceforge.net/db/grids.php", !mGridInfo.empty()); setDefaultGrid(gSavedSettings.getString("DefaultGrid")); setCurrentGrid(gSavedSettings.getString("CmdLineGridChoice")); }
void testParseUrl () { testcase ("parseUrl"); std::string strScheme; std::string strDomain; int iPort; std::string strPath; BEAST_EXPECT (parseUrl ("lower://domain", strScheme, strDomain, iPort, strPath)); BEAST_EXPECT(strScheme == "lower"); BEAST_EXPECT(strDomain == "domain"); BEAST_EXPECT(iPort == -1); BEAST_EXPECT(strPath == ""); BEAST_EXPECT(parseUrl ("UPPER://domain:234/", strScheme, strDomain, iPort, strPath)); BEAST_EXPECT(strScheme == "upper"); BEAST_EXPECT(iPort == 234); BEAST_EXPECT(strPath == "/"); BEAST_EXPECT(parseUrl ("Mixed://domain/path", strScheme, strDomain, iPort, strPath)); BEAST_EXPECT(strScheme == "mixed"); BEAST_EXPECT(strPath == "/path"); }
KUrl ConfigEntry::urlValue() const { assert( m_argType == Path || m_argType == Url || m_argType == LdapUrl ); assert( !isList() ); QString str = m_value.toString(); if ( m_argType == Path ) { KUrl url; url.setPath( str ); return url; } return parseUrl( m_argType, str ); }
/* * Parse a redirector input line, format is: * * URL ip-address/fqdn ident method * * for example * http://www.example.com/page1.html 192.168.2.3/- andi GET */ int parseLine(char *line, struct SquidInfo *s) { char *field = NULL; char *p = NULL; sgLogDebug("got redirector line %s", line); resetSquidInfo(s); /* get the URL and parse */ if ((field = strtok(line, "\t ")) == NULL) return 0; HTUnEscape(field); if (!parseUrl(field, s)) return 0; /* get the source address and parse */ if ((field = strtok(NULL, " \t\n")) == NULL) return 0; if ((p = strchr(field, '/')) != NULL) { *p = 0; strcpy(s->src, field); strcpy(s->srcDomain, p + 1); if (s->srcDomain[0] == '-' && s->srcDomain[1] == 0) s->srcDomain[0] = 0; } else { strcpy(s->src, field); } /* get the identity */ if ((field = strtok(NULL, " \t\n")) == NULL) return 0; if (!parseIdent(field,s)) return 0; /* get the method */ if ((field = strtok(NULL, " \t\n")) == NULL) return 0; strcpy(s->method, field); if (s->method[0] == '\0') return 0; sgLogDebug("parsed redirector line: furl='%s' domain='%s' surl='%s' src=%s ident='%s'", s->furl, s->domain, s->surl, s->src, s->ident); return 1; }
/* **************************************************************************** * * parseMalformedUrl1 - */ TEST(string, parseMalformedUrl1) { std::string url = "http://"; std::string host; int port; std::string path; std::string protocol; bool result = parseUrl(url, host, port, path, protocol); EXPECT_FALSE(result) << "wrong result (shall be false)"; }
/* **************************************************************************** * * parseUrlWithoutPortAndPath - */ TEST(string, parseUrlWithoutPortAndPath) { std::string url = "http://host"; std::string host; int port; std::string path; bool result = parseUrl(url, host, port, path); EXPECT_TRUE(result) << "wrong result (shall be true)"; EXPECT_EQ("host", host) << "wrong host"; EXPECT_EQ(80, port) << "wrong port"; EXPECT_EQ("/", path) << "wrong path"; }
void child_process(int sock, int number) { char fd_buff[16]; char buff[1024]; while (true) { // get fd int fd; socket_fd_read(sock, fd_buff, sizeof(fd_buff), &fd); if (fd == -1) continue; // Work with income socket ssize_t size = recv(fd, buff, sizeof(buff), MSG_NOSIGNAL); if (size == 0) break; buff[size] = '\0'; FILE *log = fopen("/home/box/error.log", "w"); std::string url = parseHttpGet(buff, size); fprintf(log, "URL1: %s\n", url.c_str()); url = parseUrl(url); fprintf(log, "URL2: %s\n", url.c_str()); fprintf(log, "URL3: %s\n", getPostfix(url).c_str()); std::string response; if (getPostfix(url) != "html") { response = HttpResponse404(); } else { std::string filename = directory + url; fprintf(log, "FILE: %s\n", filename.c_str()); if (checkFile(filename)) { std::string content = readFile(filename); response = HttpResponse200(content.c_str(), content.size()); } else { response = HttpResponse404(); } } fprintf(log, "RESPONSE: %s\n", response.c_str()); send(fd, response.c_str(), response.length(), MSG_NOSIGNAL); close(fd); } close(sock); }
/* **************************************************************************** * * parseUrlWithSlashPath - */ TEST(string, parseUrlWithSlashPath) { std::string url = "http://host:8080/"; std::string host; int port; std::string path; std::string protocol; bool result = parseUrl(url, host, port, path, protocol); EXPECT_TRUE(result) << "wrong result (shall be true)"; EXPECT_EQ("host", host) << "wrong host"; EXPECT_EQ(8080, port) << "wrong port"; EXPECT_EQ("/", path) << "wrong path"; }
/* **************************************************************************** * * parseFullUrl - */ TEST(string, parseFullUrl) { std::string url = "http://host:8080/my/path"; std::string host; int port; std::string path; bool result = parseUrl(url, host, port, path); EXPECT_TRUE(result) << "wrong result (shall be true)"; EXPECT_EQ("host", host) << "wrong host"; EXPECT_EQ(8080, port) << "wrong port"; EXPECT_EQ("/my/path", path) << "wrong path"; }
void HippoGridManager::loadFromFile() { mDefaultGridsVersion = 0; // load user grid info parseFile(gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, "grid_info.xml"), false); // merge default grid info, if newer. Force load, if list of grids is empty. parseFile(gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "default_grids.xml"), !mGridInfo.empty()); // merge grid info from web site, if newer. Force load, if list of grids is empty. if (gSavedSettings.getBOOL("CheckForGridUpdates")) parseUrl("http://imprudenceviewer.org/app/grids/", !mGridInfo.empty()); std::string last_grid = gSavedSettings.getString("LastSelectedGrid"); if (last_grid.empty()) last_grid = gSavedSettings.getString("DefaultGrid"); setDefaultGrid(last_grid); setCurrentGrid(last_grid); }
/*This function will be executed after the request served to release allocated data*/ void search_record_release_request_data(void *data) { /*The data points to the search_record_req_data struct we allocated in function search_record_init_service */ struct SearchRecord *search_record_data = (struct SearchRecord *)data; char url[URL_LEN]; if(search_record_data == NULL) return; if(getMainUrl(search_record_data->full_url,url,URL_LEN) == NULL) { free(search_record_data); return; } ci_debug_printf(5,"request url= %s\n",search_record_data->full_url); parseUrl(search_record_data,&search_engine); /*if we had body data, release the related allocated data*/ free(search_record_data); }
/* **************************************************************************** * * Notifier::sendNotifyContextAvailabilityRequest - * * FIXME: this method is very similar to sendNotifyContextRequest and probably * they could be refactored in the future to have a common part using a parent * class for both types of notifications and using it as first argument */ void Notifier::sendNotifyContextAvailabilityRequest(NotifyContextAvailabilityRequest* ncar, const std::string& url, const std::string& tenant, Format format) { /* Render NotifyContextAvailabilityRequest */ std::string payload = ncar->render(NotifyContextAvailability, format, ""); /* Parse URL */ std::string host; int port; std::string uriPath; std::string protocol; if (!parseUrl(url, host, port, uriPath, protocol)) { LM_W(("Bad Input (sending NotifyContextAvailabilityRequest: malformed URL: '%s')", url.c_str())); return; } /* Set Content-Type depending on the format */ std::string content_type = (format == XML ? "application/xml" : "application/json"); /* Send the message (no wait for response, in a separated thread to avoid blocking response)*/ #ifdef SEND_BLOCKING sendHttpSocket(host, port, protocol, "POST", tenant, "", "", uriPath, content_type, payload, true, NOTIFICATION_WAIT_MODE); #endif #ifdef SEND_IN_NEW_THREAD pthread_t tid; SenderThreadParams* params = new SenderThreadParams(); params->ip = host; params->port = port; params->verb = "POST"; params->tenant = tenant; params->resource = uriPath; params->content_type = content_type; params->content = payload; strncpy(params->transactionId, transactionId, sizeof(params->transactionId)); int ret = pthread_create(&tid, NULL, startSenderThread, params); if (ret != 0) { LM_E(("Runtime Error (error creating thread: %d)", ret)); return; } pthread_detach(tid); #endif }