Beispiel #1
0
/* parse a cgi query string returning one key-value pair at a time */
bool qstring_next_pair(const char *qstring, char *buf, char **vbuf, uint32_t buflen) {
    static const char *q = NULL;
	char *eob;
    // set up if not currently working on a qstring
    if (q == NULL) 
        q = qstring; 
    
    if (*q == '\0') { 
        q = NULL; // set internal state (no work in progress)
        return false; // signal this query string is fully parsed
    }
    eob = buf + buflen - 1;
    *vbuf = buf; // in case there is no '='
    while (*q != '\0') {
        if (buf >= eob) // check for buffer overflow
            break;
        if (*q == '=') {
            *buf++ = '\0';
            *vbuf = buf;
            ++q;
        } else if (*q == '&') {
            ++q;
            break;
        } else {
            *buf++ = *q++; 
        }
    }
    *buf = '\0'; // terminate value string
    url_decode(buf);
    if (*vbuf != buf)
        url_decode(*vbuf);
    return true;
}
Beispiel #2
0
Datei: url.c Projekt: azalpy/sdk
static int url_parse_param(const char* param, url_t* uri)
{
	const char *pn, *pv;
	char buffer[MAX_PATH];
	url_param_t *pp;

	for(pn = param; param && *param && uri->count < MAX_PARAMS; pn=param+1)
	{
		param = strchr(pn, '&');
		pv = strchr(pn, '=');
		if(!pv || pv == pn || (param && pv>param)) // name is null
			continue;

		memset(buffer, 0, sizeof(buffer));

		pp = &uri->params[uri->count++];
		url_decode(pn, pv-pn, buffer, sizeof(buffer));
		pp->name = strdup(buffer);

		++pv;
		if(param)
		{
			url_decode(pv, param-pv, buffer, sizeof(buffer));
		}
		else
		{
			url_decode(pv, -1, buffer, sizeof(buffer));
		}
		pp->value = strdup(buffer);
	}
	return 0;
}
Beispiel #3
0
void http_alarm(char *rx, unsigned int rx_len)
{
  unsigned int i, save;
  char *time, *item;
  ALARMTIME t;

  save=0;
  time=0; item=0;
  for(; rx_len!=0;)
  {
         if(strncmpi(rx, "time=", 5) == 0)
    { rx += 5; rx_len -= 5; time = rx; i = url_decode(rx, rx, rx_len); rx += i; rx_len -= i; }
    else if(strncmpi(rx, "item=", 5) == 0)
    { rx += 5; rx_len -= 5; item = rx; i = url_decode(rx, rx, rx_len); rx += i; rx_len -= i; }
    else if(strncmpi(rx, "save=", 5) == 0)
    { rx += 5; rx_len -= 5; save = 1; }
    else
    { rx++;    rx_len--; }
  }

  if(save && time && item)
  {
    if((strlen(time) > 3) || (strlen(item) > 0))
    {
      i = atoi(item);
      alarm_parsetime(time, &t);
      alarm_settime(i, &t);
      alarm_load();
      menu_drawwnd(1);
    }
  }

  return;
}
Beispiel #4
0
static void parse_get( value *p, const char *args ) {
	char *aand, *aeq, *asep;
	value tmp;
	while( true ) {
		aand = strchr(args,'&');
		if( aand == NULL ) {
			asep = strchr(args,';');
			aand = asep;
		} else {
			asep = strchr(args,';');
			if( asep != NULL && asep < aand )
				aand = asep;
		}
		if( aand != NULL )
			*aand = 0;
		aeq = strchr(args,'=');
		if( aeq != NULL ) {
			*aeq = 0;
			tmp = alloc_array(3);
			val_array_ptr(tmp)[0] = url_decode(args,(int)(aeq-args));
			val_array_ptr(tmp)[1] = url_decode(aeq+1,(int)strlen(aeq+1));
			val_array_ptr(tmp)[2] = *p;
			*p = tmp;
			*aeq = '=';
		}
		if( aand == NULL )
			break;
		*aand = (aand == asep)?';':'&';
		args = aand+1;
	}
}
Beispiel #5
0
struct url parse_url(char *uri, char *query)
{
	struct url url = {0};
	char *dir, *name;
	unsigned i;

