int CyaSSL_OCSP_set_override_url(CYASSL_OCSP* ocsp, const char* url) { if (ocsp != NULL) { int urlSz = (int)XSTRLEN(url); decode_url(url, urlSz, ocsp->overrideName, ocsp->overridePath, &ocsp->overridePort); return 1; } return 0; }
static int http_ocsp_transaction(CYASSL_OCSP* ocsp, DecodedCert* cert, byte* ocspReqBuf, int ocspReqSz, byte** ocspRespBuf) { SOCKET_T sfd = -1; byte httpBuf[SCRATCH_BUFFER_SIZE]; int httpBufSz = SCRATCH_BUFFER_SIZE; char domainName[80], path[80]; int port, ocspRespSz; if (ocsp->useOverrideUrl || cert->extAuthInfo == NULL) { if (ocsp->overrideName != NULL) { XMEMCPY(domainName, ocsp->overrideName, 80); XMEMCPY(path, ocsp->overridePath, 80); port = ocsp->overridePort; } else return OCSP_NEED_URL; } else { if (!decode_url((const char*)cert->extAuthInfo, cert->extAuthInfoSz, domainName, path, &port)) return OCSP_NEED_URL; } httpBufSz = build_http_request(domainName, path, ocspReqSz, httpBuf, httpBufSz); tcp_connect(&sfd, domainName, port); if (sfd > 0) { int written; written = (int)write(sfd, httpBuf, httpBufSz); if (written == httpBufSz) { written = (int)write(sfd, ocspReqBuf, ocspReqSz); if (written == ocspReqSz) { httpBufSz = (int)read(sfd, httpBuf, SCRATCH_BUFFER_SIZE); if (httpBufSz > 0) { ocspRespSz = decode_http_response(httpBuf, httpBufSz, ocspRespBuf); } } } close(sfd); if (ocspRespSz == 0) { CYASSL_MSG("HTTP response was not OK, no OCSP response"); return OCSP_LOOKUP_FAIL; } } else { CYASSL_MSG("OCSP Responder connection failed"); return OCSP_LOOKUP_FAIL; } return ocspRespSz; }
/* Process keyphrases from Google search, cache, and translate. * Note that the referer hasn't been decoded at the entry point * since there could be '&' within the search query. */ static int process_keyphrases (char *ref) { char *r, *ptr, *pch, *referer; int encoded = 0; if (!(strstr (ref, "http://www.google.")) && !(strstr (ref, "http://webcache.googleusercontent.com/")) && !(strstr (ref, "http://translate.googleusercontent.com/"))) return 1; /* webcache.googleusercontent */ if ((r = strstr (ref, "/+&")) != NULL) return 1; /* webcache.googleusercontent */ else if ((r = strstr (ref, "/+")) != NULL) r += 2; /* webcache.googleusercontent */ else if ((r = strstr (ref, "q=cache:")) != NULL) { pch = strchr (r, '+'); if (pch) r += pch - r + 1; } /* www.google.* or translate.googleusercontent */ else if ((r = strstr (ref, "&q=")) != NULL || (r = strstr (ref, "?q=")) != NULL) r += 3; else if ((r = strstr (ref, "%26q%3D")) != NULL || (r = strstr (ref, "%3Fq%3D")) != NULL) encoded = 1, r += 7; else return 1; if (!encoded && (ptr = strchr (r, '&')) != NULL) *ptr = '\0'; else if (encoded && (ptr = strstr (r, "%26")) != NULL) *ptr = '\0'; referer = decode_url (r); if (referer == NULL || *referer == '\0') return 1; referer = char_replace (referer, '+', ' '); process_generic_data (ht_keyphrases, trim_str (referer)); free (referer); return 0; }
int32_t SearcherWorker::getDetailInfo(const char *q_reslut, uint32_t q_size, const char *pureString, char** res, int* res_size) { //for detail char** args = NULL; int fieldCount = 0; char* pLightKey = 0; char* pDL = 0; if(!q_reslut || 0 == q_size){ return KS_EFAILED; } pLightKey = FRAMEWORK::Query::getParam(pureString, q_size, LIGHTKEY); if(pLightKey && pLightKey[0]!=0){ int len = strlen(pLightKey); int ret = decode_url(pLightKey, len, pLightKey, len+1); if(ret<0){ TWARN("decode_url pLightKey error, return!"); _session.setStatus(FRAMEWORK::ss_error); _session.response(); return KS_EFAILED; } pLightKey[ret] = 0; } pDL = FRAMEWORK::Query::getParam(pureString, q_size, DL); fieldCount = get_di_field_count(); if(di_detail_arg_alloc(&args)<(fieldCount+1)){ TERR("di_detail_arg_alloc error, return!"); _session.setStatus(FRAMEWORK::ss_error); _session.response(); return KS_EFAILED; } di_detail_arg_set(args, fieldCount+1, "title", 5, pLightKey, pDL); //Deal with detail if(di_detail_get_v3(q_reslut, pDL, args, fieldCount, res, res_size)){ *res = (char*)malloc(2); (*res)[0] = '0'; (*res)[1] = 0; *res_size = 1; } if(pLightKey)std::free(pLightKey); if(pDL)std::free(pDL); if(args)di_detail_arg_free(args); return KS_SUCCESS; }
static char * parse_req (char *line, char **method, char **protocol) { char *req = NULL, *request = NULL, *proto = NULL, *dreq = NULL; const char *meth; ptrdiff_t rlen; meth = extract_method (line); /* couldn't find a method, so use the whole request line */ if (meth == NULL) { request = xstrdup (line); } /* method found, attempt to parse request */ else { req = line + strlen (meth); if ((proto = strstr (line, " HTTP/1.0")) == NULL && (proto = strstr (line, " HTTP/1.1")) == NULL) { return alloc_string ("-"); } req++; if ((rlen = proto - req) <= 0) return alloc_string ("-"); request = xmalloc (rlen + 1); strncpy (request, req, rlen); request[rlen] = 0; if (conf.append_method) (*method) = strtoupper (xstrdup (meth)); if (conf.append_protocol) (*protocol) = strtoupper (xstrdup (++proto)); } if ((dreq = decode_url (request)) && dreq != '\0') { free (request); return dreq; } return request; }
/* process referer */ static void process_referrers (char *referrer, char *site) { char *ref; if (referrer == NULL) return; if (site != NULL && *site != '\0') process_generic_data (ht_referring_sites, site); process_keyphrases (referrer); ref = decode_url (referrer); if (ref == NULL || *ref == '\0') return; process_generic_data (ht_referrers, ref); free (ref); }
bool SetInfoDataObject::SetData(const wxDataFormat& format, size_t len, const void *buf) { if (format.GetType() != wxDF_TEXT && format.GetType() != wxDF_FILENAME // && format.GetType() != wxDF_OEMTEXT && format.GetType() != wxDF_UNICODETEXT) return false; unsigned char *escaped = (unsigned char*)malloc(len + 1); memcpy(escaped, buf, len); escaped[len] = '\0'; wxString url = decode_string(escaped); free(escaped); url.Trim(true); url.Trim(false); if (!decode_url(url, m_prefix, m_set, m_period, m_time, m_selected_draw)) return false; return true; }
/* process referer */ static void process_referrers (char *referrer) { char *ref; char url[REF_SITE_LEN] = ""; if (referrer == NULL) return; /* extract the host part, i.e., www.foo.com */ if (sscanf (referrer, "%*[^/]%*[/]%[^/]", url) == 1) process_generic_data (ht_referring_sites, url); process_keyphrases (referrer); ref = decode_url (referrer); if (ref == NULL || *ref == '\0') return; process_generic_data (ht_referrers, ref); free (ref); }
void add_http_test(testitem_t *t) { http_data_t *httptest; char *dnsip = NULL; ssloptions_t *sslopt = NULL; char *sslopt_ciphers = NULL; int sslopt_version = SSLVERSION_DEFAULT; char *sslopt_clientcert = NULL; int httpversion = HTTPVER_11; cookielist_t *ck = NULL; int firstcookie = 1; char *decodedurl; strbuffer_t *httprequest = newstrbuffer(0); /* Allocate the private data and initialize it */ httptest = (http_data_t *) calloc(1, sizeof(http_data_t)); t->privdata = (void *) httptest; decodedurl = decode_url(t->testspec, &httptest->weburl); if (!decodedurl) { errprintf("Invalid URL for http check: %s\n", t->testspec); return; } httptest->url = strdup(decodedurl); httptest->contlen = -1; httptest->parsestatus = (httptest->weburl.proxyurl ? httptest->weburl.proxyurl->parseerror : httptest->weburl.desturl->parseerror); /* If there was a parse error in the URL, dont run the test */ if (httptest->parsestatus) return; if (httptest->weburl.proxyurl && (httptest->weburl.proxyurl->ip == NULL)) { dnsip = dnsresolve(httptest->weburl.proxyurl->host); if (dnsip) { httptest->weburl.proxyurl->ip = strdup(dnsip); } else { dbgprintf("Could not resolve URL hostname '%s'\n", httptest->weburl.proxyurl->host); } } else if (httptest->weburl.desturl->ip == NULL) { dnsip = dnsresolve(httptest->weburl.desturl->host); if (dnsip) { httptest->weburl.desturl->ip = strdup(dnsip); } else { dbgprintf("Could not resolve URL hostname '%s'\n", httptest->weburl.desturl->host); } } switch (httptest->weburl.testtype) { case WEBTEST_PLAIN: case WEBTEST_STATUS: httptest->contentcheck = CONTENTCHECK_NONE; break; case WEBTEST_CONTENT: { FILE *contentfd; char contentfn[PATH_MAX]; sprintf(contentfn, "%s/content/%s.substring", xgetenv("XYMONHOME"), commafy(t->host->hostname)); contentfd = fopen(contentfn, "r"); if (contentfd) { char l[MAX_LINE_LEN]; char *p; if (fgets(l, sizeof(l), contentfd)) { p = strchr(l, '\n'); if (p) { *p = '\0'; }; httptest->weburl.expdata = strdup(l); } else { httptest->contstatus = STATUS_CONTENTMATCH_NOFILE; } fclose(contentfd); } else { httptest->contstatus = STATUS_CONTENTMATCH_NOFILE; } httptest->contentcheck = CONTENTCHECK_REGEX; } break; case WEBTEST_CONT: httptest->contentcheck = ((*httptest->weburl.expdata == '#') ? CONTENTCHECK_DIGEST : CONTENTCHECK_REGEX); break; case WEBTEST_NOCONT: httptest->contentcheck = CONTENTCHECK_NOREGEX; break; case WEBTEST_POST: case WEBTEST_SOAP: if (httptest->weburl.expdata == NULL) { httptest->contentcheck = CONTENTCHECK_NONE; } else { httptest->contentcheck = ((*httptest->weburl.expdata == '#') ? CONTENTCHECK_DIGEST : CONTENTCHECK_REGEX); } break; case WEBTEST_NOPOST: case WEBTEST_NOSOAP: if (httptest->weburl.expdata == NULL) { httptest->contentcheck = CONTENTCHECK_NONE; } else { httptest->contentcheck = CONTENTCHECK_NOREGEX; } break; case WEBTEST_TYPE: httptest->contentcheck = CONTENTCHECK_CONTENTTYPE; break; } /* Compile the hashes and regex's for those tests that use it */ switch (httptest->contentcheck) { case CONTENTCHECK_DIGEST: { char *hashfunc; httptest->exp = (void *) strdup(httptest->weburl.expdata+1); hashfunc = strchr(httptest->exp, ':'); if (hashfunc) { *hashfunc = '\0'; httptest->digestctx = digest_init(httptest->exp); *hashfunc = ':'; } } break; case CONTENTCHECK_REGEX: case CONTENTCHECK_NOREGEX: { int status; httptest->exp = (void *) malloc(sizeof(regex_t)); status = regcomp((regex_t *)httptest->exp, httptest->weburl.expdata, REG_EXTENDED|REG_NOSUB); if (status) { errprintf("Failed to compile regexp '%s' for URL %s\n", httptest->weburl.expdata, httptest->url); httptest->contstatus = STATUS_CONTENTMATCH_BADREGEX; } } break; case CONTENTCHECK_CONTENTTYPE: httptest->exp = httptest->weburl.expdata; break; } if (httptest->weburl.desturl->schemeopts) { if (strstr(httptest->weburl.desturl->schemeopts, "3")) sslopt_version = SSLVERSION_V3; else if (strstr(httptest->weburl.desturl->schemeopts, "2")) sslopt_version = SSLVERSION_V2; if (strstr(httptest->weburl.desturl->schemeopts, "h")) sslopt_ciphers = ciphershigh; else if (strstr(httptest->weburl.desturl->schemeopts, "m")) sslopt_ciphers = ciphersmedium; if (strstr(httptest->weburl.desturl->schemeopts, "10")) httpversion = HTTPVER_10; else if (strstr(httptest->weburl.desturl->schemeopts, "11")) httpversion = HTTPVER_11; } /* Get any cookies */ load_cookies(); /* Generate the request */ addtobuffer(httprequest, (httptest->weburl.postdata ? "POST " : "GET ")); switch (httpversion) { case HTTPVER_10: addtobuffer(httprequest, (httptest->weburl.proxyurl ? httptest->url : httptest->weburl.desturl->relurl)); addtobuffer(httprequest, " HTTP/1.0\r\n"); break; case HTTPVER_11: /* * Experience shows that even though HTTP/1.1 says you should send the * full URL, some servers (e.g. SunOne App server 7) choke on it. * So just send the good-old relative URL unless we're proxying. */ addtobuffer(httprequest, (httptest->weburl.proxyurl ? httptest->url : httptest->weburl.desturl->relurl)); addtobuffer(httprequest, " HTTP/1.1\r\n"); addtobuffer(httprequest, "Connection: close\r\n"); break; } addtobuffer(httprequest, "Host: "); addtobuffer(httprequest, httptest->weburl.desturl->host); if ((httptest->weburl.desturl->port != 80) && (httptest->weburl.desturl->port != 443)) { char hostporthdr[20]; sprintf(hostporthdr, ":%d", httptest->weburl.desturl->port); addtobuffer(httprequest, hostporthdr); } addtobuffer(httprequest, "\r\n"); if (httptest->weburl.postdata) { char hdr[100]; int contlen = strlen(httptest->weburl.postdata); if (strncmp(httptest->weburl.postdata, "file:", 5) == 0) { /* Load the POST data from a file */ FILE *pf = fopen(httptest->weburl.postdata+5, "r"); if (pf == NULL) { errprintf("Cannot open POST data file %s\n", httptest->weburl.postdata+5); xfree(httptest->weburl.postdata); httptest->weburl.postdata = strdup(""); contlen = 0; } else { struct stat st; if (fstat(fileno(pf), &st) == 0) { int n; xfree(httptest->weburl.postdata); httptest->weburl.postdata = (char *)malloc(st.st_size + 1); *(httptest->weburl.postdata) = '\0'; n = fread(httptest->weburl.postdata, 1, st.st_size, pf); if (n == st.st_size) { *(httptest->weburl.postdata+n) = '\0'; contlen = n; } else { errprintf("Cannot read file %s: %s\n", httptest->weburl.postdata+5, strerror(errno)); contlen = 0; } } else { errprintf("Cannot stat file %s\n", httptest->weburl.postdata+5); httptest->weburl.postdata = strdup(""); contlen = 0; } fclose(pf); } } addtobuffer(httprequest, "Content-type: "); if (httptest->weburl.postcontenttype) addtobuffer(httprequest, httptest->weburl.postcontenttype); else if ((httptest->weburl.testtype == WEBTEST_SOAP) || (httptest->weburl.testtype == WEBTEST_NOSOAP)) addtobuffer(httprequest, "application/soap+xml; charset=utf-8"); else addtobuffer(httprequest, "application/x-www-form-urlencoded"); addtobuffer(httprequest, "\r\n"); sprintf(hdr, "Content-Length: %d\r\n", contlen); addtobuffer(httprequest, hdr); } { char useragent[100]; void *hinfo; char *browser = NULL; hinfo = hostinfo(t->host->hostname); if (hinfo) browser = xmh_item(hinfo, XMH_BROWSER); if (browser) { sprintf(useragent, "User-Agent: %s\r\n", browser); } else { sprintf(useragent, "User-Agent: Xymon xymonnet/%s\r\n", VERSION); } addtobuffer(httprequest, useragent); } if (httptest->weburl.desturl->auth) { if (strncmp(httptest->weburl.desturl->auth, "CERT:", 5) == 0) { sslopt_clientcert = httptest->weburl.desturl->auth+5; } else { addtobuffer(httprequest, "Authorization: Basic "); addtobuffer(httprequest, base64encode(httptest->weburl.desturl->auth)); addtobuffer(httprequest, "\r\n"); } } if (httptest->weburl.proxyurl && httptest->weburl.proxyurl->auth) { addtobuffer(httprequest, "Proxy-Authorization: Basic "); addtobuffer(httprequest, base64encode(httptest->weburl.proxyurl->auth)); addtobuffer(httprequest, "\r\n"); } for (ck = cookiehead; (ck); ck = ck->next) { int useit = 0; if (ck->tailmatch) { int startpos = strlen(httptest->weburl.desturl->host) - strlen(ck->host); if (startpos > 0) useit = (strcmp(httptest->weburl.desturl->host+startpos, ck->host) == 0); } else useit = (strcmp(httptest->weburl.desturl->host, ck->host) == 0); if (useit) useit = (strncmp(ck->path, httptest->weburl.desturl->relurl, strlen(ck->path)) == 0); if (useit) { if (firstcookie) { addtobuffer(httprequest, "Cookie: "); firstcookie = 0; } addtobuffer(httprequest, ck->name); addtobuffer(httprequest, "="); addtobuffer(httprequest, ck->value); addtobuffer(httprequest, "\r\n"); } } /* Some standard stuff */ addtobuffer(httprequest, "Accept: */*\r\n"); addtobuffer(httprequest, "Pragma: no-cache\r\n"); if ((httptest->weburl.testtype == WEBTEST_SOAP) || (httptest->weburl.testtype == WEBTEST_NOSOAP)) { /* Must provide a SOAPAction header */ addtobuffer(httprequest, "SOAPAction: "); addtobuffer(httprequest, httptest->url); addtobuffer(httprequest, "\r\n"); } /* The final blank line terminates the headers */ addtobuffer(httprequest, "\r\n"); /* Post data goes last */ if (httptest->weburl.postdata) addtobuffer(httprequest, httptest->weburl.postdata); /* Pickup any SSL options the user wants */ if (sslopt_ciphers || (sslopt_version != SSLVERSION_DEFAULT) || sslopt_clientcert){ sslopt = (ssloptions_t *) malloc(sizeof(ssloptions_t)); sslopt->cipherlist = sslopt_ciphers; sslopt->sslversion = sslopt_version; sslopt->clientcert = sslopt_clientcert; } /* Add to TCP test queue */ if (httptest->weburl.proxyurl == NULL) { httptest->tcptest = add_tcp_test(httptest->weburl.desturl->ip, httptest->weburl.desturl->port, httptest->weburl.desturl->scheme, sslopt, t->srcip, t->testspec, t->silenttest, grabstrbuffer(httprequest), httptest, tcp_http_data_callback, tcp_http_final_callback); } else { httptest->tcptest = add_tcp_test(httptest->weburl.proxyurl->ip, httptest->weburl.proxyurl->port, httptest->weburl.proxyurl->scheme, sslopt, t->srcip, t->testspec, t->silenttest, grabstrbuffer(httprequest), httptest, tcp_http_data_callback, tcp_http_final_callback); } }
void *http_process(void *args) { int32 fd; struct http_request *req; int8 *cp = NULL; int8 *line = NULL; int8 *method = NULL; int8 *url = NULL; int8 *protocol = NULL; struct timeval timo; int32 optval = 1; int32 rc, rc_r, rc_s; int32 r = 0; if (NULL == args) return NULL; req = (struct http_request *)args; fd = req->fd; req->buff = malloc(BUFFSIZ); req->buff_size = BUFFSIZ; if (NULL == req->buff) { HTTPD_ERR("get_request_line malloc %d fail\n", BUFFSIZ); free(args); return NULL; } memset(req->buff, 0, BUFFSIZ); rc = setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &optval, sizeof(optval)); if (rc < 0) HTTPD_ERR("setsockopt error rc=%d errno=%d %s\n", rc, errno, strerror(errno)); timo.tv_sec = HTTPD_TIMO; timo.tv_usec = 0; rc_r = setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &timo, sizeof(timo)); rc_s = setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &timo, sizeof(timo)); if (rc_r < 0 || rc_s < 0) HTTPD_ERR("setsockopt error fd=%d rc=%d rc_r=%d rc_s=%d errno=%d %s\n", fd, rc, rc_r, rc_s, errno, strerror(errno)); /* GET / HTTP/1.1 */ method = get_request_line(req); if (method == NULL) goto close_task; url = parse_reqline(fd, method); if (url == NULL) goto close_task; protocol = parse_reqline(fd, url); if (protocol == NULL) goto close_task; req->method = http_method(method); if (req->method == M_OPTIONS) { send_error(fd, 204, "No Content", NULL, "Method OPTIONS."); goto close_task; } if (req->method == M_UNKNOWN) { send_error(fd, 400, "Bad Request", NULL, "Method Not Support."); goto close_task; } decode_url(req, url); HTTPD_INFO("method[%s] protocol[%s] url[%s] path[%s] query[%s]!\n", method, protocol, url, req->path, req->query ? : ""); while ((line = get_request_line(req)) != NULL) { if (line[0] == '\0') break; if (strncasecmp(line, "Upgrade:", 8) == 0) { cp = &line[8]; cp += strspn(cp, " \t"); if (strncasecmp(cp, "websocket", 9) == 0) req->is_websocket = 1; } else if (strncasecmp(line, "Connection:", 11) == 0) { cp = &line[11]; cp += strspn(cp, " \t"); /* Firefox: [Connection: keep-alive, Upgrade] */ if (strcasestr(cp, "Upgrade") != NULL) req->is_connection_upgrade = 1; } else if (strncasecmp(line, "Sec-WebSocket-Key:", 18) == 0) { cp = &line[18]; cp += strspn(cp, " \t"); req->sec_websocket_key = cp; } else if (strncasecmp(line, "Origin:", 7) == 0) { cp = &line[7]; cp += strspn(cp, " \t"); req->origin = cp; } else if (strncasecmp(line, "Sec-WebSocket-Version:", 22) == 0) { cp = &line[22]; cp += strspn(cp, " \t"); req->sec_websocket_version = atoi(cp); } else if (strncasecmp(line, "Content-Length:", 15) == 0) { cp = &line[15]; cp += strspn(cp, " \t"); req->content_length = atol(cp); if ((BUFFSIZ < req->content_length + MAX_HEADER_LEN) && (req->buff_size != req->content_length + MAX_HEADER_LEN) + 1) { re_alloc_buff(req); memset(req->buff + BUFFSIZ, 0, req->buff_size - BUFFSIZ); } } else if (strncasecmp(line, "Content-Type:", 13) == 0) { cp = &line[13]; cp += strspn(cp, " \t"); req->content_type = cp; } else if (strncasecmp(line, "Host:", 5) == 0) { cp = &line[5]; cp += strspn(cp, " \t"); req->host = cp; } } HTTPD_INFO("Left %d bytes HTTP data with Content-Length: %ld req->sz[%d] req->pos[%d]\n", req->sz - req->pos, req->content_length, req->sz, req->pos); if (line == NULL || req->path[0] != '/') send_error(fd, 400, "Bad Request", NULL, "Bad Request!"); if ((0 != req->content_length) && (req->sz != req->hd_sz + req->content_length)) { while ((r = http_read(req->fd, req->buff + req->sz, req->buff_size - req->sz)) > 0) { req->sz += r; if (req->sz == req->hd_sz + req->content_length) break; } } if (req->is_websocket) ws_process(req); else { uint32 i = 0; int8 *file = NULL; int8 *path = req->path; int8 *pTmp = path; int8 prefix[PREFIX_LEN] = {0}; int8 new_link[MAX_URL + 8] = {0}; rmm_cfg_get_rest_prefix(prefix, PREFIX_LEN); /*snprintf(new_link, (MAX_URL + 8), "%s%s", prefix, "/rack");*/ snprintf_s_s(new_link, (MAX_URL + 8), "%s", prefix); /*TODO: move to correct place */ get_json_pointer(req); /* remove redundant '/' */ for (; *(path+i) != '\0'; i++) { if ((*(path+i) == '/') && (*(path+i+1) == '/')) continue; *pTmp++ = *(path+i); } *pTmp = '\0'; if ((path[1] == '\0') || (strncasecmp(path, new_link, strnlen_s(new_link, sizeof(new_link)-1)) == 0)) file = NULL; else file = path; if (file != NULL) send_file(req->fd, file); else rest_process(req); } close_task: close(fd); if (NULL != req->buff) { free(req->buff); req->buff = NULL; } HTTPD_INFO("\nrest_req_thread[%lld] exit, fd[%d], errno:%d %s\n", (uint64)(req->tid_rest_req), fd, errno, strerror(errno)); free(args); pthread_detach(pthread_self()); return NULL; }
static void print_host(hostlist_t *host, htnames_t *testnames[], int testcount) { int testi, rowcount, netcount; void *hinfo = hostinfo(host->hostname); char *dispname = NULL, *clientalias = NULL, *comment = NULL, *description = NULL, *pagepathtitle = NULL; char *net = NULL, *nkalerts = NULL; char *nktime = NULL, *downtime = NULL, *reporttime = NULL; char *itm; tag_t *taghead = NULL; int contidx = 0, haveping = 0; char contcol[1024]; activealerts_t *alert; strbuffer_t *buf = newstrbuffer(0); fprintf(stdout, "<p style=\"page-break-before: always\">\n"); fprintf(stdout, "<table width=\"100%%\" border=1 summary=\"%s configuration\">\n", host->hostname); pagepathtitle = bbh_item(hinfo, BBH_PAGEPATHTITLE); if (!pagepathtitle || (strlen(pagepathtitle) == 0)) pagepathtitle = "Top page"; dispname = bbh_item(hinfo, BBH_DISPLAYNAME); if (dispname && (strcmp(dispname, host->hostname) == 0)) dispname = NULL; clientalias = bbh_item(hinfo, BBH_CLIENTALIAS); if (clientalias && (strcmp(clientalias, host->hostname) == 0)) clientalias = NULL; comment = bbh_item(hinfo, BBH_COMMENT); description = bbh_item(hinfo, BBH_DESCRIPTION); net = bbh_item(hinfo, BBH_NET); nkalerts = bbh_item(hinfo, BBH_NK); nktime = bbh_item(hinfo, BBH_NKTIME); if (!nktime) nktime = "24x7"; else nktime = strdup(timespec_text(nktime)); downtime = bbh_item(hinfo, BBH_DOWNTIME); if (downtime) downtime = strdup(timespec_text(downtime)); reporttime = bbh_item(hinfo, BBH_REPORTTIME); if (!reporttime) reporttime = "24x7"; else reporttime = strdup(timespec_text(reporttime)); rowcount = 1; if (pagepathtitle) rowcount++; if (dispname || clientalias) rowcount++; if (comment) rowcount++; if (description) rowcount++; if (!newnkconfig && nktime) rowcount++; if (downtime) rowcount++; if (reporttime) rowcount++; fprintf(stdout, "<tr>\n"); fprintf(stdout, "<th rowspan=%d align=left width=\"25%%\" valign=top>Basics</th>\n", rowcount); fprintf(stdout, "<th align=center>%s (%s)</th>\n", (dispname ? dispname : host->hostname), bbh_item(hinfo, BBH_IP)); fprintf(stdout, "</tr>\n"); if (dispname || clientalias) { fprintf(stdout, "<tr><td>Aliases:"); if (dispname) fprintf(stdout, " %s", dispname); if (clientalias) fprintf(stdout, " %s", clientalias); fprintf(stdout, "</td></tr>\n"); } if (pagepathtitle) fprintf(stdout, "<tr><td>Monitoring location: %s</td></tr>\n", pagepathtitle); if (comment) fprintf(stdout, "<tr><td>Comment: %s</td></tr>\n", comment); if (description) fprintf(stdout, "<tr><td>Description: %s</td></tr>\n", description); if (!newnkconfig && nktime) fprintf(stdout, "<tr><td>NK monitoring period: %s</td></tr>\n", nktime); if (downtime) fprintf(stdout, "<tr><td>Planned downtime: %s</td></tr>\n", downtime); if (reporttime) fprintf(stdout, "<tr><td>SLA Reporting Period: %s</td></tr>\n", reporttime); /* Build a list of the network tests */ itm = bbh_item_walk(hinfo); while (itm) { char *visdata = NULL, *colname = NULL, *expdata = NULL; bburl_t bu; int dialuptest = 0, reversetest = 0, alwaystruetest = 0, httpextra = 0; if (*itm == '?') { dialuptest=1; itm++; } if (*itm == '!') { reversetest=1; itm++; } if (*itm == '~') { alwaystruetest=1; itm++; } if ( argnmatch(itm, "http") || argnmatch(itm, "content=http") || argnmatch(itm, "cont;http") || argnmatch(itm, "cont=") || argnmatch(itm, "nocont;http") || argnmatch(itm, "nocont=") || argnmatch(itm, "post;http") || argnmatch(itm, "post=") || argnmatch(itm, "nopost;http") || argnmatch(itm, "nopost=") || argnmatch(itm, "type;http") || argnmatch(itm, "type=") ) { visdata = decode_url(itm, &bu); colname = bu.columnname; if (!colname) { if (bu.expdata) { httpextra = 1; if (contidx == 0) { colname = "content"; contidx++; } else { sprintf(contcol, "content%d", contidx); colname = contcol; contidx++; } } else { colname = "http"; } } expdata = bu.expdata; } else if (strncmp(itm, "rpc=", 4) == 0) { colname = "rpc"; visdata = strdup(itm+4); } else if (strncmp(itm, "dns=", 4) == 0) { colname = "dns"; visdata = strdup(itm+4); } else if (strncmp(itm, "dig=", 4) == 0) { colname = "dns"; visdata = strdup(itm+4); } else if (strncmp(itm, pingplus, strlen(pingplus)) == 0) { haveping = 1; colname = pingcolumn; visdata = strdup(itm+strlen(pingplus)); } else if (is_net_test(itm)) { colname = strdup(itm); } if (colname) { tag_t *newitem; addtolist: for (newitem = taghead; (newitem && strcmp(newitem->columnname, colname)); newitem = newitem->next); if (!newitem) { newitem = (tag_t *)calloc(1, sizeof(tag_t)); newitem->columnname = strdup(colname); newitem->visualdata = (visdata ? strdup(visdata) : NULL); newitem->expdata = (expdata ? strdup(expdata) : NULL); newitem->next = taghead; taghead = newitem; } else { /* Multiple tags for one column - must be http */ newitem->visualdata = (char *)realloc(newitem->visualdata, strlen(newitem->visualdata) + strlen(visdata) + 5); strcat(newitem->visualdata, "<br>"); strcat(newitem->visualdata, visdata); } if (httpextra) { httpextra = 0; colname = "http"; expdata = NULL; goto addtolist; } } itm = bbh_item_walk(NULL); } if (!haveping && !bbh_item(hinfo, BBH_FLAG_NOCONN)) { for (testi = 0; (testi < testcount); testi++) { if (strcmp(testnames[testi]->name, pingcolumn) == 0) { tag_t *newitem = (tag_t *)calloc(1, sizeof(tag_t)); newitem->columnname = strdup(pingcolumn); newitem->next = taghead; taghead = newitem; } } } /* Add the "badFOO" settings */ itm = bbh_item_walk(hinfo); while (itm) { if (strncmp(itm, "bad", 3) == 0) { char *tname, *p; int b1, b2, b3, n = -1; tag_t *tag = NULL; tname = itm+3; p = strchr(tname, ':'); if (p) { *p = '\0'; n = sscanf(p+1, "%d:%d:%d", &b1, &b2, &b3); for (tag = taghead; (tag && strcmp(tag->columnname, tname)); tag = tag->next); *p = ':'; } if (tag && (n == 3)) { tag->b1 = b1; tag->b2 = b2; tag->b3 = b3; } } itm = bbh_item_walk(NULL); } if (taghead) { fprintf(stdout, "<tr>\n"); fprintf(stdout, "<th align=left valign=top>Network tests"); if (net) fprintf(stdout, "<br>(from %s)", net); fprintf(stdout, "</th>\n"); fprintf(stdout, "<td><table border=0 cellpadding=\"3\" cellspacing=\"5\" summary=\"%s network tests\">\n", host->hostname); fprintf(stdout, "<tr><th align=left valign=top>Service</th><th align=left valign=top>NK</th><th align=left valign=top>C/Y/R limits</th><th align=left valign=top>Specifics</th></tr>\n"); } for (testi = 0, netcount = 0; (testi < testcount); testi++) { tag_t *twalk; for (twalk = taghead; (twalk && strcasecmp(twalk->columnname, testnames[testi]->name)); twalk = twalk->next); if (!twalk) continue; use_columndoc(testnames[testi]->name); fprintf(stdout, "<tr>"); fprintf(stdout, "<td valign=top>%s</td>", testnames[testi]->name); fprintf(stdout, "<td valign=top>%s</td>", nkval(host->hostname, testnames[testi]->name, nkalerts)); fprintf(stdout, "<td valign=top>"); if (twalk->b1 || twalk->b2 || twalk->b3) { fprintf(stdout, "%d/%d/%d", twalk->b1, twalk->b2, twalk->b3); } else { fprintf(stdout, "-/-/-"); } fprintf(stdout, "</td>"); fprintf(stdout, "<td valign=top>"); fprintf(stdout, "<i>%s</i>", (twalk->visualdata ? twalk->visualdata : " ")); if (twalk->expdata) fprintf(stdout, " must return <i>'%s'</i>", twalk->expdata); fprintf(stdout, "</td>"); fprintf(stdout, "</tr>"); netcount++; } if (taghead) { fprintf(stdout, "</table></td>\n"); fprintf(stdout, "</tr>\n"); } if (netcount != testcount) { fprintf(stdout, "<tr>\n"); fprintf(stdout, "<th align=left valign=top>Local tests</th>\n"); fprintf(stdout, "<td><table border=0 cellpadding=\"3\" cellspacing=\"5\" summary=\"%s local tests\">\n", host->hostname); fprintf(stdout, "<tr><th align=left valign=top>Service</th><th align=left valign=top>NK</th><th align=left valign=top>C/Y/R limits</th><th align=left valign=top>Configuration <i>(NB: Thresholds on client may differ)</i></th></tr>\n"); } for (testi = 0; (testi < testcount); testi++) { tag_t *twalk; for (twalk = taghead; (twalk && strcasecmp(twalk->columnname, testnames[testi]->name)); twalk = twalk->next); if (twalk) continue; use_columndoc(testnames[testi]->name); fprintf(stdout, "<tr>"); fprintf(stdout, "<td valign=top>%s</td>", testnames[testi]->name); fprintf(stdout, "<td valign=top>%s</td>", nkval(host->hostname, testnames[testi]->name, nkalerts)); fprintf(stdout, "<td valign=top>-/-/-</td>"); /* Make up some default configuration data */ fprintf(stdout, "<td valign=top>"); if (strcmp(testnames[testi]->name, "cpu") == 0) { fprintf(stdout, "UNIX - Yellow: Load average > 1.5, Red: Load average > 3.0<br>"); fprintf(stdout, "Windows - Yellow: CPU utilisation > 80%%, Red: CPU utilisation > 95%%"); } else if (strcmp(testnames[testi]->name, "disk") == 0) { fprintf(stdout, "Default limits: Yellow 90%% full, Red 95%% full<br>\n"); print_disklist(host->hostname); } else if (strcmp(testnames[testi]->name, "memory") == 0) { fprintf(stdout, "Yellow: swap/pagefile use > 80%%, Red: swap/pagefile use > 90%%"); } else if (strcmp(testnames[testi]->name, "procs") == 0) { htnames_t *walk; if (!host->procs) fprintf(stdout, "No processes monitored<br>\n"); for (walk = host->procs; (walk); walk = walk->next) { fprintf(stdout, "%s<br>\n", walk->name); } } else if (strcmp(testnames[testi]->name, "svcs") == 0) { htnames_t *walk; if (!host->svcs) fprintf(stdout, "No services monitored<br>\n"); for (walk = host->svcs; (walk); walk = walk->next) { fprintf(stdout, "%s<br>\n", walk->name); } } else { fprintf(stdout, " "); } fprintf(stdout, "</td>"); fprintf(stdout, "</tr>"); } if (netcount != testcount) { fprintf(stdout, "</table></td>\n"); fprintf(stdout, "</tr>\n"); } /* Do the alerts */ alert = (activealerts_t *)calloc(1, sizeof(activealerts_t)); alert->hostname = host->hostname; alert->location = bbh_item(hinfo, BBH_ALLPAGEPATHS); strcpy(alert->ip, "127.0.0.1"); alert->color = COL_RED; alert->pagemessage = ""; alert->state = A_PAGING; alert->cookie = 12345; alert_printmode(2); for (testi = 0; (testi < testcount); testi++) { alert->testname = testnames[testi]->name; if (have_recipient(alert, NULL)) print_alert_recipients(alert, buf); } xfree(alert); if (STRBUFLEN(buf) > 0) { fprintf(stdout, "<tr>\n"); fprintf(stdout, "<th align=left valign=top>Alerts</th>\n"); fprintf(stdout, "<td><table border=0 cellpadding=\"3\" cellspacing=\"5\" summary=\"%s alerts\">\n", host->hostname); fprintf(stdout, "<tr><th>Service</th><th>Recipient</th><th>1st Delay</th><th>Stop after</th><th>Repeat</th><th>Time of Day</th><th>Colors</th></tr>\n"); fprintf(stdout, "%s", STRBUF(buf)); fprintf(stdout, "</table></td>\n"); fprintf(stdout, "</tr>\n"); } /* Finish off this host */ fprintf(stdout, "</table>\n"); freestrbuffer(buf); }
static SongInfo * get_song_id_info(const gchar *id) { SongInfo *info = NULL; XmrService *service = xmr_service_new(); gchar *url = g_strdup_printf(XIAMI_INFO_URL"%s", id); GString *data = g_string_new(""); gint result = xmr_service_get_url_data(service, url, data); g_object_unref(service); do { const gchar *p = data->str; const gchar *q; gchar *tmp; if (result != 0) break; p = strstr(p, "<location>"); if (p == NULL) break; p += strlen("<location>"); q = strstr(p, "</location>"); if (q == NULL) break; // skip white space while (*p && isspace(*p)) p++; while (q > p && isspace(*(q-1))) q--; info = song_info_new(); tmp = g_strndup(p, q - p); info->location = decode_url(tmp); g_free(tmp); p = strstr(q, "<pic>"); if (p == NULL) break; p += strlen("<pic>"); q = strstr(p, "</pic>"); if (q == NULL) break; // skip white space while (*p && isspace(*p)) p++; while (q > p && isspace(*(q-1))) q--; info->album_cover = g_strndup(p, q - p); info->song_id = g_strdup(id); }while (0); decode_url(id); g_free(url); g_string_free(data, TRUE); return info; }
int EmbedOcspLookup(void* ctx, const char* url, int urlSz, byte* ocspReqBuf, int ocspReqSz, byte** ocspRespBuf) { SOCKET_T sfd = 0; word16 port; int ret = -1; #ifdef CYASSL_SMALL_STACK char* path; char* domainName; #else char path[80]; char domainName[80]; #endif #ifdef CYASSL_SMALL_STACK path = (char*)XMALLOC(80, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (path == NULL) return -1; domainName = (char*)XMALLOC(80, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (domainName == NULL) { XFREE(path, NULL, DYNAMIC_TYPE_TMP_BUFFER); return -1; } #endif (void)ctx; if (ocspReqBuf == NULL || ocspReqSz == 0) { CYASSL_MSG("OCSP request is required for lookup"); } else if (ocspRespBuf == NULL) { CYASSL_MSG("Cannot save OCSP response"); } else if (decode_url(url, urlSz, domainName, path, &port) < 0) { CYASSL_MSG("Unable to decode OCSP URL"); } else { /* Note, the library uses the EmbedOcspRespFree() callback to * free this buffer. */ int httpBufSz = SCRATCH_BUFFER_SIZE; byte* httpBuf = (byte*)XMALLOC(httpBufSz, NULL, DYNAMIC_TYPE_IN_BUFFER); if (httpBuf == NULL) { CYASSL_MSG("Unable to create OCSP response buffer"); } else { httpBufSz = build_http_request(domainName, path, ocspReqSz, httpBuf, httpBufSz); if ((tcp_connect(&sfd, domainName, port) != 0) || (sfd <= 0)) { CYASSL_MSG("OCSP Responder connection failed"); } else if ((int)send(sfd, (char*)httpBuf, httpBufSz, 0) != httpBufSz) { CYASSL_MSG("OCSP http request failed"); } else if ((int)send(sfd, (char*)ocspReqBuf, ocspReqSz, 0) != ocspReqSz) { CYASSL_MSG("OCSP ocsp request failed"); } else { ret = process_http_response(sfd, ocspRespBuf, httpBuf, SCRATCH_BUFFER_SIZE); } close(sfd); XFREE(httpBuf, NULL, DYNAMIC_TYPE_IN_BUFFER); } } #ifdef CYASSL_SMALL_STACK XFREE(path, NULL, DYNAMIC_TYPE_TMP_BUFFER); XFREE(domainName, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return ret; }
void media_info_get (xmmsv_t *value, media_info *info) { xmmsv_t *infos, *dict_entry; const char *artist, *album, *title, *url, *comment, *genre, *date; assert(value); assert(info); infos = xmmsv_propdict_to_dict(value, NULL); if (!xmmsv_dict_get (infos, "id", &dict_entry) || !xmmsv_get_int (dict_entry, &info->id)) { info->id = 0; } if (!xmmsv_dict_get (infos, "artist", &dict_entry) || !xmmsv_get_string (dict_entry, &artist)) { artist = "[Unknown Artist]"; } if (!xmmsv_dict_get (infos, "album", &dict_entry) || !xmmsv_get_string (dict_entry, &album)) { album = "[Unknown Album]"; } if (!xmmsv_dict_get (infos, "url", &dict_entry) || !xmmsv_get_string (dict_entry, &url)) { url = "[Unknown URL]"; } if (!xmmsv_dict_get (infos, "title", &dict_entry) || !xmmsv_get_string (dict_entry, &title)) { title = ecore_file_file_get(url); } if (!xmmsv_dict_get (infos, "comment", &dict_entry) || !xmmsv_get_string (dict_entry, &comment)) { comment = ""; } if (!xmmsv_dict_get (infos, "genre", &dict_entry) || !xmmsv_get_string (dict_entry, &genre)) { genre = "[Unknown Genre]"; } if (!xmmsv_dict_get (infos, "date", &dict_entry) || !xmmsv_get_string (dict_entry, &date)) { date = ""; } if (!xmmsv_dict_get (infos, "duration", &dict_entry) || !xmmsv_get_int (dict_entry, &info->duration)) { info->duration = 0; } if (!xmmsv_dict_get (infos, "bitrate", &dict_entry) || !xmmsv_get_int (dict_entry, &info->bitrate)) { info->bitrate = 0; } if (!xmmsv_dict_get (infos, "tracknr", &dict_entry) || !xmmsv_get_int (dict_entry, &info->tracknr)) { info->tracknr = 0; } info->artist = strdup(artist); info->album = strdup(album); info->title = decode_url(title); info->url = decode_url(url); info->comment = strdup(comment); info->genre = strdup(genre); info->date = strdup(date); xmmsv_unref(infos); }
int main(int argc, char *argv[]) { char buffer[5000]; char *val; char *buf, *buf2; long buflen; int i, j, n; char *p, *q, *tp; char valbuf[5000]; char ibuf[10]; int date_error = 0; // used for Prolog RC rc; TERM term; TF tf; char errmsg[1000]; TERM table; TERM row; TERM item; val = getenv("CONTENT_LENGTH"); if (val == NULL) { val = getenv("QUERY_STRING"); if (val == NULL) return; buf = (char *)malloc(strlen(val)+2); strcpy(buf, val); } else { // Add two for two nuls and malloc space buflen = atol(val)+2; buf = (char *)malloc(buflen); if (buf == NULL) return; fgets(buf, buflen-1, stdin); buf[buflen-1] = '\0'; // Add an extra nul } //strcpy(buffer, head); //strcat(buffer, buf); //strcat(buffer, foot); //fputs(buffer, outfile); p = buf; i = 0; while (*p != '\0') { // Grab the attribute (up to the equal = sign) q = strchr(p, '='); if (q == NULL) // Not the right format { free(buf); return; } *q = '\0'; tp = q + 1; decode_url(p); // get the attribute name strcpy(facts[i].name, p); // Grab the value (up to the & or nul) p = tp; q = strchr(p, '&'); if (q == NULL) // End of string { q = &buf[buflen-1]; tp = q; } else // More values left to process { *q = '\0'; tp = q + 1; } decode_url(p); if (strstr( facts[i].name, "Date" ) != 0 && strlen(p) > 0) { strcpy(facts[i].value, build_date(p)); if (strcmp(facts[i].value, "bad date") == 0) date_error = 1; } else { strcpy(facts[i].value, p); } i++; p = tp; } n = i; printf("Content-type: text/html\n\n<html>\n\n<body><h1>EVA India</h1>"); #ifdef TEST strcpy(buffer, "<table border='3' cellpadding='5'>"); for (i=0; i<n; i++) { strcat(buffer, "<tr>"); strcat(buffer, "<td>"); strcat(buffer, facts[i].name); strcat(buffer, "</td>"); strcat(buffer, "<td>"); strcat(buffer, facts[i].value); strcat(buffer, "</td>"); strcat(buffer, "</tr>"); } strcat(buffer, "</table>"); fputs(buffer, stdout); // was outfile #endif free(buf); if (date_error == 1) { printf("<p><font color=red>Please enter dates in YYYY-MM-DD format</font></p>"); goto main_error; } // Initialize the Prolog environment #ifdef TEST printf("<P><font color='green'>lsInit cureng= %p</font></p>", CurEng); #endif rc = lsInit(&CurEng, "arules"); if (rc != 0) { lsGetExceptMsg(CurEng, errmsg, 1024); printf("<p><font color='red'>Fatal Error #%d initializing Amzi! Logic Server:\n%s</font></p>", rc, errmsg); goto main_error; } #ifdef TEST printf("<P><font color='green'>lsInitLSX cureng= %p</font></p>", CurEng); #endif rc = lsInitLSX(CurEng, NULL); if (rc != 0) { printf("<p><font color='red'>Fatal Error #%d initializing LSXs</font></p>", rc); goto main_error; } // Load the .xpl file #ifdef TEST printf("<P><font color='green'>lsLoad cureng= %p</font></p>", CurEng); #endif rc = lsLoad(CurEng, "arules"); if (rc != 0) { lsGetExceptMsg(CurEng, errmsg, 1024); printf("<p><font color='red'>Fatal Error #%d loading Amzi! Logic Server XPL file:\n%s</font></p>", rc, errmsg); goto main_error; } #ifdef TEST printf("<P><font color='green'>lsExecStr version(X) cureng= %p</font></p>", CurEng); tf = lsExecStr(CurEng, &term, "version( ?x )"); if (tf != TRUE) { printf("<p><font color='red'>version failed"); goto main_error; } rc = lsGetArg(CurEng, term, 1, cSTR, buffer); printf("<P><font color='green'>version = %s, cureng= %p</font></p>", buffer, CurEng); #endif #ifdef TEST printf("<P><font color='green'>lsExecStr load('eva_india.axl') cureng= %p</font></p>", CurEng); #endif tf = lsExecStr(CurEng, &term, "load('eva_india.axl')"); if (tf != TRUE) { lsGetExceptMsg(CurEng, errmsg, 1024); printf("<p><font color='red'>Fatal Error #%d loading eva_india.axl file: %s</font></p>", rc, errmsg); goto main_error; } #ifdef TEST printf("<P><font color='green'>lsExecStr arxl... cureng= %p</font></p>", CurEng); #endif // Assert the basic data for the case tf = lsExecStr(CurEng, &term, "arxl_initialize_table(`CommonRules`, `data`)"); tf = lsExecStr(CurEng, &term, "arxl_initialize_table(`CommonRules`, `raw_vaccination`)"); j = 1; for (i=0; i<n; i++) { if (strstr(facts[i].name, "Vaccination") != 0 && strlen(facts[i].value) > 0 ) { strcpy(buffer, "arxl_add_to_table(`CommonRules`, `raw_vaccination`, "); sprintf(ibuf, "%d", j); strcat(buffer, ibuf); strcat(buffer, ", `Vaccination`, `"); strcat(buffer, facts[i].value); strcat(buffer, "`)"); //printf(buffer); tf = lsExecStr(CurEng, &term, buffer); i++; strcpy(buffer, "arxl_add_to_table(`CommonRules`, `raw_vaccination`, "); strcat(buffer, ibuf); strcat(buffer, ", `VaccinationDate`, `"); strcat(buffer, facts[i].value); strcat(buffer, "`)"); //printf(buffer); tf = lsExecStr(CurEng, &term, buffer); j++; } else { strcpy(buffer, "arxl_add_to_vector(`CommonRules`, `data`, `"); strcat(buffer, facts[i].name); strcat(buffer, "`, `"); strcat(buffer, facts[i].value); strcat(buffer, "`)"); //printf(buffer); tf = lsExecStr(CurEng, &term, buffer); } } // Start the Output printf("<h2><font color=red>Demonstration Only, Not for Medical use</font></h2>"); printf("<p><a href='/vaccinationanalysis/index.html'>EVA</a> is a tool for the encoding, verification, testing, and deployment of vaccination knowledge.</p>"); printf("<p><a href='/vaccinationanalysis/eva_user_documentation.html'>Explanation of Results</a></p>"); // Get the age tf = lsExecStr(CurEng, &term, "arxl_query('EVA', false, `FIND age`, ?x)"); rc = lsGetArg(CurEng, term, 4, cSTR, buffer); printf("<h3>age = %s</h3>", buffer); // Get the history tf = lsExecStr(CurEng, &term, "arxl_query('EVA', false, `FIND history`, ?x)"); rc = lsGetArg(CurEng, term, 4, cTERM, &table); #ifdef TEST rc = lsTermToStr(CurEng, table, buffer, 500); if (strcmp(buffer, "[]") == 0) table = NULL; printf("<P><font color='green'>history = %s</font></p>", buffer); #endif printf("<h2>Retrospective Analysis</h2>"); printf("<p><font color=green>The comment indicates whether a previously given vaccination was:</p>"); printf("<ul><li>too early,</li><li>early but OK,</li><li>during the optimal interval,</li><li>past the optimal interval,</li>"); printf("<li>a violation of minimum intervals between doses, or</li><li>an invalid spacing between live virus vaccinations.</li></ul>"); printf("<p>A dose with an X was not given at the correct time and does not count as a valid dose. </font></p>"); printf("<table border='3' cellspacing='2' cellpadding='5'>"); printf("<tr>"); printf("<th>Vaccination</th>"); printf("<th>Dose</th>"); printf("<th>Date Given</th>"); printf("<th>Status</th>"); printf("<th>Comment</th>"); printf("<th>Age Given</th>"); printf("</tr>"); i = 0; while (table != 0 && i < 50) { lsGetHead(CurEng, table, cTERM, &row); j = 0; printf("<tr>"); while (row != 0 && j < 10) { lsGetHead(CurEng, row, cTERM, &item); lsTermToStr(CurEng, item, buffer, 80); printf("<td>%s</td>", buffer); row = lsGetTail(CurEng, row); j++; } table = lsGetTail(CurEng, table); printf("</tr>"); i++; } printf("</table>"); // Get the plan tf = lsExecStr(CurEng, &term, "arxl_query('EVA', false, `FIND plans`, ?x)"); rc = lsGetArg(CurEng, term, 4, cTERM, &table); #ifdef TEST rc = lsTermToStr(CurEng, table, buffer, 500); printf("<P><font color='green'>plans = %s</font></p>", buffer); #endif printf("<h2>Future Plan</h2>"); printf("<p><font color=green>The status indicates what should happen next for a given vaccine as of the date the report is given. The results are sorted with most critical future vaccinations first. Possible values are:</p>"); printf("<ul>"); printf("<li>not applicable - for example doctor deferred or HPV for males.</li>"); printf("<li>complete - the full series has been given.</li>"); printf("<li>current - the vaccinations are up-to-date, nothing to do today.</li>"); printf("<li>eligible - it's after the minimum date, so it could be given today, but it's before the optimal range.</li>"); printf("<li>due - it's in the optimal range.</li>"); printf("<li>past due - it's past the optimal range.</li>"); printf("</ul>"); printf("<p>The three dates indicate the earliest date for the next dose, and the beginning and end of the optimal range. "); printf("Note that the <a href='http://www.iapindia.org/immunisation/immunisation-schedule'>IAP ITT</a> documents do not specify a minimum age or interval, so for this demonstration the earliest age and the optimal start are the same."); printf(" The document does not specify the acceptable range either, so either one week or one month was assumed."); printf("</font></p>"); printf("<table border='3' cellspacing='2' cellpadding='5'>"); printf("<tr>"); printf("<th>Vaccination</th>"); printf("<th>Status</th>"); printf("<th>Dose</th>"); printf("<th>Earliest</th>"); printf("<th>Optimal Start</th>"); printf("<th>Optimal End</th>"); printf("<th>Citation</th>"); printf("<th>Comment</th>"); printf("</tr>"); i = 0; while (table != 0 && i < 50) { lsGetHead(CurEng, table, cTERM, &row); j = 0; printf("<tr>"); while (row != 0 && j < 10) { lsGetHead(CurEng, row, cTERM, &item); lsTermToStr(CurEng, item, buffer, 80); printf("<td>%s</td>", buffer); row = lsGetTail(CurEng, row); j++; } table = lsGetTail(CurEng, table); printf("</tr>"); i++; } printf("</table>"); main_error: rc = lsClose(CurEng); printf("<p>Use the browser back button to enter another.</p></body></html>"); return(TRUE); }
static int parse_format (GLogItem * glog, const char *fmt, const char *date_format, char *str) { const char *p; double serve_secs; int special = 0; struct tm tm; unsigned long long bandw, serve_time; if (str == NULL || *str == '\0') return 1; memset (&tm, 0, sizeof (tm)); /* iterate over the log format */ for (p = fmt; *p; p++) { if (*p == '%') { special++; continue; } if (special && *p != '\0') { char *pch, *sEnd, *bEnd, *tkn = NULL, *end = NULL; errno = 0; bandw = 0; serve_time = 0; serve_secs = 0; switch (*p) { /* date */ case 'd': if (glog->date) return 1; /* parse date format including dates containing spaces, * i.e., syslog date format (Jul 15 20:10:56) */ tkn = parse_string (&str, p[1], count_matches (date_format, ' ') + 1); if (tkn == NULL) return 1; end = strptime (tkn, date_format, &tm); if (end == NULL || *end != '\0') { free (tkn); return 1; } glog->date = tkn; break; /* remote hostname (IP only) */ case 'h': if (glog->host) return 1; tkn = parse_string (&str, p[1], 1); if (tkn == NULL) return 1; if (invalid_ipaddr (tkn)) { free (tkn); return 1; } glog->host = tkn; break; /* request method */ case 'm': if (glog->method) return 1; tkn = parse_string (&str, p[1], 1); if (tkn == NULL) return 1; if (!extract_method (tkn)) { free (tkn); return 1; } glog->method = tkn; break; /* request not including method or protocol */ case 'U': if (glog->req) return 1; tkn = parse_string (&str, p[1], 1); if (tkn == NULL || *tkn == '\0') return 1; if ((glog->req = decode_url (tkn)) == NULL) return 1; free (tkn); break; /* request protocol */ case 'H': if (glog->protocol) return 1; tkn = parse_string (&str, p[1], 1); if (tkn == NULL) return 1; if (invalid_protocol (tkn)) { free (tkn); return 1; } glog->protocol = tkn; break; /* request, including method + protocol */ case 'r': if (glog->req) return 1; tkn = parse_string (&str, p[1], 1); if (tkn == NULL) return 1; glog->req = parse_req (tkn, &glog->method, &glog->protocol); free (tkn); break; /* Status Code */ case 's': if (glog->status) return 1; tkn = parse_string (&str, p[1], 1); if (tkn == NULL) return 1; strtol (tkn, &sEnd, 10); if (tkn == sEnd || *sEnd != '\0' || errno == ERANGE) { free (tkn); return 1; } glog->status = tkn; break; /* size of response in bytes - excluding HTTP headers */ case 'b': if (glog->resp_size) return 1; tkn = parse_string (&str, p[1], 1); if (tkn == NULL) return 1; bandw = strtol (tkn, &bEnd, 10); if (tkn == bEnd || *bEnd != '\0' || errno == ERANGE) bandw = 0; glog->resp_size = bandw; conf.bandwidth = 1; free (tkn); break; /* referrer */ case 'R': if (glog->ref) return 1; tkn = parse_string (&str, p[1], 1); if (tkn == NULL) tkn = alloc_string ("-"); if (tkn != NULL && *tkn == '\0') { free (tkn); tkn = alloc_string ("-"); } if (strcmp (tkn, "-") != 0) extract_referer_site (tkn, glog->site); glog->ref = tkn; break; /* user agent */ case 'u': if (glog->agent) return 1; tkn = parse_string (&str, p[1], 1); if (tkn != NULL && *tkn != '\0') { /* Make sure the user agent is decoded (i.e.: CloudFront) * and replace all '+' with ' ' (i.e.: w3c) */ glog->agent = char_replace (decode_url (tkn), '+', ' '); free (tkn); break; } else if (tkn != NULL && *tkn == '\0') { free (tkn); tkn = alloc_string ("-"); } /* must be null */ else { tkn = alloc_string ("-"); } glog->agent = tkn; break; /* time taken to serve the request, in seconds */ case 'T': if (glog->serve_time) return 1; /* ignore seconds if we have microseconds */ if (strstr (fmt, "%D") != NULL) break; tkn = parse_string (&str, p[1], 1); if (tkn == NULL) return 1; if (strchr (tkn, '.') != NULL) serve_secs = strtod (tkn, &bEnd); else serve_secs = strtoull (tkn, &bEnd, 10); if (tkn == bEnd || *bEnd != '\0' || errno == ERANGE) serve_secs = 0; /* convert it to microseconds */ if (serve_secs > 0) glog->serve_time = serve_secs * SECS; else glog->serve_time = 0; conf.serve_usecs = 1; free (tkn); break; /* time taken to serve the request, in microseconds */ case 'D': if (glog->serve_time) return 1; tkn = parse_string (&str, p[1], 1); if (tkn == NULL) return 1; serve_time = strtoull (tkn, &bEnd, 10); if (tkn == bEnd || *bEnd != '\0' || errno == ERANGE) serve_time = 0; glog->serve_time = serve_time; conf.serve_usecs = 1; free (tkn); break; /* everything else skip it */ default: if ((pch = strchr (str, p[1])) != NULL) str += pch - str; } if ((str == NULL) || (*str == '\0')) return 0; special = 0; } else if (special && isspace (p[0])) { return 1; } else str++; } return 0; }
static void get_track(xmlNodePtr root, GList **list) { SongInfo *song; gchar *url; song = song_info_new(); if (song == NULL) return ; do { GList *p = *list; gboolean song_exists = FALSE; song->song_id = (gchar *)xml_first_child_content(root, BAD_CAST "song_id"); if (song->song_id == NULL) break; for ( ; p != NULL; p = p->next) { SongInfo *si = (SongInfo *)p->data; if (g_strcmp0(si->song_id, song->song_id) == 0) { song_exists = TRUE; break; } } if (song_exists) break; song->song_name = (gchar *)xml_first_child_content(root, BAD_CAST "title"); song->album_id = (gchar *)xml_first_child_content(root, BAD_CAST "album_id"); song->album_name = (gchar *)xml_first_child_content(root, BAD_CAST "album_name"); song->artist_id = (gchar *)xml_first_child_content(root, BAD_CAST "artist_id"); song->artist_name = (gchar *)xml_first_child_content(root, BAD_CAST "artist"); song->album_cover = (gchar *)xml_first_child_content(root, BAD_CAST "pic"); url = (gchar *)xml_first_child_content(root, BAD_CAST "location"); if (song->song_name == NULL) song->song_name = (gchar *)xml_first_child_content(root, BAD_CAST "song_name"); if (song->artist_name == NULL) song->artist_name = (gchar *)xml_first_child_content(root, BAD_CAST "artist_name"); if (song->album_cover == NULL) song->album_cover = (gchar *)xml_first_child_content(root, BAD_CAST "album_cover"); if (url == NULL) break; song->location = decode_url(url); g_free(url); song->grade = (gchar *)xml_first_child_content(root, BAD_CAST "grade"); *list = g_list_append(*list, song); return ; } while(0); song_info_free(song); }
bool DrawApp::OnInit() { /* Read params from szarp.cfg. */ #if wxUSE_UNICODE libpar_read_cmdline_w(&argc, argv); #else libpar_read_cmdline(&argc, argv); #endif #if BOOST_FILESYSTEM_VERSION == 3 boost::filesystem::wpath::imbue(std::locale("C")); #else boost::filesystem::wpath_traits::imbue(std::locale("C")); #endif if (!DrawGLApp::OnInit()) return false; SetProgName(_T("Draw 3")); //signal(SIGINT, INThandler); if (m_just_print_version) { std::cout << SZARP_VERSION << std::endl; return false; } m_server = NULL; m_db_queue = NULL; m_executor = NULL; m_remarks_handler = NULL; #ifdef __WXGTK__ libpar_init(); char *base = NULL; if (m_base == wxEmptyString) { base = libpar_getpar("", "config_prefix", 1); m_base = SC::L2S(base); free(base); } { if (m_base_type != IKS_BASE) { char *iks_server = libpar_getpar("draw3", "iks_server", 0); if (iks_server) { m_iks_server = SC::L2S(iks_server); m_base_type = IKS_BASE; free(iks_server); } char *iks_port = libpar_getpar("draw3", "iks_server_port", 0); if (iks_port) { m_iks_port = SC::L2S(iks_port); free(iks_port); } } } m_probers_from_szarp_cfg = get_probers_addresses(); #endif #ifdef MINGW32 WORD wVersionRequested = MAKEWORD(2, 2); WSADATA wsaData; WSAStartup(wVersionRequested, &wsaData); #endif /* Set logging to stderr. */ wxLog *logger = new wxLogStderr(); //wxLog *logger = new wxLogGui(); wxLog::SetActiveTarget(logger); m_instance = new szSingleInstanceChecker(_T(".szarp_m_instance_lock"), wxEmptyString, _T("draw3")); if (m_instance->IsAnotherRunning()) { if (!m_url.IsEmpty()) { if (m_url_open_in_existing) SendToRunningInstance(_T("START_URL"), m_url.c_str()); else SendToRunningInstance(_T("START_URL_EXISTING"), m_url.c_str()); } else if (!m_base.IsEmpty()) { SendToRunningInstance(_T("START_BASE"), m_base.c_str()); } else { wxLogError(_T("base not given")); return false; } return false; } InitGL(); SplashScreen *splash = NULL; wxBitmap bitmap; // this loads draw64_xpm under Linux, or draw64 icon resource under Windows szFrame::setDefaultIcon(wxICON(draw64)); wxString splashimage = GetSzarpDir(); #ifndef MINGW32 splashimage += _T("resources/wx/images/szarp-logo.png"); #else splashimage += _T("resources\\wx\\images\\szarp-logo.png"); #endif #if wxUSE_LIBPNG /* Activate PNG image handler. */ wxImage::AddHandler( new wxPNGHandler ); #endif if (bitmap.LoadFile(splashimage, wxBITMAP_TYPE_PNG)) splash = new SplashScreen(&bitmap); else splash = new SplashScreen(); splash->Show(true); splash->PushStatusText(_("Setting locale...")); /* Set locale. */ this->InitializeLocale(_T("draw3"), locale); splash->PushStatusText(_("Reading params from szarp.cfg...")); wxString _lang = wxConfig::Get()->Read(_T("LANGUAGE"), AUTO_LANGUAGE); if (_lang == AUTO_LANGUAGE) _lang = DEFAULT_LANGUAGE; splash->PushStatusText(_("Initializing IPKContainer...")); IPKContainer::Init(GetSzarpDataDir().c_str(), GetSzarpDir().c_str(), _lang.c_str()); m_cfg_mgr = new ConfigManager(GetSzarpDataDir(), IPKContainer::GetObject()); m_cfg_mgr->SetSplashScreen(splash); splash->PushStatusText(_("Initializing szbase...")); splash->PushStatusText(_("Initializing XML Resources...")); InitXmlResource(); splash->PushStatusText(_("Starting database query mechanism...")); m_db_queue = new DatabaseQueryQueue(); m_dbmgr = new DatabaseManager(m_db_queue, m_cfg_mgr); m_db_queue->SetDatabaseManager(m_dbmgr); m_dbmgr->SetProbersAddresses(GetProbersAddresses()); Draw3Base* draw_base; switch (m_base_type) { case SZBASE_BASE: draw_base = new SzbaseBase(m_dbmgr, GetSzarpDataDir().c_str(), &ConfigurationFileChangeHandler::handle, wxConfig::Get()->Read(_T("SZBUFER_IN_MEMORY_CACHE"), 0L)); break; case SZ4_BASE: draw_base = new Sz4Base(m_dbmgr, GetSzarpDataDir().c_str(), IPKContainer::GetObject()); break; case IKS_BASE: draw_base = new Sz4ApiBase(m_dbmgr, m_iks_server.c_str(), m_iks_port.c_str(), IPKContainer::GetObject()); break; } m_executor = new QueryExecutor(m_db_queue, m_dbmgr, draw_base); m_executor->Create(); m_executor->SetPriority((WXTHREAD_MAX_PRIORITY + WXTHREAD_DEFAULT_PRIORITY) / 2); m_executor->Run(); m_cfg_mgr->SetDatabaseManager(m_dbmgr); ConfigurationFileChangeHandler::database_manager = m_dbmgr; /* default config */ wxString defid; DrawsSets *config = NULL; splash->PushStatusText(_("Loading configuration...")); /* init activity logger with base name as server name. This assumes that * server has written basename to /etc/hosts on linux machines and probably * doesn't work on windows. */ UDPLogger::SetAppName( "draw3" ); UDPLogger::SetAddress( (const char*)m_base.mb_str(wxConvUTF8) ); UDPLogger::SetPort ( "7777" ); UDPLogger::LogEvent ( "drawapp:start" ); wxString prefix, window; PeriodType pt = PERIOD_T_YEAR; time_t time = -1; int selected_draw = 0; if (!m_url.IsEmpty()) { if (!decode_url(m_url, prefix, window, pt, time, selected_draw)) { wxLogError(_T("Invalid URL")); StopThreads(); return FALSE; } } else if (!m_base.IsEmpty()) { if ((config = m_cfg_mgr->LoadConfig(m_base,std::wstring(),m_show_logparams)) == NULL) { wxLogError(_("Error occurred while loading default configuration. Check your szarp.cfg file.")); StopThreads(); return FALSE; } prefix = m_base; } else { wxLogError(_("Missing starting base specification.")); StopThreads(); return FALSE; } #ifndef MINGW32 libpar_done(); #endif m_help = new szHelpController; #ifndef MINGW32 m_help->AddBook(wxGetApp().GetSzarpDir() + L"/resources/documentation/new/draw3/html/draw3.hhp"); #else m_help->AddBook(wxGetApp().GetSzarpDir() + L"\\resources\\documentation\\new\\draw3\\html\\draw3.hhp"); #endif szHelpControllerHelpProvider* provider = new szHelpControllerHelpProvider; wxHelpProvider::Set(provider); provider->SetHelpController(m_help); splash->PushStatusText(_("Initizalizing remarks...")); m_remarks_handler = new RemarksHandler(m_cfg_mgr); m_remarks_handler->Start(); splash->PushStatusText(_("Creating Frame Manager...")); VersionChecker* version_checker = new VersionChecker(argv[0]); version_checker->Start(); FrameManager *fm = new FrameManager(m_dbmgr, m_cfg_mgr, m_remarks_handler); /*@michal */ if (!fm->CreateFrame(prefix, window, pt, time, wxSize(width, height), wxPoint(x, y), selected_draw, m_url.IsEmpty(), m_full_screen)) { StopThreads(); wxLogError(_T("Unable to load base: %s"), prefix.c_str()); return FALSE; } StartInstanceServer(fm, m_cfg_mgr); wxToolTip::SetDelay(1000); SetAppName(_T("SZARPDRAW3")); splash->Destroy(); m_cfg_mgr->ResetSplashScreen(); #ifndef NO_GSTREAMER if (!gst_init_check(NULL, NULL, NULL)) return 1; #endif return TRUE; }
static char * parse_req (char *line, GLogItem * glog) { const char *lookfor = NULL; char *req, *request, *req_l = NULL, *req_r = NULL; char *method = NULL, *protocol = NULL; ptrdiff_t req_len; if ((lookfor = "OPTIONS ", req_l = strstr (line, lookfor)) != NULL || (lookfor = "GET ", req_l = strstr (line, lookfor)) != NULL || (lookfor = "HEAD ", req_l = strstr (line, lookfor)) != NULL || (lookfor = "POST ", req_l = strstr (line, lookfor)) != NULL || (lookfor = "PUT ", req_l = strstr (line, lookfor)) != NULL || (lookfor = "DELETE ", req_l = strstr (line, lookfor)) != NULL || (lookfor = "TRACE ", req_l = strstr (line, lookfor)) != NULL || (lookfor = "CONNECT ", req_l = strstr (line, lookfor)) != NULL || (lookfor = "PATCH", req_l = strstr (line, lookfor)) != NULL || (lookfor = "options ", req_l = strstr (line, lookfor)) != NULL || (lookfor = "get ", req_l = strstr (line, lookfor)) != NULL || (lookfor = "head ", req_l = strstr (line, lookfor)) != NULL || (lookfor = "post ", req_l = strstr (line, lookfor)) != NULL || (lookfor = "put ", req_l = strstr (line, lookfor)) != NULL || (lookfor = "delete ", req_l = strstr (line, lookfor)) != NULL || (lookfor = "trace ", req_l = strstr (line, lookfor)) != NULL || (lookfor = "connect ", req_l = strstr (line, lookfor)) != NULL || (lookfor = "patch", req_l = strstr (line, lookfor)) != NULL) { /* didn't find it - weird */ if ((req_r = strstr (line, " HTTP/1.0")) == NULL && (req_r = strstr (line, " HTTP/1.1")) == NULL) return alloc_string ("-"); req_l += strlen (lookfor); req_len = req_r - req_l; /* make sure we don't have some weird requests */ if (req_len <= 0) return alloc_string ("-"); req = xmalloc (req_len + 1); strncpy (req, req_l, req_len); req[req_len] = 0; if (conf.append_method) { method = trim_str (xstrdup (lookfor)); str_to_upper (method); glog->method = method; } if (conf.append_protocol) { protocol = xstrdup (++req_r); str_to_upper (protocol); glog->protocol = protocol; } } else req = alloc_string (line); request = decode_url (req); if (request != NULL && *request != '\0') { free (req); return request; } return req; }
int EmbedOcspLookup(void* ctx, const char* url, int urlSz, byte* ocspReqBuf, int ocspReqSz, byte** ocspRespBuf) { char domainName[80], path[80]; int port, httpBufSz, sfd = -1; int ocspRespSz = 0; byte* httpBuf = NULL; (void)ctx; if (ocspReqBuf == NULL || ocspReqSz == 0) { CYASSL_MSG("OCSP request is required for lookup"); return -1; } if (ocspRespBuf == NULL) { CYASSL_MSG("Cannot save OCSP response"); return -1; } if (decode_url(url, urlSz, domainName, path, &port) < 0) { CYASSL_MSG("Unable to decode OCSP URL"); return -1; } /* Note, the library uses the EmbedOcspRespFree() callback to * free this buffer. */ httpBufSz = SCRATCH_BUFFER_SIZE; httpBuf = (byte*)XMALLOC(httpBufSz, NULL, DYNAMIC_TYPE_IN_BUFFER); if (httpBuf == NULL) { CYASSL_MSG("Unable to create OCSP response buffer"); return -1; } httpBufSz = build_http_request(domainName, path, ocspReqSz, httpBuf, httpBufSz); if ((tcp_connect(&sfd, domainName, port) == 0) && (sfd > 0)) { int written; written = (int)send(sfd, httpBuf, httpBufSz, 0); if (written == httpBufSz) { written = (int)send(sfd, ocspReqBuf, ocspReqSz, 0); if (written == ocspReqSz) { ocspRespSz = process_http_response(sfd, ocspRespBuf, httpBuf, SCRATCH_BUFFER_SIZE); } } close(sfd); if (ocspRespSz == 0) { CYASSL_MSG("OCSP response was not OK, no OCSP response"); XFREE(httpBuf, NULL, DYNAMIC_TYPE_IN_BUFFER); return -1; } } else { CYASSL_MSG("OCSP Responder connection failed"); close(sfd); XFREE(httpBuf, NULL, DYNAMIC_TYPE_IN_BUFFER); return -1; } XFREE(httpBuf, NULL, DYNAMIC_TYPE_IN_BUFFER); return ocspRespSz; }