Ejemplo n.º 1
0
	/**
	 * URL encodes the input string.
	 * @param QString input
	 * @returns QString
	 * @author John M. Harris, Jr.
	 */
	QString HttpService::UrlEncode(QString input){
		CURL* curl;

		curl = curl_easy_init();
		if(curl){
			char* encoded = curl_easy_escape(curl, input.toStdString().c_str(), 0);

			size_t thingLen = strlen(encoded) + 1;
			char* newGuy = new char[thingLen];
			strcpy(newGuy, encoded);
			//newGuy[thingLen] = '\0';

			curl_free(encoded);
			curl_easy_cleanup(curl);

			return QString(newGuy);
		}
		return "";
	}
Ejemplo n.º 2
0
int test(char *URL)
{
  unsigned char a[] = {0x2f, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
                       0x91, 0xa2, 0xb3, 0xc4, 0xd5, 0xe6, 0xf7};
  CURLcode res;
  CURL *curl;
  int asize;
  char *str = NULL;

  (void)URL;

  res = curl_global_init_mem(CURL_GLOBAL_ALL,
                             custom_malloc,
                             custom_free,
                             custom_realloc,
                             custom_strdup,
                             custom_calloc);
  if (res != CURLE_OK) {
    fprintf(stderr, "curl_global_init_mem() failed\n");
    return TEST_ERR_MAJOR_BAD;
  }

  if ((curl = curl_easy_init()) == NULL) {
    fprintf(stderr, "curl_easy_init() failed\n");
    curl_global_cleanup();
    return TEST_ERR_MAJOR_BAD;
  }

  test_setopt(curl, CURLOPT_USERAGENT, "test509"); /* uses strdup() */

  asize = (int)sizeof(a);
  str = curl_easy_escape(curl, (char *)a, asize); /* uses realloc() */

test_cleanup:

  if(str)
    curl_free(str);

  curl_easy_cleanup(curl);
  curl_global_cleanup();

  return (int)res;
}
Ejemplo n.º 3
0
bool
http_post(const char *url, http_response_t *resp, int pairs, ...)
{
    CURL *curl;
    CURLcode res;

    int i, len=0;
    char *k[pairs], *v[pairs], *vv[pairs];
    va_list params;
    va_start(params, pairs);
    for (i=0; i<pairs; i++) {
        k[i] = va_arg(params, char *);
        v[i] = va_arg(params, char *);
        vv[i]= curl_easy_escape(curl, v[i], 0);
        tlog(DEBUG, "http post: %s = %s(%s)", k[i], v[i], vv[i]);
        len += 4+strlen(k[i])+strlen(vv[i]);
    }
    va_end(params);

    char data[len];
    memset(data, 0, len);
    for (i=0; i<pairs; i++) {
        strcat(data, "&");
        strcat(data, k[i]);
        strcat(data, "=");
        strcat(data, vv[i]);
        curl_free(vv[i]);
    }
    tlog(DEBUG, "http post: data = %s", data);

    curl = curl_easy_init();
    if (curl != NULL) {
        curl_easy_setopt(curl, CURLOPT_URL, url);
        curl_easy_setopt(curl, CURLOPT_POST, 1);
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_memory_cb);
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)resp);
        res = curl_easy_perform(curl);
        curl_easy_cleanup(curl);
        return res==CURLE_OK;
    }
    return false;
}
Ejemplo n.º 4
0
void CPushPlayerInfoHttpCMD::EscapeUrl(CHAR szUrl[], UINT16 wLen)
{
    UINT8	abyDigest[16] = {0};
    string	strInput = m_strfields;
    strInput.append(CENTER_SIGN);
    SDMD5(abyDigest, (UINT8*)strInput.c_str(), strInput.length());
    CHAR szTemp[32] = {0};
    CHAR szHexDigest[256] = {0};
    for (UINT8 byIdx = 0; byIdx < 16; byIdx++)
    {
        sprintf(szTemp, "%02x", (UINT8)abyDigest[byIdx]);
        strcat(szHexDigest, szTemp);
    }

    char *szEscapeHex = curl_easy_escape(m_pEasyHandle, szHexDigest, 0);;
    SDSnprintf(szUrl, wLen, "%s?_sig=%s", m_strUrl.c_str(), szEscapeHex);

    curl_free(szEscapeHex);
}
Ejemplo n.º 5
0
/* Extracts the name portion of the URL.
 * Returns a pointer to a heap-allocated string or NULL if
 * no name part, at location indicated by first argument.
 */