	if (!(dir = strtok(uri, "/"))) {
		/*
		 * strtok() never return an empty string.  And that's
		 * what we usually want, because "/players/" will be
		 * handled the same than "/players".
		 *
		 * However, the root route doesn't have a name, hence
		 * the default page doesn't either.  So to allow default
		 * page for root directory, we make a special case and
		 * use an empty string.
		 */
		strcpy(uri, "");
		url.dirs[0] = uri;
		url.ndirs = 1;
	} else {
		do {
			if (url.ndirs == MAX_DIRS)
				error(414, NULL);

			url_decode(dir);
			url.dirs[url.ndirs] = dir;
			url.ndirs++;
		} while ((dir = strtok(NULL, "/")));
	}

	/*
	 * Load arg 'name' and 'val' in two steps to not mix up strtok()
	 * instances.
	 */

	if (query[0] == '\0')
		return url;

	name = strtok(query, "&");
	while (name) {
		if (url.nargs == MAX_ARGS)
			error(414, NULL);

		url.args[url.nargs].name = name;
		url.nargs++;
		name = strtok(NULL, "&");
	}

	for (i = 0; i < url.nargs; i++) {
		strtok(url.args[i].name, "=");
		url.args[i].val = strtok(NULL, "=");

		if (url.args[i].val)
			url_decode(url.args[i].val);
	}

	return url;
}
Beispiel #6
0
void test_url_decode() {
    char buf[20];
    url_decode(buf, "/foo%20bar");
    info("URL decoded: %s", buf);
    assert(strcmp("/foo bar", buf) == 0);
    url_decode(buf, "/%E4%B8%AD%E5%9B%BD%E4%BA%BA");
    info("URL decoded: %s", buf);
    assert(strcmp("/中国人", buf) == 0);
}
Beispiel #7
0
GHashTable *http_parse_header (http_request *h, gchar *req) {
    GHashTable *head = g_hash_new();
    gchar **lines, **items, *key, *val, *p, prefix[50];
    guint i;

    h->method = NULL;
    h->uri    = NULL;
    h->header = head;
    
    if (req == NULL)
	return head;
    
    lines = g_strsplit( req, "\r\n", 0 );

    if (lines == NULL || lines[0] == NULL)
	return head;

    items = g_strsplit( lines[0], " ", 3 );

    h->method = g_strdup( items[0] );
    h->uri    = g_strdup( items[1] );
    // if (CONFd("Verbosity") >= 8) g_message( "http_parse_header: method_len: %d, uri_len: %d", strlen(h->method), strlen(h->uri));
    if (CONFd("Verbosity") >= 8) g_message( "http_parse_header: Method: %s", h->method );
    if (CONFd("Verbosity") >= 8) g_message( "http_parse_header: URI: %s", url_decode(h->uri) );
    g_strfreev( items );

    for (i = 1; lines[i] != NULL && lines[i][0] != '\0'; i++ ) {
	key = lines[i];
	val = strchr(key, ':');
	if (val != NULL) {
	    /* Separate the key from the value */
	    *val = '\0';

	    /* Normalize key -- lowercase every after 1st char */
	    for (p = key + 1; *p != '\0'; p++)
		*p = tolower(*p);

	    /* Strip ": " plus leading and trailing space from val */
	    g_strchomp( val += 2 ); // ": "

	    //if ( strcmp(key, "Referer" )== 0) {
	    //    if (CONFd("Verbosity") >= 8) g_message("http_parse_header: Referer: %s", url_decode(val) );
	    //} 
            //else {
	        if (CONFd("Verbosity") >= 8) {
                    g_snprintf(prefix, 50, "http_parse_header: %s: ", key);
                    syslog_message(prefix, url_decode(val), strlen(url_decode(val)) );
                }
	        g_hash_set( head, key, val );
	    //}
	}
    }

    g_strfreev( lines );
    h->header = head;
    return head;
}
Beispiel #8
0
/**
 * Parses the query string into parameters
 */
