void uri_free(UriUriA *uri) { if (uri) { uriFreeUriMembersA(uri); m_free(uri); } }
char *extract_relative_url(const char *src_filename, const char *base_filename) { UriUriA *abs_src_uri, *abs_base_uri, dst; char *dst_filename = NULL; if (!src_filename || !base_filename) return NULL; abs_src_uri = filename2absolute_uri(src_filename); abs_base_uri = filename2absolute_uri(base_filename); if (!abs_src_uri || !abs_base_uri) { uri_free(abs_src_uri); uri_free(abs_base_uri); return NULL; } if (uriRemoveBaseUriA(&dst, abs_src_uri, abs_base_uri, URI_FALSE) != URI_SUCCESS) goto exit; dst_filename = uri2string(&dst); exit: uri_free(abs_src_uri); uri_free(abs_base_uri); uriFreeUriMembersA(&dst); return dst_filename; }
void HttpHandler::parseURL(const char* request_uri) { this->parameter = new std::unordered_map<std::string, std::string>(); UriParserStateA state; UriUriA uri; state.uri = &uri; if (request_uri == nullptr) { return; } if (uriParseUriA(&state, request_uri) != URI_SUCCESS) { uriFreeUriMembersA(&uri); return; } UriQueryListA* queryList; int itemCount; if (uriDissectQueryMallocA(&queryList, &itemCount, uri.query.first, uri.query.afterLast) == URI_SUCCESS) { auto& current = queryList; do { if (queryList->value != nullptr) { auto buffer = new char[std::strlen(queryList->value) + 1]; std::strcpy(buffer, (char*) queryList->value); uriUnescapeInPlaceExA(buffer, false, URI_BR_DONT_TOUCH); (*this->parameter)[queryList->key] = buffer; delete[] buffer; } else { (*this->parameter)[queryList->key] = std::string(""); } current = queryList->next; } while (current != nullptr); uriFreeQueryListA(queryList); uriFreeUriMembersA(&uri); return; } }
void parsed_uri_free(parsed_uri *u) /*===============================*/ { if (u) { uriFreeUriMembersA(&u->uri) ; free(u) ; } }
int parse_uri(char *uri_str, UriUriA *uri) { UriParserStateA state; state.uri = uri; if (uriParseUriA(&state, uri_str) != URI_SUCCESS) { /* Failure */ uriFreeUriMembersA(uri); return -1; } return 0; }
Crawler::Website::Website ( const std::string & website ) { UriParserStateA state ; UriUriA parsedURI ; state.uri = & parsedURI ; if ( uriParseUriA ( & state , website.c_str ( ) ) == URI_SUCCESS ) { this->setScheme ( getString ( parsedURI.scheme ) ) ; std::string userInfo = getString ( parsedURI.userInfo ) ; std::string hostText = getString ( parsedURI.hostText ) ; std::string portText = getString ( parsedURI.portText ) ; std::string authority = ! userInfo.empty ( ) ? userInfo + "@" : "" ; authority += hostText + ( ! portText.empty ( ) ? ":" + portText : "" ) ; this->setAuthority ( authority ) ; } uriFreeUriMembersA ( & parsedURI ) ; }
static void parse_url_string(const char *s, struct PP_URLComponents_Dev *components) { UriParserStateA ups; UriUriA uri; ups.uri = &uri; if (uriParseUriA(&ups, s) != URI_SUCCESS) { uriFreeUriMembersA(&uri); trace_warning("failure at %s\n", __func__); return; } components->scheme.begin = 0; components->scheme.len = -1; components->username.begin = 0; components->username.len = -1; components->password.begin = 0; components->password.len = -1; components->host.begin = 0; components->host.len = -1; components->port.begin = 0; components->port.len = -1; components->path.begin = 0; components->path.len = -1; components->query.begin = 0; components->query.len = -1; components->ref.begin = 0; components->ref.len = -1; #define C_PARSE(c1, c2) \ components->c1.begin = uri.c2.first ? uri.c2.first - s + 1 : 0; \ components->c1.len = uri.c2.first ? uri.c2.afterLast - uri.c2.first : -1; C_PARSE(scheme, scheme); C_PARSE(username, userInfo); C_PARSE(password, userInfo); if (components->username.begin > 0) { const char *first = s + components->username.begin - 1; const char *last = first + components->username.len; const char *ptr = first; while (ptr < last) { if (*ptr == ':') { components->username.len = ptr - first; components->password.begin += ptr - first + 1; components->password.len -= ptr - first + 1; if (components->username.len == 0) { components->username.begin = 0; components->username.len = -1; } if (components->password.len == 0) { components->password.begin = 0; components->password.len = -1; } break; } ptr ++; } } C_PARSE(host, hostText); C_PARSE(port, portText); components->path.begin = uri.pathHead ? uri.pathHead->text.first - s + 1 : 0; components->path.len = uri.pathHead ? uri.pathTail->text.afterLast - uri.pathHead->text.first : -1; if (components->path.begin > 0) { components->path.begin -= 1; components->path.len += 1; } C_PARSE(query, query); C_PARSE(ref, fragment); #undef C_PARSE uriFreeUriMembersA(&uri); }
int urlparse ( const char *str, url_t *url ) { UriParserStateA state; UriPathSegmentA *path; UriUriA uri; char *s, buf[256]; if (str == NULL || url == NULL) return -1; urlreset(url); /* Parse */ state.uri = &uri; if (uriParseUriA(&state, str) != URI_SUCCESS) { uriFreeUriMembersA(&uri); return -1; } /* Store raw */ url->raw = strdup(str); /* Copy */ #define uri_copy(y, x)\ if (x.first) {\ size_t len = x.afterLast - x.first;\ y = strndup(x.first, len);\ } #define uri_copy_static(y, x)\ if (x.first) {\ size_t len = x.afterLast - x.first;\ strncpy(y, x.first, len);\ y[len] = '\0';\ } else {\ y[0] = '\0';\ } uri_copy(url->scheme, uri.scheme); uri_copy(url->host, uri.hostText); uri_copy(url->user, uri.userInfo); uri_copy(url->query, uri.query); uri_copy(url->frag, uri.fragment); uri_copy_static(buf, uri.portText); if (*buf) url->port = atoi(buf); else url->port = 0; path = uri.pathHead; while (path) { uri_copy_static(buf, path->text); if (url->path) url->path = realloc(url->path, strlen(url->path) + strlen(buf) + 2); else url->path = calloc(1, strlen(buf) + 2); strcat(url->path, "/"); strcat(url->path, buf); path = path->next; } // TODO: query/fragment /* Split user/pass */ if (url->user) { s = strstr(url->user, ":"); if (s) { url->pass = strdup(s + 1); *s = 0; } } /* Cleanup */ uriFreeUriMembersA(&uri); return 0; }
int session_config_init(char *base, char *ca_cert, char *client_cert, bool grace) { size_t base_len; UriParserStateA state; UriUriA uri; char *firstdot = NULL; assert(base); if (curl_global_init(CURL_GLOBAL_ALL)) { log_print(LOG_CRIT, SECTION_SESSION_DEFAULT, "session_config_init: Failed to initialize libcurl."); return -1; } config_grace = grace; // Ensure the base URL has no trailing slash. base_len = strlen(base); base_url = strdup(base); if (base[base_len - 1] == '/') base_url[base_len - 1] = '\0'; if (ca_cert != NULL) ca_certificate = strdup(ca_cert); if (client_cert != NULL) { client_certificate = strdup(client_cert); // Repair p12 to point to pem for now. if (strcmp(client_certificate + strlen(client_certificate) - 4, ".p12") == 0) { log_print(LOG_CRIT, SECTION_SESSION_DEFAULT, "session_config_init: Remapping deprecated certificate path: %s", client_certificate); strncpy(client_certificate + strlen(client_certificate) - 4, ".pem", 4); } log_print(LOG_INFO, SECTION_SESSION_DEFAULT, "session_config_init: Using client certificate at path: %s", client_certificate); } state.uri = &uri; if (uriParseUriA(&state, base) != URI_SUCCESS) { /* Failure */ log_print(LOG_CRIT, SECTION_SESSION_DEFAULT, "session_config_init: error on uriParse on: %s", base); uriFreeUriMembersA(&uri); return -1; } filesystem_domain = strndup(uri.hostText.first, uri.hostText.afterLast - uri.hostText.first); filesystem_port = strndup(uri.portText.first, uri.portText.afterLast - uri.portText.first); firstdot = strchr(uri.hostText.first, '.'); if (firstdot) { filesystem_cluster = strndup(uri.hostText.first, firstdot - uri.hostText.first); } else { /* Failure */ log_print(LOG_CRIT, SECTION_SESSION_DEFAULT, "session_config_init: error on uriParse finding cluster name: %s", base); asprintf(&filesystem_cluster, "unknown"); } uriFreeUriMembersA(&uri); log_print(LOG_DEBUG, SECTION_SESSION_DEFAULT, "session_config_init: host (%s) :: port (%s) :: cluster (%s)", filesystem_domain, filesystem_port, filesystem_cluster); return 0; }
/* http://www.gnu.org/s/libc/manual/html_node/Getopt.html */ int parse_args(int argc, char **argv) { UriParserStateA uristate; int opt, index; int rc = EX_OK; opterr = 0; while ((opt = getopt(argc, argv, "p:vVh")) != -1) switch (opt) { case 'p': port = optarg; break; case '?': switch (optopt) { case 'p': dprintf(STDERR_FILENO, "option -%c requires an argument\n", optopt); break; default: if (isprint(optopt)) dprintf(STDERR_FILENO, "unknown option `-%c'\n", optopt); else dprintf(STDERR_FILENO, "unknown option character `\\x%x'\n", optopt); } rc = -EX_USAGE; goto exit; case 'v': verbose++; break; case 'V': dprintf(STDOUT_FILENO, "%s %s\n\n", basename(argv[0]), VERSION); dprintf(STDOUT_FILENO, "Copyright (C) 2013 Alexander Clouter <*****@*****.**>\n" "License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.\n" "This is free software: you are free to change and redistribute it.\n" "There is NO WARRANTY, to the extent permitted by law.\n"); rc = -EX_SOFTWARE; goto exit; case 'h': default: dprintf(STDOUT_FILENO, "Usage: %s [options] server [uri ...]\n", basename(argv[0])); dprintf(STDOUT_FILENO, "Multipath UDP Transport over TCP\n" "\n" " -p port to function over (default: " SOCKTOPUS_PORT ")\n" "\n" " -v increase verbosity\n" "\n" " -h display this help and exit\n" " -V print version information and exit\n"); rc = -EX_SOFTWARE; goto exit; } if (GETOPT_NUM_ARGS == 0) { dprintf(STDERR_FILENO, "missing server\n"); rc = -EX_SOFTWARE; goto exit; } else if (GETOPT_NUM_ARGS == 1) dprintf(STDOUT_FILENO, "WARNING: no URI nodes specified\n"); /* argv array makes up list of URIs */ channel = calloc(GETOPT_NUM_ARGS, sizeof(struct channel)); if (!channel) { PERROR("calloc"); rc = -EX_OSERR; goto exit; } for (index = optind; index < argc; index++) { char *scheme; int urc, i = index - optind; long int port; uristate.uri = &channel[i].uri; urc = uriParseUriA(&uristate, argv[index]); if (urc != URI_SUCCESS) { PERROR("uriParseUriA[%d]", urc); rc = -EX_USAGE; uriFreeUriMembersA(uristate.uri); goto exit; } scheme = uripart(&uristate.uri->scheme); if (!scheme) { dprintf(STDERR_FILENO, "missing scheme: %s\n", argv[index]); rc = -EX_USAGE; goto exit; } if (!strcmp(scheme, "tcp")) { channel[i].scheme = SCHEME_TCP; channel[i].port = uriport(&uristate.uri->portText, SOCKTOPUS_PORT); } else if (!strcmp(scheme, "http")) { channel[i].scheme = SCHEME_HTTP; channel[i].port = uriport(&uristate.uri->portText, DEFAULT_PORT_HTTP); } else if (!strcmp(scheme, "socks")) { channel[i].scheme = SCHEME_SOCKS; channel[i].port = uriport(&uristate.uri->portText, DEFAULT_PORT_SOCKS); } else if (!strcmp(scheme, "socks4")) { channel[i].scheme = SCHEME_SOCKS4; channel[i].port = uriport(&uristate.uri->portText, DEFAULT_PORT_SOCKS); } else { dprintf(STDERR_FILENO, "unsupported scheme: %s\n", argv[index]); rc = -EX_USAGE; goto exit; } free(scheme); assert(channel[i].scheme != SCHEME_INVALID); channel[i].host = uripart(&uristate.uri->hostText); if (!channel[i].host) { dprintf(STDERR_FILENO, "bad host: %s\n", argv[index]); rc = -EX_USAGE; goto exit; } errno = 0; port = strtol(channel[i].port, NULL, 10); if (port < 1 || port > 65535 || errno) { dprintf(STDERR_FILENO, "bad port: %s\n", argv[optind]); rc = -EX_USAGE; goto exit; } channel[i].fd = FD_INVALID; } if (channel[0].scheme != SCHEME_TCP) { dprintf(STDERR_FILENO, "endpoint must be TCP: %s\n", argv[optind]); rc = -EX_USAGE; goto exit; } exit: return rc; }
Datum parse_uri(PG_FUNCTION_ARGS) { TupleDesc tupledesc; AttInMetadata *attinmeta; text* input=PG_GETARG_TEXT_P(0); /* Function is defined STRICT in SQL, so no NULL check is needed. */ bool normalize=PG_GETARG_BOOL(1); bool parse_query=PG_GETARG_BOOL(2); char* inp=palloc((1+VARSIZE(input)-VARHDRSZ)*sizeof(char)); if (!inp) { ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("Memory allocation failed."))); PG_RETURN_NULL(); } memcpy(inp,VARDATA(input),VARSIZE(input)-VARHDRSZ); inp[VARSIZE(input)-VARHDRSZ]='\0'; /* Function internals start here */ int i; int memctr; UriPathSegmentA* pathseg; int quit; char* writehere; UriParserStateA state; UriUriA uri; state.uri = &uri; if (uriParseUriA(&state, inp) != URI_SUCCESS) { uriFreeUriMembersA(&uri); /* ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("Unable to parse URI."))); */ PG_RETURN_NULL(); } if (normalize) { if (uriNormalizeSyntaxA(&uri) != URI_SUCCESS) { uriFreeUriMembersA(&uri); PG_RETURN_NULL(); } } UriQueryListA* queryList=NULL; int itemCount; if (parse_query&&(uri.query.afterLast!=uri.query.first)) { if (uriDissectQueryMallocA(&queryList, &itemCount, uri.query.first, uri.query.afterLast) != URI_SUCCESS) { uriFreeUriMembersA(&uri); uriFreeQueryListA(queryList); PG_RETURN_NULL(); } } /* Function internals finish here */ if (get_call_result_type(fcinfo, NULL, &tupledesc) != TYPEFUNC_COMPOSITE) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("function returning record called in context " "that cannot accept type record"))); PG_RETURN_NULL(); } /* This error should never happen, because the SQL function is defined as returning a uri_type. */ attinmeta = TupleDescGetAttInMetadata(tupledesc); char** retval=(char**) palloc(13*sizeof(char*)); if (!retval) { ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("Memory allocation failed."))); PG_RETURN_NULL(); } if (uri.scheme.afterLast==uri.scheme.first) { retval[0]=NULL; } else { retval[0]=(char*) palloc((1+(uri.scheme.afterLast-uri.scheme.first))*sizeof(char)); /* scheme, e.g. "http" */ if (!retval[0]) { ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("Memory allocation failed."))); PG_RETURN_NULL(); } memcpz(retval[0],uri.scheme.first,uri.scheme.afterLast-uri.scheme.first); } if (uri.userInfo.afterLast==uri.userInfo.first) { retval[1]=NULL; } else { retval[1]=(char*) palloc((1+(uri.userInfo.afterLast-uri.userInfo.first))*sizeof(char)); /* userInfo, e.g. "gpadmin" */ if (!retval[1]) { ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("Memory allocation failed."))); PG_RETURN_NULL(); } memcpz(retval[1],uri.userInfo.first,uri.userInfo.afterLast-uri.userInfo.first); } if (uri.hostText.afterLast==uri.hostText.first) { retval[2]=NULL; } else { retval[2]=(char*) palloc((1+(uri.hostText.afterLast-uri.hostText.first))*sizeof(char)); /* hostText, e.g. "192.165.0.0" */ if (!retval[2]) { ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("Memory allocation failed."))); PG_RETURN_NULL(); } memcpz(retval[2],uri.hostText.first,uri.hostText.afterLast-uri.hostText.first); } if (uri.hostData.ip4==NULL) { retval[3]=NULL; } else { retval[3]=(char*) palloc(17*sizeof(char)); /* IPv4 */ if (!retval[3]) { ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("Memory allocation failed."))); PG_RETURN_NULL(); } memcpy(retval[3],"\\000\\000\\000\\000",17); for(i=0;i<4;++i) { retval[3][1+4*i]+=uri.hostData.ip4->data[i]>> 6; retval[3][2+4*i]+=(uri.hostData.ip4->data[i]>> 3)&7; retval[3][3+4*i]+=uri.hostData.ip4->data[i]&7; } } if (uri.hostData.ip6==NULL) { retval[4]=NULL; } else { retval[4]=(char*) palloc(65*sizeof(char)); /* IPv6 */ if (!retval[4]) { ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("Memory allocation failed."))); PG_RETURN_NULL(); } memcpy(retval[4],"\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000\\000",65); for(i=0;i<16;++i) { retval[4][1+4*i]+=uri.hostData.ip6->data[i]>> 6; retval[4][2+4*i]+=(uri.hostData.ip6->data[i]>> 3)&7; retval[4][3+4*i]+=uri.hostData.ip6->data[i]&7; } } if (uri.hostData.ipFuture.afterLast==uri.hostData.ipFuture.first) { retval[5]=NULL; } else { retval[5]=(char*) palloc((1+(uri.hostData.ipFuture.afterLast-uri.hostData.ipFuture.first))*sizeof(char)); /* ipFuture, text field */ if (!retval[5]) { ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("Memory allocation failed."))); PG_RETURN_NULL(); } memcpz(retval[5],uri.hostData.ipFuture.first,uri.hostData.ipFuture.afterLast-uri.hostData.ipFuture.first); } if (uri.portText.afterLast==uri.portText.first) { retval[6]=NULL; } else { retval[6]=(char*) palloc((1+(uri.portText.afterLast-uri.portText.first))*sizeof(char)); /* portText, e.g. "80" */ if (!retval[6]) { ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("Memory allocation failed."))); PG_RETURN_NULL(); } memcpz(retval[6],uri.portText.first,uri.portText.afterLast-uri.portText.first); } if (uri.pathHead==NULL) { retval[7]=NULL; } else { memctr=2; pathseg=uri.pathHead; do { quit=((pathseg==uri.pathTail)||(pathseg->next==NULL)); memctr+=3+2*(pathseg->text.afterLast-pathseg->text.first); pathseg=pathseg->next; } while (!quit); if (memctr==2) { ++memctr; } retval[7]=(char*) palloc(memctr*sizeof(char)); /* path */ /* e.g. "{usr,local,lib}" */ if (!retval[7]) { ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("Memory allocation failed."))); PG_RETURN_NULL(); } writehere=retval[7]; *writehere='{'; ++writehere; pathseg=uri.pathHead; do { quit=((pathseg==uri.pathTail)||(pathseg->next==NULL)); writehere=memenc(writehere,pathseg->text.first,pathseg->text.afterLast-pathseg->text.first); *writehere=','; ++writehere; pathseg=pathseg->next; } while (!quit); if (memctr!=3) { --writehere; } memcpy(writehere,"}",2); } if (uri.query.afterLast==uri.query.first) { retval[8]=NULL; } else { retval[8]=(char*) palloc((1+(uri.query.afterLast-uri.query.first))*sizeof(char)); /* query without leading "?" */ if (!retval[8]) { ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("Memory allocation failed."))); PG_RETURN_NULL(); } memcpz(retval[8],uri.query.first,uri.query.afterLast-uri.query.first); } if (uri.fragment.afterLast==uri.fragment.first) { retval[9]=NULL; } else { retval[9]=(char*) palloc((1+(uri.fragment.afterLast-uri.fragment.first))*sizeof(char)); /* fragment without leading "#" */ if (!retval[9]) { ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("Memory allocation failed."))); PG_RETURN_NULL(); } memcpz(retval[9],uri.fragment.first,uri.fragment.afterLast-uri.fragment.first); } if (uri.absolutePath) { retval[10]=(char*) palloc(5*sizeof(char)); /* absolutePath */ if (!retval[10]) { ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("Memory allocation failed."))); PG_RETURN_NULL(); } memcpy(retval[10],"true",5); } else { retval[10]=(char*) palloc(6*sizeof(char)); /* absolutePath */ if (!retval[10]) { ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("Memory allocation failed."))); PG_RETURN_NULL(); } memcpy(retval[10],"false",6); } if (parse_query) { int key_counter=2; int val_counter=2; int counter=0; for(UriQueryListA* it=queryList;(counter!=itemCount)&&(it!=NULL); it=it->next,++counter) { if (it->key==NULL) { key_counter+=3; /* should never reach here. */ } else { key_counter+=3+2*strlen(it->key); } if (it->value==NULL) { val_counter+=3; /* currently no way to distinguish empty string value (?a=) from null value (?a). This is a GPDB limitation. */ } else { val_counter+=3+2*strlen(it->value); } } if (key_counter==2) { ++key_counter; } if (val_counter==2) { ++val_counter; } retval[11]=palloc(key_counter*sizeof(char)); if (!retval[11]) { ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("Memory allocation failed."))); PG_RETURN_NULL(); } retval[12]=palloc(val_counter*sizeof(char)); if (!retval[12]) { ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("Memory allocation failed."))); PG_RETURN_NULL(); } retval[11][0]='{'; retval[12][0]='{'; char* key_ptr=retval[11]+1; char* val_ptr=retval[12]+1; counter=0; for(UriQueryListA* it=queryList;(counter!=itemCount)&&(it!=NULL); it=it->next,++counter) { if (it->key==NULL) { *key_ptr='"'; ++key_ptr; *key_ptr='"'; ++key_ptr; *key_ptr=','; ++key_ptr; /* should never reach here. */ } else { key_ptr=strenc(key_ptr,it->key); *key_ptr=','; ++key_ptr; } if (it->value==NULL) { *val_ptr='"'; ++val_ptr; *val_ptr='"'; ++val_ptr; *val_ptr=','; ++val_ptr; /* currently no way to distinguish empty string value (?a=) from null value (?a). This is a GPDB limitation. */ } else { val_ptr=strenc(val_ptr,it->value); *val_ptr=','; ++val_ptr; } } if (key_counter!=3) { --key_ptr; } memcpy(key_ptr,"}",2); if (val_counter!=3) { --val_ptr; } memcpy(val_ptr,"}",2); uriFreeQueryListA(queryList); } else { retval[11]=NULL; retval[12]=NULL; } /* There is no need to call pfree. It's called automatically. */ HeapTuple tuple; Datum result; tuple=BuildTupleFromCStrings(attinmeta,retval); result=HeapTupleGetDatum(tuple); /* Free memory start */ uriFreeUriMembersA(&uri); /* Free memory finish */ PG_RETURN_DATUM(result); }
static bool loadImage(ofPixels_<PixelType> & pix, const std::filesystem::path& _fileName, const ofImageLoadSettings& settings){ ofInitFreeImage(); auto uriStr = _fileName.string(); UriUriA uri; UriParserStateA state; state.uri = &uri; if(uriParseUriA(&state, uriStr.c_str())!=URI_SUCCESS){ const int bytesNeeded = 8 + 3 * strlen(uriStr.c_str()) + 1; std::vector<char> absUri(bytesNeeded); #ifdef TARGET_WIN32 uriWindowsFilenameToUriStringA(uriStr.c_str(), absUri.data()); #else uriUnixFilenameToUriStringA(uriStr.c_str(), absUri.data()); #endif if(uriParseUriA(&state, absUri.data())!=URI_SUCCESS){ ofLogError("ofImage") << "loadImage(): malformed uri when loading image from uri " << _fileName; uriFreeUriMembersA(&uri); return false; } } std::string scheme(uri.scheme.first, uri.scheme.afterLast); uriFreeUriMembersA(&uri); if(scheme == "http" || scheme == "https"){ return ofLoadImage(pix, ofLoadURL(_fileName.string()).data); } std::string fileName = ofToDataPath(_fileName, true); bool bLoaded = false; FIBITMAP * bmp = nullptr; FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; fif = FreeImage_GetFileType(fileName.c_str(), 0); if(fif == FIF_UNKNOWN) { // or guess via filename fif = FreeImage_GetFIFFromFilename(fileName.c_str()); } if((fif != FIF_UNKNOWN) && FreeImage_FIFSupportsReading(fif)) { if(fif == FIF_JPEG) { int option = getJpegOptionFromImageLoadSetting(settings); bmp = FreeImage_Load(fif, fileName.c_str(), option); } else { bmp = FreeImage_Load(fif, fileName.c_str(), 0); } if (bmp != nullptr){ bLoaded = true; } } //----------------------------- if ( bLoaded ){ putBmpIntoPixels(bmp,pix); } if (bmp != nullptr){ FreeImage_Unload(bmp); } return bLoaded; }
LLUriParser::~LLUriParser() { uriFreeUriMembersA(&mUri); }
UriUriA *create_absolute_uri(const UriUriA *base_uri, const char *url) { UriParserStateA state; UriUriA *abs_dest, rel_source; char *newurl; if (!url || !*url) return NULL; if ((abs_dest = uri_alloc_1()) == NULL) return NULL; if (base_uri) { state.uri = &rel_source; if (uriParseUriA(&state, url) != URI_SUCCESS) { uri_free(abs_dest); uriFreeUriMembersA(&rel_source); return NULL; } if (uriAddBaseUriA(abs_dest, &rel_source, base_uri) != URI_SUCCESS) { uri_free(abs_dest); uriFreeUriMembersA(&rel_source); return NULL; } uriFreeUriMembersA(&rel_source); } else { state.uri = abs_dest; if (uriParseUriA(&state, url) != URI_SUCCESS) { uri_free(abs_dest); return NULL; } } if (uriNormalizeSyntaxA(abs_dest) != URI_SUCCESS) { uri_free(abs_dest); return NULL; } /* http://www.example.com and http://www.example.com/ have to generate the same object */ if (!base_uri && (!abs_dest->pathHead || !abs_dest->pathHead->text.first) && !abs_dest->query.first) { newurl = string_new(url); string_cat(&newurl, "/"); uriFreeUriMembersA(abs_dest); state.uri = abs_dest; if (uriParseUriA(&state, newurl) != URI_SUCCESS) { uri_free(abs_dest); string_free(newurl); return NULL; } if (uriNormalizeSyntaxA(abs_dest) != URI_SUCCESS) { uri_free(abs_dest); string_free(newurl); return NULL; } string_free(newurl); } return abs_dest; }
static void _free_uri(gpointer d) { uriFreeUriMembersA((UriUriA *) d); g_free(d); }
static void decode_options(application_info_t* application_info, int argc, char **argv) { static const char *opt_string="i:p:d:h"; static struct option const longopts[] = { {"ip",required_argument,NULL,'i'}, {"port",required_argument,NULL,'p'}, {"dst",required_argument,NULL,'d'}, {"help",no_argument,NULL,'h'}, {NULL,0,NULL,0} }; int optc, longind=0; const char *name = argv[0]; while((optc=getopt_long(argc,argv,opt_string,longopts,&longind))!=-1) { switch (optc) { case 'h': usage(name); exit(0); case 'i': application_info->multicast_ip = strdup(optarg); break; case 'p': application_info->multicast_port = atoi(optarg); break; case 'd': application_info->filepath = strdup(optarg); break; default: usage(name); exit(0); } } int i; for(i = optind; i < argc; i++) { // application_info->uri = strdup(argv[i]); fprintf(stderr, "argv[%d]: %s\n", i, argv[i]); UriParserStateA state; UriUriA _uri; state.uri = &_uri; char* uri = argv[i]; if (uriParseUriA(&state, uri) != URI_SUCCESS) { /* Failure */ uriFreeUriMembersA(&_uri); fprintf(stderr, "failed to <uriParseUriA>\n"); exit(0); } if(memcmp("rtp", _uri.scheme.first, _uri.scheme.afterLast - _uri.scheme.first)==0) { application_info->prot = eRTP; } else if(memcmp("udp", _uri.scheme.first, _uri.scheme.afterLast - _uri.scheme.first)==0) { application_info->prot = eUDP; } else { fprintf(stderr, "Unknown protocol\n"); usage(name); } /* group address */ char tmp[512] = {0}; sprintf(tmp, "%d.%d.%d.%d", _uri.hostData.ip4->data[0], _uri.hostData.ip4->data[1], _uri.hostData.ip4->data[2], _uri.hostData.ip4->data[3]); if(application_info->multicast_ip) free(application_info->multicast_ip); application_info->multicast_ip = strdup(tmp); /* port */ application_info->multicast_port = atoi(_uri.portText.first); uriFreeUriMembersA(&_uri); } }