Esempio n. 1
0
static void
test_evutil_strtoll(void *ptr)
{
	const char *s;
	char *endptr;

	tt_want(evutil_strtoll("5000000000", NULL, 10) ==
		((ev_int64_t)5000000)*1000);
	tt_want(evutil_strtoll("-5000000000", NULL, 10) ==
		((ev_int64_t)5000000)*-1000);
	s = " 99999stuff";
	tt_want(evutil_strtoll(s, &endptr, 10) == (ev_int64_t)99999);
	tt_want(endptr == s+6);
	tt_want(evutil_strtoll("foo", NULL, 10) == 0);
 }
Esempio n. 2
0
/**
 * The initial i and trailing e are beginning and ending delimiters.
 * You can have negative numbers such as i-3e. You cannot prefix the
 * number with a zero such as i04e. However, i0e is valid.
 * Example: i3e represents the integer "3"
 * NOTE: The maximum number of bit of this integer is unspecified,
 * but to handle it as a signed 64bit integer is mandatory to handle
 * "large files" aka .torrent for more that 4Gbyte
 */
int
tr_bencParseInt (const uint8_t  * buf,
                 const uint8_t  * bufend,
                 const uint8_t ** setme_end,
                 int64_t        * setme_val)
{
  char * endptr;
  const void * begin;
  const void * end;
  int64_t val;

  if (buf >= bufend)
    return EILSEQ;
  if (*buf != 'i')
    return EILSEQ;

  begin = buf + 1;
  end = memchr (begin, 'e', (bufend - buf) - 1);
  if (end == NULL)
    return EILSEQ;

  errno = 0;
  val = evutil_strtoll (begin, &endptr, 10);
  if (errno || (endptr != end)) /* incomplete parse */
    return EILSEQ;
  if (val && * (const char*)begin == '0') /* no leading zeroes! */
    return EILSEQ;

  *setme_end = (const uint8_t*)end + 1;
  *setme_val = val;
  return 0;
}
Esempio n. 3
0
File: util.c Progetto: Phoul/shim
ev_int64_t
get_int(const char *buf, int base)
{
	char *endp;
	ev_int64_t rv;

	rv = evutil_strtoll(buf, &endp, base);
	// XXX
	//
	
	return rv;
}
Esempio n. 4
0
// read HTTP headers
// return TRUE if all haders are read, FALSE if not enough data
static gboolean s3http_client_parse_headers (S3HttpClient *http, struct evbuffer *input_buf)
{
    size_t line_length = 0;
    char *line = NULL;
    S3HttpClientHeader *header;

	while ((line = evbuffer_readln (input_buf, &line_length, EVBUFFER_EOL_CRLF)) != NULL) {
		char *skey, *svalue;
        
        // the last line
		if (*line == '\0') {
			g_free (line);
			return TRUE;
		}

     //   LOG_debug (HTTP_LOG, "HEADER line: %s\n", line);

		svalue = line;
		skey = strsep (&svalue, ":");
		if (svalue == NULL) {
            LOG_debug (HTTP_LOG, "Wrong header data received !");
	        g_free (line);
			return FALSE;
        }

		svalue += strspn (svalue, " ");

        header = g_new0 (S3HttpClientHeader, 1);
        header->key = g_strdup (skey);
        header->value = g_strdup (svalue);
        http->l_input_headers = g_list_append (http->l_input_headers, header);
        
        if (!strcmp (skey, "Content-Length")) {
            char *endp;
		    http->input_length = evutil_strtoll (svalue, &endp, 10);
		    if (*svalue == '\0' || *endp != '\0') {
                LOG_debug (HTTP_LOG, "Illegal content length: %s", svalue);
                http->input_length = 0;
            }
        }

        g_free (line);        
    }
    LOG_debug (HTTP_LOG, "Wrong header line: %s", line);

    // if we are here - not all headers have been received !
    return FALSE;
}
Esempio n. 5
0
File: tun.c Progetto: nizox/hub
int
tnt_tun_iface_set_ipv4(struct tnt_tun *tun, char const *ipaddr) {
  int ret = -1;
  char *addr, *ptr;
  short netbits = 24;

  addr = strdup(ipaddr);
  if (addr == NULL)
    return (-1);
  ptr = strchr(addr, '/');
  if (ptr != NULL) {
    netbits = (short) evutil_strtoll(ptr + 1, NULL, 10);
    if (netbits < 1 || netbits > 32) {
      goto fail;
    }
    *ptr = '\0';
  }
  ret = tapcfg_iface_set_ipv4(tun->handle, addr, netbits);
fail:
  free(addr);
  return (ret);
}