static void parse_parameters(multimap_t * const params, char * query_string)
{
  if (query_string) {
    size_t query_string_len = strlen(query_string);
    char * buf = query_string;
    char * end_buf = buf + query_string_len;
    char * key = NULL;
    size_t key_len = 0;
    char * value = NULL;
    size_t value_len = 0;

    while (buf < end_buf) {
      char * end = strpbrk(buf, "=&;#");
      size_t len = end ? end - buf : end_buf - buf;
      char next = end ? *end : 0;

      switch (next) {
        case '=': {
          key = buf;
          key_len = len;
        }
        break;

        case '&':
        case ';':
        case '#':
        case '\0': {
          if (key) {
            value = buf;
            value_len = len;
          } else {
            // key with no value
            key = buf;
            key_len = len;
            value = "";
            value_len = 0;
          }

          char * decoded_key = url_decode(key, key_len);
          char * decoded_value = url_decode(value, value_len);

          multimap_put(params, decoded_key, decoded_value);
          key = NULL;
          value = NULL;
        }
        break;
      }

      buf += len + 1;
    }
  }
}
static void http_auth_init(const char *url)
{
	char *at, *colon, *cp, *slash, *decoded;
	int len;

	cp = strstr(url, "://");
	if (!cp)
		return;

	/*
	 * Ok, the URL looks like "proto://something".  Which one?
	 * "proto://<user>:<pass>@<host>/...",
	 * "proto://<user>@<host>/...", or just
	 * "proto://<host>/..."?
	 */
	cp += 3;
	at = strchr(cp, '@');
	colon = strchr(cp, ':');
	slash = strchrnul(cp, '/');
	if (!at || slash <= at)
		return; /* No credentials */
	if (!colon || at <= colon) {
		/* Only username */
		len = at - cp;
		user_name = xmalloc(len + 1);
		memcpy(user_name, cp, len);
		user_name[len] = '\0';
		decoded = url_decode(user_name);
		free(user_name);
		user_name = decoded;
		user_pass = NULL;
	} else {
		len = colon - cp;
		user_name = xmalloc(len + 1);
		memcpy(user_name, cp, len);
		user_name[len] = '\0';
		decoded = url_decode(user_name);
		free(user_name);
		user_name = decoded;
		len = at - (colon + 1);
		user_pass = xmalloc(len + 1);
		memcpy(user_pass, colon + 1, len);
		user_pass[len] = '\0';
		decoded = url_decode(user_pass);
		free(user_pass);
		user_pass = decoded;
	}
}
Beispiel #10
0
int parseURL(ExHttp *pHttp)
{
	/* we should treat URL carefully to prevent security issues. */
	char *ePos = NULL;
	char *pBuf = pHttp->curPos;

	TRIM_HEAD(&pBuf);
	pHttp->url = pBuf;
	SKIP(&pBuf, ' ');
	TRIMI_LB_TAIL(pBuf);

	TRIM_HEAD(&pBuf);
	pHttp->protocol = pBuf;
	SKIP(&pBuf, '\n');
	TRIMI_LB_TAIL(pBuf);

	pHttp->curPos = pBuf;
	pHttp->queryString = NULL;
	if (*(pHttp->method) == 'G') {
		/* if URL is empty, take index file as default */
		if (*(pHttp->url) == '\0') {
			pHttp->url = (char *) IndexFile;
		}
		else if ((ePos = strchr(pHttp->url, '?')) != NULL) {
			*ePos = '\0';
			pHttp->queryString = ++ePos;
			pHttp->paramEndPos = find_lb_end(pHttp->protocol);
		}
	}
	/* convert URL to UTF-8 encoding */
	return url_decode(pHttp->url, pHttp->url, 0);
}
static std::string URLDecode(const std::string& url) {
	char* s = url_decode(url.c_str());
	std::string result = s;
	free(s);

	return result;
}
Beispiel #12
0
static int
parse_struct_info (unsigned char *where, size_t length, const char *start,
                   const char *end, P11KitUri *uri)
{
	unsigned char *value;
	size_t value_length;
	int ret;

	assert (start <= end);

	ret = url_decode (start, end, &value, &value_length);
	if (ret < 0)
		return ret;

	/* Too long, shouldn't match anything */
	if (value_length > length) {
		free (value);
		uri->unrecognized = 1;
		return 1;
	}

	memset (where, ' ', length);
	memcpy (where, value, value_length);

	free (value);
	return 1;
}
Beispiel #13
0
static int
parse_string_attribute (const char *name, const char *start, const char *end,
                        P11KitUri *uri)
{
	unsigned char *value;
	CK_ATTRIBUTE attr;
	size_t length;
	int ret;

	assert (start <= end);

	if (strcmp ("id", name) == 0)
		attr.type = CKA_ID;
	else if (strcmp ("object", name) == 0)
		attr.type = CKA_LABEL;
	else
		return 0;

	ret = url_decode (start, end, &value, &length);
	if (ret < 0)
		return ret;

	attr.pValue = value;
	attr.ulValueLen = length;
	uri_take_attribute (uri, &attr);
	return 1;
}
Beispiel #14
0
int main()
{ 
  formu.lu = 1;
  tt_nsconnect("ns-server.epita.fr", 4242, "EdzC*nO4", "poulai_f");
  /*tt_nsgetinfo("poulai_f");*/
  /*tt_nssendmsg("poulai_f", "si ce message apparaît, c'est gut");*/
  depart.lu = 0;
  depart.login = malloc(9);
  depart.msg = malloc(18);
  strcat(depart.login, "poulai_f");
  strcat(depart.msg, "teste de messageu");
  tt_nssendmsg("poulai_f", "tonku");
  
  while (1)
    {
      tt_nsverif(&formu, &depart);
      printf("pwet\n");
      if (!formu.lu)
	{
	  printf("\nMessage de %s:\n%s\n", formu.login, url_decode(formu.msg));
	  formu.lu = 1;
	}
      sleep(1);
    }
  return 0;
}
Beispiel #15
0
//Code to play a file. Only Gaya will understand this.
void gaya_auto_load(char *url_encoded_file) {

    char *file = url_decode(url_encoded_file);
    char *name = util_basename(file);

    printf("Content-Type: text/html\n\n");
    printf("<html><body onloadset=playme bgcolor=black text=white link=white >\n");
    //printf("<html><body >\n");

    printf("<br><a href=\"/oversight/oversight.cgi\">Oversight</a>\n");

    //char *back=get_self_link("","",name);
    //printf("<br>%s\n",back);
    //FREE(back);

    printf("<br><a href=\"/start.cgi\">Home</a>\n");

    printf("<hr><a href=\"file://%s\" %s onfocusload name=playme>Play %s</a>\n", // file://
            url_encoded_file,vod_attr(file),name);

    printf("</body></html>\n");

    FREE(file);
    FREE(name);
}
Beispiel #16
0
bool HttpConnection::onMessageBegin(const BufferRef& method, const BufferRef& uri, int versionMajor, int versionMinor)
{
	TRACE("onMessageBegin: '%s', '%s', HTTP/%d.%d", method.str().c_str(), uri.str().c_str(), versionMajor, versionMinor);

	request_->method = method;
	request_->uri = uri;
	url_decode(input_, request_->uri);

	std::size_t n = request_->uri.find("?");
	if (n != std::string::npos) {
		request_->path = request_->uri.ref(0, n);
		request_->query = request_->uri.ref(n + 1);
	} else {
		request_->path = request_->uri;
	}

	request_->httpVersionMajor = versionMajor;
	request_->httpVersionMinor = versionMinor;

	if (request_->supportsProtocol(1, 1))
		// FIXME? HTTP/1.1 is keeping alive by default. pass "Connection: close" to close explicitely
		setShouldKeepAlive(true);
	else
		setShouldKeepAlive(false);

	// limit request uri length
	if (request_->uri.size() > worker().server().maxRequestUriSize()) {
		request_->status = HttpError::RequestUriTooLong;
		request_->finish();
		return false;
	}

	return true;
}
void KConcatFetchObject::init(KHttpRequest *rq)
{
	assert(head==NULL);
	KConcatPath *cp = new KConcatPath;
	cp->path = strdup(rq->url->path);
	add(cp);
	assert(rq->url->param);
	char *buf = strdup(rq->url->param+1);
	url_decode(buf,0,NULL,false);
	char *param = buf;
	while (param) {
		char *p = strchr(param,',');
		if (p) {
			*p = '\0';
			p++;
		}
		if (*param) {
			cp = new KConcatPath;
			cp->path = strdup(param);
			add(cp);
		}
		param = p;
	}
	free(buf);
	hot = head;
}
Beispiel #18
0
char *XDG_GetStringValue(XDG_PARSED_FILE *file, const char *group_name, const char *value_name, DWORD dwFlags)
{
    PARSED_GROUP *group;
    PARSED_ENTRY *entry;

    for (group = file->groups; group; group = group->next)
    {
        if (!parsed_str_eq(&group->name, group_name))
            continue;

        for (entry = group->entries; entry; entry = entry->next)
            if (entry->name.str != NULL && parsed_str_eq(&entry->name, value_name))
            {
                int len;
                char *ret;
                
                len = dskentry_decode(entry->value.str, entry->value.len, NULL);
                ret = SHAlloc(len);
                if (ret == NULL) return NULL;
                dskentry_decode(entry->value.str, entry->value.len, ret);
                if (dwFlags & XDG_URLENCODE)
                    url_decode(ret, ret);
                return ret;
            }
    }
    
    return NULL;
}
Beispiel #19
0
int decode(char * inputStr, hashmap_t * map)
{
	char * pch, * tmp, * key, * value;
	char *saveptr1, *saveptr2;

	/* split input string */
	pch = strtok_r (inputStr," ", &saveptr1);
	while (pch != NULL)
	{
		/* url decode the part */
		tmp = url_decode(pch);

		key = strtok_r (tmp,":", &saveptr2);
		value = strtok_r (NULL,":", &saveptr2);

		/* put it into hashmap */
		if (hashmap_set(map,key,value) < 0)
		{
			fprintf(stderr,"can't set decode string into hashmap (%s/%s)\n",key,value);
			return -1;
		}

		/* continue */
		pch = strtok_r (NULL," ", &saveptr1);
	}
	return 0;
}
Beispiel #20
0
static void cgi_init_cookie()
{
	char * buf;
	char key[COOKIE_KEY_MAX];
	char value[COOKIE_VALUE_MAX];
	
	if((buf = getenv("COOKIE")) != NULL && *buf)
	{
		FILE * f = fopen(buf, "r");
		
		if(!f)
		{
			exit(EXIT_FAILURE);
		}
		
		has_cookie = 1;
		
		while(!feof(f))
		{
			fscanf(f, "%511s %8191s", key, value);
			
			char * decoded = url_decode(value);
			strcpy(value, decoded);
			free(decoded);
				
			prefix_tree_set(COOKIE, key, value);
		}
		
		fclose(f);
	}
}
Beispiel #21
0
const char *http_request_headers(int fd)
{
    static char buf[8192];      /* static variables are not on the stack */
    int i;
    char value[512];
    char envvar[512];

    /* For lab 2: don't remove this line. */
    touch("http_request_headers");

    /* Now parse HTTP headers */
    for (;;)
    {
        if (http_read_line(fd, buf, sizeof(buf)) < 0)
            return "Socket IO error";

        if (buf[0] == '\0')     /* end of headers */
            break;

        /* Parse things like "Cookie: foo bar" */
        char *sp = strchr(buf, ' ');
        if (!sp)
            return "Header parse error (1)";
        *sp = '\0';
        sp++;

        /* Strip off the colon, making sure it's there */
        if (strlen(buf) == 0)
            return "Header parse error (2)";

        char *colon = &buf[strlen(buf) - 1];
        if (*colon != ':')
            return "Header parse error (3)";
        *colon = '\0';

        /* Set the header name to uppercase and replace hyphens with underscores */
        for (i = 0; i < strlen(buf); i++) {
            buf[i] = toupper(buf[i]);
            if (buf[i] == '-')
                buf[i] = '_';
        }

        /* Decode URL escape sequences in the value */
        
        url_decode(value, sp);

        /* Store header in env. variable for application code */
        /* Some special headers don't use the HTTP_ prefix. */
        if (strcmp(buf, "CONTENT_TYPE") != 0 &&
            strcmp(buf, "CONTENT_LENGTH") != 0) {
            sprintf(envvar, "HTTP_%s", buf);
            setenv(envvar, value, 1);
        } else {
            setenv(buf, value, 1);
        }
    }

    return 0;
}
Beispiel #22
0
int handle_request(ClientConn client_conn)
{
    int error = 0;
    do {
        std::string request = client_conn.getData();
        key_value_t params;

        splitStringToMap(request, '&', '=', params);

        key_value_t::iterator iter = params.find("name");
        if (iter == params.end()) 
        {
            log_error("param error: miss 'name'");
            error = -1;
            break;
        }
        iter = params.find("age");
        if (iter == params.end()) 
        {
            log_error("param error: miss 'age'");
            error = -1;
            break;
        }

        std::string name = url_decode(params["name"]);
        std::string age = url_decode(params["age"]);

        MysqlRowSetPtr res = mysqlApi.query("SELECT age FROM es.lovers WHERE name='%s'", name.c_str());
        if (res.get() == NULL || !res->next()) {
            log_error("User '%s' NOT-FOUND", name.c_str());
            error = -1;
            break;
        }

        if (mysqlApi.update("UPDATE es.lovers SET age=%s WHERE name='%s'",  age.c_str(), name.c_str()) < 0) {
            log_error("update failed.");
            error = -2;
            break;
        }

    } while(0);

    send_reply(client_conn.getFD(), error ? "FAILED" : "SUCC");

    return error;
}
Beispiel #23
0
const std::string& LazyDecodedValue::string() const
{
    if (decoded_value_.empty())
    {
        decoded_value_ = url_decode(raw_value_.data(), raw_value_.end());
    }

    return decoded_value_;
}
Beispiel #24
0
/* Receives an HTTP request from socket SOCKFD and decodes it into KVREQ.
 * Returns false if there is an error. */