CURLcode get_url_file_name(char **filename, const char *url)
{
  const char *pc;

  *filename = NULL;

  /* Find and get the remote file name */
  pc = strstr(url, "://");
  if(pc)
    pc += 3;
  else
    pc = url;
  pc = strrchr(pc, '/');

  if(pc) {
    /* duplicate the string beyond the slash */
    pc++;
    if(*pc) {
      *filename = strdup(pc);
      if(!*filename)
        return CURLE_OUT_OF_MEMORY;
    }
  }

  /* in case we built debug enabled, we allow an environment variable
   * named CURL_TESTDIR to prefix the given file name to put it into a
   * specific directory
   */
#ifdef DEBUGBUILD
  {
    char *tdir = curlx_getenv("CURL_TESTDIR");
    if(tdir) {
      char buffer[512]; /* suitably large */
      snprintf(buffer, sizeof(buffer), "%s/%s", tdir, *filename);
      Curl_safefree(*filename);
      *filename = strdup(buffer); /* clone the buffer */
      curl_free(tdir);
    }
  }
#endif

  return CURLE_OK;
}
Ejemplo n.º 6
0
char *
http_client_uri_escape(const char *src)
{
#if GLIB_CHECK_VERSION(2,16,0)
	/* if GLib is recent enough, prefer that over CURL
	   functions */
	return g_uri_escape_string(src, NULL, false);
#else
	/* curl_escape() is deprecated, but for some reason,
	   curl_easy_escape() wants to have a CURL object, which we
	   don't have right now */
	char *tmp = curl_escape(src, 0);
	/* call g_strdup(), because the caller expects a pointer which
	   can be freed with g_free() */
	char *dest = g_strdup(tmp == NULL ? src : tmp);
	curl_free(tmp);
	return dest;
#endif
}
Ejemplo n.º 7
0
static const char *make_url(const request_rec *r, const crowd_config *config, CURL *curl_easy, const char *user,
    const char *format) {
    char *url;
    if (user == NULL) {
        url = apr_psprintf(r->pool, format, config->crowd_url);
    } else {
        char *encoded_user = log_ralloc(r, curl_easy_escape(curl_easy, user, 0));
        if (encoded_user == NULL) {
            return NULL;
        }
        url = apr_psprintf(r->pool, format, config->crowd_url, encoded_user);
        curl_free(encoded_user);
    }
    log_ralloc(r, url);
    if (url == NULL) {
        return NULL;
    }
    return url;
}
Ejemplo n.º 8
0
PCS_API char *pcs_http_build_post_data_v(PcsHttp handle, va_list args)
{
	struct pcs_http *http = (struct pcs_http *)handle;
	char *name, *val, 
		*escapval, *res = NULL, *p;
	int ressz;

	while((name = va_arg(args, char *)) != NULL) {
		val = va_arg(args, char *);
		if (name[0] == '\0') continue;
		escapval = curl_easy_escape(http->curl, val, 0);

		if (!res) {
			ressz = strlen(name) + strlen(escapval) + 1;
			res = (char *)pcs_malloc(ressz + 1);
			if (!res) {
				return NULL;
			}
			strcpy(res, name);
			strcat(res, "=");
			strcat(res, escapval);
		}
		else {
			ressz += strlen(name) + strlen(escapval) + 2;
			p = (char *)pcs_malloc(ressz + 1);
			if (!p) {
				pcs_free(res);
				return NULL;
			}
			strcpy(p, res);
			pcs_free(res);
			res = p;
			strcat(res, "&");
			strcat(res, name);
			strcat(res, "=");
			strcat(res, escapval);
		}
		curl_free((void *)escapval);
	}

	return res;
}
Ejemplo n.º 9
0
bool LLWLParamManager::removeParamSet(const std::string& name, bool delete_from_disk)
{
	// remove from param list
	std::map<std::string, LLWLParamSet>::iterator mIt = mParamList.find(name);
	if(mIt != mParamList.end()) 
	{
		mParamList.erase(mIt);
	}

	F32 key;

	// remove all references
	bool stat = true;
	do 
	{
		// get it
		stat = mDay.getKey(name, key);
		if(stat == false) 
		{
			break;
		}

		// and remove
		stat = mDay.removeKey(key);

	} while(stat == true);
	
	if(delete_from_disk)
	{
		std::string path_name(gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "windlight/skies", ""));
		
		// use full curl escaped name
		char * curl_str = curl_escape(name.c_str(), name.size());
		std::string escaped_name(curl_str);
		curl_free(curl_str);
		curl_str = NULL;
		
		gDirUtilp->deleteFilesInDir(path_name, escaped_name + ".xml");
	}

	return true;
}
Ejemplo n.º 10
0
bool
http_escape(const char *in, char *out)
{
    char *res = NULL;
    CURL *curl;
    bool ret = false;

    curl = curl_easy_init();
    if (curl != NULL) {
        res = curl_easy_escape(curl, in, 0);
        if (res != NULL) {
            memcpy(out, res, strlen(res)+1);
            ret = true;
            curl_free(res);
        }
        curl_easy_cleanup(curl);
        return ret;
    }
    return false;
}
Ejemplo n.º 11
0
/* exported interface documented in utils/url.h */
nserror url_unescape(const char *str, int length, char **result)
{
	char *curlstr;
	char *retstr;

	curlstr = curl_unescape(str, length);
	if (curlstr == NULL) {
		return NSERROR_NOMEM;
	}

	retstr = strdup(curlstr);
	curl_free(curlstr);

	if (retstr == NULL) {
		return NSERROR_NOMEM;
	}

	*result = retstr;
	return NSERROR_OK;
}
Ejemplo n.º 12
0
void LLWLDayCycle::saveDayCycle(const std::string & fileName)
{
	
	// bugfix for SL-46920: preventing filenames that break stuff.
	char * curl_str = curl_escape(fileName.c_str(), fileName.size());
	std::string escaped_filename(curl_str);
	curl_free(curl_str);
	curl_str = NULL;

	escaped_filename += ".xml";

	std::string pathName(gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "windlight/days", escaped_filename));
	llinfos << "Saving Day Cycle preset from " << pathName << llendl;

	llofstream day_cycle_xml;
	day_cycle_xml.open(pathName.c_str());

	// That failed, try loading from the users area instead.
	if(!day_cycle_xml)
	{
		pathName=gDirUtilp->getExpandedFilename( LL_PATH_USER_SETTINGS , "windlight/days", escaped_filename);
		llinfos << "Saving User Day Cycle preset from " << pathName << llendl;
		day_cycle_xml.open(pathName.c_str());
	}

	LLSD day_data(LLSD::emptyArray());

	for(std::map<F32, std::string>::const_iterator mIt = mTimeMap.begin();
		mIt != mTimeMap.end();
		++mIt) 
	{
		LLSD key(LLSD::emptyArray());
		key.append(mIt->first);
		key.append(mIt->second);
		day_data.append(key);
	}

	LLPointer<LLSDFormatter> formatter = new LLSDXMLFormatter();
	formatter->format(day_data, day_cycle_xml, LLSDFormatter::OPTIONS_PRETTY);
	day_cycle_xml.close();
}
Ejemplo n.º 13
0
int
curl_url_encoding(CURL *curl, char *input, char *output, size_t size)
{
  ol_log_func ();
  char *escp;
  int flag = 0;
  if(curl == NULL) {
    curl = curl_easy_init();
    flag = 1;
  }

  /* 
   * convert to GBK, this should be done before this function called
   *
   char buf[BUFSZ];
   iconv_t icv;
   if(charset != NULL)
   icv = iconv_open("GBK", charset);
   else
   icv = iconv_open("GBK", "UTF-8");
	
   convert_icv(&icv, input, strlen(input), buf, BUFSZ);
   iconv_close(icv);
  */

  escp = curl_easy_escape(curl, input, 0);
  if(escp == NULL) {
    ol_errorf ("curl_easy_escape error.\n");
    return -1;
  }
  if(strlen(escp) > size) {
    errno = E2BIG; /* identify that buffer storing the result is too small */
    return -1;
  }
  strcpy(output, escp);
  curl_free(escp);

  if(flag == 1)
    curl_easy_cleanup(curl);
  return 0;
}
Ejemplo n.º 14
0
int viprinet_status_connect(viprinet_status_t *status)
{
    char *password_encoded;
    char uri[MAX_URI_LEN];
    int rc;

    pthread_attr_t ptattr;

    if (status == NULL) {
        return -1;
    }
    if (status->close != -1) {
        return -1;
    }
    
    password_encoded = curl_easy_escape(status->curl, status->password, 0);
    snprintf(uri, MAX_URI_LEN,
             "http://%s/exec?module=interfacestats&action=data&group=ModuleSlots&nick=root&pass=%s",
             status->hostname,
             password_encoded);
    curl_free(password_encoded);
    
    status->close = 0;
    
    curl_easy_setopt(status->curl, CURLOPT_URL, uri);
    curl_easy_setopt(status->curl, CURLOPT_NOPROGRESS, 0);
    curl_easy_setopt(status->curl, CURLOPT_PROGRESSDATA, status);
    curl_easy_setopt(status->curl, CURLOPT_PROGRESSFUNCTION, &progress_callback);
    curl_easy_setopt(status->curl, CURLOPT_WRITEFUNCTION, &write_callback);
    curl_easy_setopt(status->curl, CURLOPT_WRITEDATA, status);
   
    pthread_attr_init(&ptattr);
    pthread_attr_setdetachstate(&ptattr, PTHREAD_CREATE_JOINABLE);
    rc = pthread_create(status->thread, &ptattr, &perform, (void *)status);
    pthread_attr_destroy(&ptattr);

    if (rc) {
        return -2;
    }
    return 0;
}
Ejemplo n.º 15
0
void wswcurl_urlencode( const char *src, char *dst, size_t size )
{
	char *curl_esc;

	assert( src );
	assert( dst );

	if( !src || !dst ) {
		return;
	}

	// libcurl needs a curl pointer to be passed to a function that
	// should clearly be "static", how inconvenient...
	if( !curldummy ) {
		curldummy = curl_easy_init();
	}

	curl_esc = curl_easy_escape( curldummy, src, 0 );
	Q_strncpyz( dst, curl_esc, size );
	curl_free( curl_esc );
}
Ejemplo n.º 16
0
	std::string Authorization::sort_params(std::map<std::string ,std::string> &params)
	{
		
		stringstream qs;
		CURL *curl = curl_easy_init();
		char *value; 
		for (std::map<std::string,std::string>::iterator it=params.begin(); it!=params.end(); ++it)
		{
			//Some parse and safety check left  refer auth_handler.py
			// utf encoding on values left
			//url encoding
			value = curl_easy_escape(curl,it->second.c_str(),0);
			qs<<it->first<<"="<<value<<"&";
		}
		string qs_ = qs.str();
		qs_[qs_.length()-1]='\0'; //removing last &
		curl_free(value);
		return qs_;


	}
