}
-/**
- * convert integer to string representation
- *
- * @param i integer
- * @return the character
- */
-static char
-i_to_hexchar (unsigned char i)
-{
- static char hexmap[] = "0123456789abcdef";
-
- GNUNET_assert (sizeof (hexmap) > (i & 15));
- return hexmap[i & 15];
-}
-
-
-/**
-// FIXME: use cURL API
- * Escape given 0-terminated string
- *
- * @param to_esc string to escapse
- * @return allocated new escaped string (MUST free!)
- */
-static char*
-escape_to_urlenc (const char *to_esc)
-{
- char *pos = (char*)to_esc;
- char *res = GNUNET_malloc (strlen (to_esc) * 3 + 1);
- char *rpos = res;
-
- while ('\0' != *pos)
- {
- if (isalnum (*pos) ||
- ('-' == *pos) || ('_' == *pos) ||
- ('.' == *pos) || ('~' == *pos))
- *rpos++ = *pos;
- else if (' ' == *pos)
- *rpos++ = '+';
- else
- {
- *rpos++ = '%';
- *rpos++ = i_to_hexchar (*pos >> 4);
- *rpos++ = i_to_hexchar (*pos >> 15);
- }
- pos++;
- }
- *rpos = '\0';
- return res;
-}
-
-
static int
con_post_data_iter (void *cls,
enum MHD_ValueKind kind,
if (0 == off)
{
+ enc = curl_easy_escape (ctask->curl, key, 0);
+ if (NULL == enc)
+ {
+ GNUNET_break (0);
+ return MHD_NO;
+ }
/* a key */
pdata = GNUNET_malloc (sizeof (struct ProxyUploadData));
- enc = escape_to_urlenc (key);
pdata->value = GNUNET_malloc (strlen (enc) + 3);
if (NULL != ctask->upload_data_head)
{
pdata->value[strlen (pdata->value)] = '=';
pdata->bytes_left = strlen (pdata->value);
pdata->total_bytes = pdata->bytes_left;
- GNUNET_free (enc);
+ curl_free (enc);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Escaped POST key: '%s'\n",
}
/* a value */
+ enc = curl_easy_escape (ctask->curl, data, 0);
+ if (NULL == enc)
+ {
+ GNUNET_break (0);
+ return MHD_NO;
+ }
pdata = GNUNET_malloc (sizeof (struct ProxyUploadData));
- enc = escape_to_urlenc (data);
pdata->value = GNUNET_malloc (strlen (enc) + 1);
memcpy (pdata->value, enc, strlen (enc));
pdata->bytes_left = strlen (pdata->value);
pdata->total_bytes = pdata->bytes_left;
- GNUNET_free (enc);
+ curl_free (enc);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Escaped POST value: '%s'\n",
run_mhd_now (ctask->mhd);
}
+
/**
* Handle data from cURL
*
struct ProxyCurlTask *ctask;
int num_ctasks;
long resp_code;
-
struct ProxyCurlTask *clean_head = NULL;
struct ProxyCurlTask *clean_tail = NULL;
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Shutdown requested while trying to download\n");
- //TODO cleanup
- return;
+ //TODO cleanup
+ return;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Ready to dl\n");
len);
}
else
- {
-
+ {
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "write");
s5r->cleanup = GNUNET_YES;
s5r->cleanup_sock = GNUNET_YES;
- cleanup_s5r (s5r);
-
+ cleanup_s5r (s5r);
return;
}
struct Socks5Request *s5r = cls;
s5r->fwdrtask = GNUNET_SCHEDULER_NO_TASK;
-
-
if ((NULL != tc->write_ready) &&
(GNUNET_NETWORK_fdset_isset (tc->read_ready, s5r->remote_sock)) &&
(s5r->wbuf_len = GNUNET_NETWORK_socket_recv (s5r->remote_sock, s5r->wbuf,
}
else
{
- if (s5r->wbuf_len == 0)
+ if (0 == s5r->wbuf_len)
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"0 bytes received from remote... graceful shutdown!\n");
if (s5r->fwdwtask != GNUNET_SCHEDULER_NO_TASK)
s5r->wtask = GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
s5r->sock,
- &do_write, s5r);
-
+ &do_write, s5r);
}
static int
add_handle_to_ssl_mhd (struct GNUNET_NETWORK_Handle *h, const char* domain)
{
- struct MhdHttpList *hd = NULL;
+ struct MhdHttpList *hd;
struct ProxyGNSCertificate *pgc;
struct NetworkHandleList *nh;
struct socks5_server_hello *s_hello;
struct socks5_client_request *c_req;
struct socks5_server_response *s_resp;
-
int ret;
char domain[256];
uint8_t dom_len;
uint32_t remote_ip;
struct sockaddr_in remote_addr;
struct in_addr *r_sin_addr;
-
struct NetworkHandleList *nh;
s5r->rtask = GNUNET_SCHEDULER_NO_TASK;
do_shutdown (void *cls,
const struct GNUNET_SCHEDULER_TaskContext *tc)
{
-
struct MhdHttpList *hd;
struct MhdHttpList *tmp_hd;
struct NetworkHandleList *nh;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Shutting down...\n");
-
- gnutls_global_deinit ();
-
if (NULL != local_gns_zone)
GNUNET_free (local_gns_zone);
if (NULL != local_private_zone)
GNUNET_SCHEDULER_cancel (hd->httpd_task);
hd->httpd_task = GNUNET_SCHEDULER_NO_TASK;
}
-
if (NULL != hd->daemon)
{
MHD_stop_daemon (hd->daemon);
hd->daemon = NULL;
}
-
for (nh = hd->socket_handles_head; nh != NULL; nh = tmp_nh)
{
tmp_nh = nh->next;
GNUNET_free_non_null (pdata->value);
GNUNET_free (pdata);
}
-
GNUNET_free (ctask);
}
curl_multi_cleanup (curl_multi);
-
GNUNET_GNS_disconnect (gns_handle);
+ gnutls_global_deinit ();
}
load_local_zone_key (const struct GNUNET_CONFIGURATION_Handle *cfg)
{
char *keyfile;
- struct GNUNET_CRYPTO_RsaPrivateKey *key = NULL;
+ struct GNUNET_CRYPTO_RsaPrivateKey *key;
struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey;
- struct GNUNET_CRYPTO_ShortHashCode *zone = NULL;
+ struct GNUNET_CRYPTO_ShortHashCode *zone;
struct GNUNET_CRYPTO_ShortHashAsciiEncoded zonename;
if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns",
struct sockaddr_un mhd_unix_sock_addr;
#endif
- curl_multi = curl_multi_init ();
-
- if (NULL == curl_multi)
+ if (NULL == (curl_multi = curl_multi_init ()))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to create cURL multo handle!\n");
if (NULL == cafile)
{
if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns-proxy",
- "PROXY_CACERT",
- &cafile_cfg))
+ "PROXY_CACERT",
+ &cafile_cfg))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unable to load proxy CA config value!\n");
compile_regex (&re_dotplus, (char*) RE_A_HREF);
- gns_handle = GNUNET_GNS_connect (cfg);
-
- if (GNUNET_NO == load_local_zone_key (cfg))
+ if (NULL == (gns_handle = GNUNET_GNS_connect (cfg)))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unable to load zone!\n");
+ "Unable to connect to GNS!\n");
return;
}
-
- if (NULL == gns_handle)
+ if (GNUNET_NO == load_local_zone_key (cfg))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unable to connect to GNS!\n");
+ "Unable to load zone!\n");
return;
}
"Specify PROXY_UNIXPATH in gns-proxy config section!\n");
return;
}
-
- mhd_unix_socket = GNUNET_NETWORK_socket_create (AF_UNIX,
- SOCK_STREAM,
- 0);
-
- if (NULL == mhd_unix_socket)
+ if (NULL == (mhd_unix_socket = GNUNET_NETWORK_socket_create (AF_UNIX,
+ SOCK_STREAM,
+ 0)))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unable to create unix domain socket!\n");
#endif
len = strlen (proxy_sockfile) + sizeof(AF_UNIX);
-
GNUNET_free (proxy_sockfile);
if (GNUNET_OK != GNUNET_NETWORK_socket_bind (mhd_unix_socket,