bool kvrequest_receive(kvrequest_t *kvreq, int sockfd) {
  bool success = false;
  kvreq->type = EMPTY;

  http_request_t req;
  url_params_t params;
  zero_params(&params);

  success = http_request_receive(&req, sockfd);
  if (!success)
    goto error;
  success = url_decode(&params, req.path);
  if (!success)
    goto error;

  switch (req.method) {
  case GET: {
    kvreq->type = is_empty_str(params.key) ? INDEX : GETREQ;
    break;
  }
  case PUT: {
    if (is_empty_str(params.key) || is_empty_str(params.val))
      goto error;
    kvreq->type = PUTREQ;
    break;
  }
  case DELETE: {
    if (is_empty_str(params.key))
      goto error;
    kvreq->type = DELREQ;
    break;
  }
  case POST: {
    if (is_empty_str(params.path))
      goto error;
    if (!strcmp(params.path, REGISTER_PATH)) {
      if (is_empty_str(params.key) || is_empty_str(params.val))
        goto error;
      kvreq->type = REGISTER;
    } else if (!strcmp(params.path, COMMIT_PATH)) {
      kvreq->type = COMMIT;
    } else if (!strcmp(params.path, ABORT_PATH)) {
      kvreq->type = ABORT;
    }
    break;
  }
  default:
    goto error;
  }
  strcpy(kvreq->key, params.key);
  strcpy(kvreq->val, params.val);

  return true;

error:
  return false;
}
Beispiel #25
0
void http_init(struct httpc *app, struct request **rpp, char *str_uri)
{
    int ok;
    struct request *request;
    struct pl pl_uri;
    struct url url;

    *rpp = NULL;

    pl_uri.p = NULL;
    str_dup((char**)&pl_uri.p, str_uri);
    pl_uri.l = strlen(str_uri);

    ok = url_decode(&url, &pl_uri);

    if(ok!=0)
        goto err_uri;

    request = mem_zalloc(sizeof(*request), destructor);
    ok = hash_alloc(&request->hdrht, HDR_HASH_SIZE);
    request->err_h = dummy_err;
    request->done_h = http_done;
    request->post = NULL;
    request->form = 0;
    request->www_auth.p = NULL;
    request->www_auth.l = 0;
    request->auth = NULL;

    request->retry = 0;

    pl_strdup(&request->host, &url.host);
    pl_strdup(&request->path, &url.path);
    request->secure = !pl_strcmp(&url.scheme, "https");
    memcpy(&request->meth, "GET", 4);
    request->meth[4] = 0;

    if(url.port)
	request->port = url.port;
    else
        request->port = request->secure ? 443 : 80;

    DEBUG_INFO("secure: %d port %d\n", request->secure, request->port);
    sa_init(&request->dest, AF_INET);
    ok = sa_set_str(&request->dest, request->host, request->port);

    request->state = ok ? START : RESOLVED;

    request->app = app;
    *rpp = request;

err_uri:
    if(pl_uri.p)
        mem_deref((void*)pl_uri.p);

    return;
}
Beispiel #26
0
int main(int argc, char **argv)
{
	struct strbuf buf = STRBUF_INIT, url_sb = STRBUF_INIT,
			private_ref_sb = STRBUF_INIT, marksfilename_sb = STRBUF_INIT,
			notes_ref_sb = STRBUF_INIT;
	static struct remote *remote;
	const char *url_in;

	git_extract_argv0_path(argv[0]);
	setup_git_directory();
	if (argc < 2 || argc > 3) {
		usage("git-remote-svn <remote-name> [<url>]");
		return 1;
	}

	remote = remote_get(argv[1]);
	url_in = (argc == 3) ? argv[2] : remote->url[0];

	if (starts_with(url_in, "file://")) {
		dump_from_file = 1;
		url = url_decode(url_in + sizeof("file://")-1);
	} else {
		dump_from_file = 0;
		end_url_with_slash(&url_sb, url_in);
		url = url_sb.buf;
	}

	strbuf_addf(&private_ref_sb, "refs/svn/%s/master", remote->name);
	private_ref = private_ref_sb.buf;

	strbuf_addf(&notes_ref_sb, "refs/notes/%s/revs", remote->name);
	notes_ref = notes_ref_sb.buf;

	strbuf_addf(&marksfilename_sb, "%s/info/fast-import/remote-svn/%s.marks",
		get_git_dir(), remote->name);
	marksfilename = marksfilename_sb.buf;

	while (1) {
		if (strbuf_getline(&buf, stdin, '\n') == EOF) {
			if (ferror(stdin))
				die("Error reading command stream");
			else
				die("Unexpected end of command stream");
		}
		if (do_command(&buf))
			break;
		strbuf_reset(&buf);
	}

	strbuf_release(&buf);
	strbuf_release(&url_sb);
	strbuf_release(&private_ref_sb);
	strbuf_release(&notes_ref_sb);
	strbuf_release(&marksfilename_sb);
	return 0;
}
Beispiel #27
0
struct curl_httppost *multipartform(const char *url)
{
    struct curl_httppost *formpost = NULL;
    struct curl_httppost *lastptr = NULL;