Ejemplo n.º 17
0
// out should be enough to hold result
bool
http_unescape(const char *in, char *out)
{
    int   len = -1;
    char *res = NULL;
    CURL *curl;
    bool ret = false;

    curl = curl_easy_init();
    if (curl != NULL) {
        res = curl_easy_unescape(curl, in, 0, &len);
        if (res != NULL && len > 0) {
            memcpy(out, res, len+1);
            ret = true;
        }
        if (res != NULL) curl_free(res);
        curl_easy_cleanup(curl);
        return ret;
    }
    return false;
}
Ejemplo n.º 18
0
static int url_encoding(lua_State* l)
{
    struct webclient* webclient = (struct webclient*)luaL_checkudata(l, 1, LUA_WEB_CLIENT_MT);
    if (!webclient)
        return luaL_argerror(l, 1, "parameter self invalid");
    
    if (!webclient->encoding_curl)
        webclient->encoding_curl = curl_easy_init();
    
    size_t length = 0;
    const char* str = lua_tolstring(l, 2, &length);
    char* ret = curl_easy_escape(webclient->encoding_curl, str, (int)length);
    if (!ret) {
        lua_pushlstring(l, str, length);
        return 1;
    }
    
    lua_pushstring(l, ret);
    curl_free(ret);
    return 1;
}
Ejemplo n.º 19
0
/* 下载单个文件 */
void BaiduPCS_Download(BaiduPCS *api, const char *remote_file, FILE *local_fp) {
//{{{
    if (remote_file == NULL || local_fp == NULL) return;

    HttpClient *client          = api->client;
    char *url_buffer            = api->util_buffer0;
    const char *token           = api->token;
    const char *error           = NULL;
    char *remote_path_encode    = NULL;

    BaiduPCS_ResetError(api); 

    remote_path_encode = curl_easy_escape(client->curl, remote_file, 0);
    sprintf(url_buffer, "https://d.pcs.baidu.com/rest/2.0/pcs/file?"
           "access_token=%s"
           "&method=download"
           "&path=%s", token, remote_path_encode);
    curl_free(remote_path_encode);
    remote_path_encode = NULL;

#ifdef DEBUG
    fprintf(stderr, "request %s\n", url_buffer);
#endif
    
    HttpClient_Init(client);
    HttpClient_SetFailRetry(client, 0, 0);
    curl_easy_setopt(client->curl, CURLOPT_WRITEFUNCTION, _BaiduPCS_Download_WriteData);
    curl_easy_setopt(client->curl, CURLOPT_WRITEDATA, local_fp);
    /* 跟随重定向 */
    curl_easy_setopt(client->curl, CURLOPT_FOLLOWLOCATION, 1);
    /* 下载木有超时 */
    curl_easy_setopt(client->curl, CURLOPT_TIMEOUT, 0);
    HttpClient_Get(client, url_buffer);

    error = HttpClient_GetError(client);
    if (error != NULL) {
        BaiduPCS_ThrowError(api, "http request failed: %s", error);
    }
}
Ejemplo n.º 20
0
Archivo: curl.c Proyecto: NgoHuy/uim
static void *
uim_curl_url_escape_internal(void *url_)
{
  uim_lisp escaped_url_;
  const char *unescaped_url = REFER_C_STR((uim_lisp)url_);
  char *escaped_url;
  CURL *curl;

  curl = curl_easy_init();

  if(curl == NULL)
    return uim_scm_f();

  escaped_url = curl_easy_escape(curl, unescaped_url, strlen(unescaped_url));
  escaped_url_ = (escaped_url != NULL) ? MAKE_STR(escaped_url) : uim_scm_f();

  curl_free(escaped_url);
  curl_easy_cleanup(curl);
  curl_global_cleanup();

  return (void *)escaped_url_;
}
Ejemplo n.º 21
0
void format_query(char *query_str, char *result) {

  char *escaped;
  CURL *curl = curl_easy_init();

  char *token = strtok(query_str, ",;?!-_ \n\r");
  while (token != NULL) {

    escaped = curl_easy_escape(curl, token, strlen(token));

    strcpy(result + strlen(result), escaped);
    strcpy(result + strlen(result), "+");

    token = strtok(NULL, ",.:;?!-_ ");

    curl_free(escaped);
  }

  result[strlen(result) - 1] = '\0';

  curl_easy_cleanup(curl);
}
Ejemplo n.º 22
0
int AsyncHttpRequest::getMethodSend(const char *data,char *recv,const char *url)
{
    std::string request(url);
	
	CURL* easy_handle=curl_easy_init();
	
	char *encodedURL = curl_easy_escape(easy_handle,data, strlen(data));
	
	request.append(encodedURL);
	//struct curl_slist *header=NULL;
	//header= curl_slist_append(header,request.c_str());
	if(m_pInstance->enableDebug)
        curl_easy_setopt(easy_handle, CURLOPT_VERBOSE,1L);/*open comment when debug mode.*/
	
    CallbackData *cba = (CallbackData*)malloc(sizeof(CallbackData));
    cba->buffer = (char*)malloc(100000);
   
    cba->position = 0;
	curl_easy_setopt(easy_handle,CURLOPT_URL,request.c_str());
	//curl_easy_setopt(easy_handle,CURLOPT_HTTPHEADER,header);
	curl_easy_setopt(easy_handle,CURLOPT_HTTP_TRANSFER_DECODING,1);
	curl_easy_setopt(easy_handle,CURLOPT_WRITEFUNCTION,postWriteData);//receive callback function
	
	curl_easy_setopt(easy_handle,CURLOPT_WRITEDATA,cba);
	CURLcode code=curl_easy_perform(easy_handle);//
	
    memcpy(recv,cba->buffer,cba->position);
    
    free(cba->buffer);
    free(cba);
  
	//curl_slist_free_all(header);
	
	curl_easy_cleanup(easy_handle);
	
	curl_free(encodedURL);
    
	return code;
}
void AnalyticsManager::logEventToServer(const char* serverURL, const char* eventCategory, const char* eventType, const char* eventLabel, int eventValue)
{
	CURL* curl = curl_easy_init();
	CURLcode res;

	// construct the postfields using much string math
	char postfields[512] = "";
	sprintf_s(postfields, 512, "v=%d&tid=%s&an=%s&cid=%s&t=%s&ec=%s&ea=%s&debug=%d", 1, TRACKING_ID, TRACKING_APP_NAME, clientID, "event", eventCategory, eventType, isDebugMode);
	if ( eventLabel[0] != 0 )
	{
		char* tempEncode = curl_easy_escape(curl, eventLabel, strlen(eventLabel));
		strcat_s(postfields, 512, "&el=");
		strcat_s(postfields, 512, tempEncode);
		curl_free(tempEncode);
	}
	if ( eventValue != -1 )
	{
		char tempEncode[128] = "";
		_itoa_s(eventValue, tempEncode, 64, 10);
		strcat_s(postfields, 512, "&ev=");
		strcat_s(postfields, 512, tempEncode);
	}

	// post the data using curl
	if ( curl )
	{
		// post to Google Analytics first
	    curl_easy_setopt(curl, CURLOPT_URL, serverURL);
		curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postfields); 
		res = curl_easy_perform(curl);
		if (res != CURLE_OK)
		{
			al_trace("curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
		}
		
	    curl_easy_cleanup(curl);
	}
}
Ejemplo n.º 24
0
void SmsGateway::sendSms(std::string &id, std::string &value)
{
    if (type_m == Clickatell)
    {
#ifdef HAVE_LIBCURL
        CURL *curl;
        CURLcode res;

        curl = curl_easy_init();
        if(curl)
        {
            char *escaped_value = curl_escape(value.c_str(), value.length());
            std::stringstream msg;
            msg << "http://api.clickatell.com/http/sendmsg?user="******"&password="******"&api_id=" << data_m;
            if (!from_m.empty())
                msg << "&from=" << from_m;
            msg << "&to=" << id << "&text=" << escaped_value;
            std::string url = msg.str();
            curl_free(escaped_value);
            //        curl_easy_setopt(curl, CURLOPT_VERBOSE, TRUE);
            curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
            res = curl_easy_perform(curl);

            logger_m.infoStream() << "curl_easy_perform returned: " << res << endlog;
            if (res != 0)
                logger_m.infoStream() << "msg=" << curl_easy_strerror(res) << endlog;

            curl_easy_cleanup(curl);
        }
        else
            logger_m.errorStream() << "Unable to execute SendSmsAction. Curl not available" << endlog;
#endif
    }
    else
        logger_m.errorStream() << "Unable to send SMS, gateway not set." << endlog;
}
Ejemplo n.º 25
0
Archivo: lib1560.c Proyecto: curl/curl
static int get_url(void)
{
  int i;
  CURLUcode rc;
  int error = 0;
  for(i = 0; get_url_list[i].in && !error; i++) {
    char *url = NULL;
    CURLU *urlp = curl_url();
    if(!urlp) {
      error++;
      break;
    }
    rc = curl_url_set(urlp, CURLUPART_URL, get_url_list[i].in,
                      get_url_list[i].urlflags);
    if(!rc) {
      rc = curl_url_get(urlp, CURLUPART_URL, &url, get_url_list[i].getflags);

      if(rc) {
        fprintf(stderr, "%s:%d returned %d\n",
                __FILE__, __LINE__, (int)rc);
        error++;
      }
      else {
        if(checkurl(url, get_url_list[i].out)) {
          error++;
        }
      }
    }
    else if(rc != get_url_list[i].ucode) {
      fprintf(stderr, "Get URL\nin: %s\nreturned %d (expected %d)\n",
              get_url_list[i].in, (int)rc, get_url_list[i].ucode);
      error++;
    }
    curl_free(url);
    curl_url_cleanup(urlp);
  }
  return error;
}
Ejemplo n.º 26
0
char *url_to_path(const char *url)
{
	char *tmps, *unesc;
	CURL *curl;

	tmps = strstr(url, "///localhost/") + 13;

	if(tmps < url) tmps = strstr(url,"///") + 3;

	if(tmps >= url)
	{
		if(curl = curl_easy_init())
		{
			unesc = curl_easy_unescape(curl,tmps,0,NULL);
			tmps = strdup(unesc);
			curl_free(unesc);
			curl_easy_cleanup(curl);
			return tmps;
		}
	}

	return strdup((char *)url);
}
Ejemplo n.º 27
0
void CPushPlayerInfoHttpCMD::EscapeFields()
{
    CNGString strTemp;
    char *szEscape = NULL;
    m_strfields.append("playerid=");
    strTemp = m_stPlayerInfo.dwPlayerID;
    szEscape = curl_easy_escape(m_pEasyHandle, strTemp.c_str(), 0);
    m_strfields.append(szEscape);
    curl_free(szEscape);

    m_strfields.append("&level=");
    strTemp = m_stPlayerInfo.wLevel;
    szEscape = curl_easy_escape(m_pEasyHandle, strTemp.c_str(), 0);
    m_strfields.append(szEscape);
    curl_free(szEscape);

    m_strfields.append("&careerid=");
    strTemp = m_stPlayerInfo.wCoachHeroID;
    szEscape = curl_easy_escape(m_pEasyHandle, strTemp.c_str(), 0);
    m_strfields.append(szEscape);
    curl_free(szEscape);

	m_strfields.append("&viplevel=");
	strTemp = m_stPlayerInfo.byVipLv;
	szEscape = curl_easy_escape(m_pEasyHandle, strTemp.c_str(), 0);
	m_strfields.append(szEscape);
	curl_free(szEscape);

	m_strfields.append("&_ch=");
	strTemp = m_stPlayerInfo.byAuthType;
	szEscape = curl_easy_escape(m_pEasyHandle, strTemp.c_str(), 0);
	m_strfields.append(szEscape);
	curl_free(szEscape);

    m_strfields.append("&name=");
    szEscape = curl_easy_escape(m_pEasyHandle, m_stPlayerInfo.strNickName.c_str(), 0);
    if(NULL == szEscape)
    {
        SYS_CRITICAL( _SDT( "[%s: %d]: curl_easy_escape playerid[%u] nickname [%s] failed"), MSG_MARK, 
            m_stPlayerInfo.dwPlayerID, m_stPlayerInfo.strNickName.c_str());
    }

    m_strfields.append(szEscape);
    curl_free(szEscape);
}
Ejemplo n.º 28
0
// "inworldz://simname/x/y/z" -> "simname/x/y/z"
// (actually .*//foo -> foo)
// static
void LLURLSimString::setString(const std::string& sim_string)
{
	sInstance.mSimString.clear();
	sInstance.mSimName.clear();
	sInstance.mParseState = NOT_PARSED;
	if (sim_string == sLocationStringHome)
	{
		gSavedSettings.setBOOL("LoginLastLocation", FALSE);
	}
	else if (sim_string == sLocationStringLast)
	{
		gSavedSettings.setBOOL("LoginLastLocation", TRUE);
	}
	else
	{
		char* curlstr = curl_unescape(sim_string.c_str(), sim_string.size());
		std::string tstring = std::string(curlstr);
		curl_free(curlstr);
		std::string::size_type idx = tstring.find("//");
		idx = (idx == std::string::npos) ? 0 : idx+2;
		sInstance.mSimString = tstring.substr(idx);
	}
}
Ejemplo n.º 29
0
void AppWindow::on_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, const Gtk::SelectionData& selection_data, guint info, guint time)
	{  
    // this is totally ridiculous, but so be it!
	// we erase the protocol in front of the filename
	// using std::string because Glib::ustring throws a conversion error for some reason
	std::string string_filename = selection_data.get_data_as_string();
	string_filename.erase(0, string_filename.find(':')+3); 

	//convert to char* and unescape
	char * temp_filename = curl_unescape( string_filename.c_str(), 0);
	string_filename = temp_filename;
	// curl requires this to be freed
	curl_free( temp_filename );
	
	//let's remove any \n and \r that are typical of URI's
	if ( string_filename.find('\n') != Glib::ustring::npos )
		string_filename.erase( string_filename.find('\n'), 1 );
	if ( string_filename.find('\r') != Glib::ustring::npos )
		string_filename.erase( string_filename.find('\r'), 1 );

	open_new_file( string_filename );
	context->drag_finish(false, false, time);
	}
Ejemplo n.º 30
0
/* Send a GET request to write *data (after url encoding) to *url 
 * Sends request to influx host defined in conn. Returns resulting CURLcode.
 */
CURLcode sendGet(influxConn *conn, char *url, char *data){
    CURL *curl = conn->curl;
    CURLcode resultCode;
    if(curl){
        if(data){ //urlencode data
            char *encoded_data = curl_easy_escape(curl, data, strlen(data));
            url = realloc(url, sizeof(char *) * ((int) strlen(url) + strlen(encoded_data) + 1) );
            if(url){
                strncat(url, encoded_data, strlen(encoded_data));
                curl_free(encoded_data);
            }
        }

        if(influx_debug){printf("[q: %s]\n", url);}
        
        curl_easy_setopt(curl, CURLOPT_URL, url);
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeCallback);
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, conn);
        resultCode = curl_easy_perform(curl);
    }
    free(url);
    return resultCode;
}