    char *temp = strrchr(url, '?');
    char *begin = url_decode(temp);
    char *mid = NULL;

    char *name, *value;
    char *file, *path;

    /* Fill in the filename field */
    do
    {
        mid = strchr(begin, '=');
        begin++;
        name = strndup(begin, mid-begin);

        begin = strchr(begin, '&');
        mid++;

        if (!begin)
            value = strdup(mid);
        else value = strndup(mid, begin-mid);

        if(strstr(value, "_UPLOAD"))
        {
            path = strrchr(value, '_');
            file = strndup(value, path-value);

            curl_formadd(&formpost,
                &lastptr,
                CURLFORM_COPYNAME, name,
                CURLFORM_FILE, file,
                CURLFORM_END);

            free(file);
        }
        else
        {
            curl_formadd(&formpost,
                &lastptr,
                CURLFORM_COPYNAME, name,
                CURLFORM_COPYCONTENTS, value,
                CURLFORM_END);
        }

        free(name);
        free(value);
    }
    while (begin);

    free(begin);
    return formpost;
}
Beispiel #28
0
void HttpProtocol::DecodeCookies(Variant &variables, char *data) {
  ASSERT(data && *data);

  char *strtok_buf = NULL;
  char *var = strtok_r(data, ";", &strtok_buf);
  while (var) {
    char *val = strchr(var, '=');

    // Remove leading spaces from cookie names, needed for multi-cookie
    // header where ; can be followed by a space */
    while (isspace(*var)) {
      var++;
    }

    if (var != val && *var != '\0') {
      if (val) { /* have a value */
        int len = val - var;
        char *name = url_decode(var, len);
        String sname(name, len, AttachString);

        ++val;
        len = strlen(val);
        char *value = url_decode(val, len);
        if (RuntimeOption::EnableMagicQuotesGpc) {
          char *slashedvalue = string_addslashes(value, len);
          free(value);
          value = slashedvalue;
        }
        String svalue(value, len, AttachString);

        register_variable(variables, (char*)sname.data(), svalue, false);
      } else {
        int len = strlen(var);
        char *name = url_decode(var, len);
        String sname(name, len, AttachString);

        register_variable(variables, (char*)sname.data(), "", false);
      }
    }

    var = strtok_r(NULL, ";", &strtok_buf);
  }
}
String StringUtil::UrlDecode(CStrRef input, bool decodePlus /* = true */) {
  int len = input.size();
  char *ret;
  if (decodePlus) {
    ret = url_decode(input.data(), len);
  } else {
    ret = url_raw_decode(input.data(), len);
  }
  return String(ret, len, AttachString);
}
Beispiel #30
0
int main(void)
{
	char buf[] = "you%20are%20good%3b%3b";

	assert(url_decode(buf, strlen(buf)) == 14);
	printf("%s\n", buf);
	printf("%d\n", if_get_mtu("en1"));

	return 0;
}