Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
+/**
+ * @author Martin Schanzenbach
+ * @file src/gns/gnunet-gns-proxy.c
+ * @brief HTTP(S) proxy that rewrites URIs and fakes certificats to make GADS work
+ * with legacy browsers
+ */
#include "platform.h"
#include <microhttpd.h>
#include <curl/curl.h>
char* buf,
size_t max);
+
/**
* Check HTTP response header for mime
*
MHD_HTTP_HEADER_SET_COOKIE,
cookie_hdr_len))
{
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Looking for cookie in: `%s'\n", hdr_generic);
ndup = GNUNET_strdup (hdr_generic+cookie_hdr_len+1);
memset (new_cookie_hdr, 0, sizeof (new_cookie_hdr));
- tok = strtok (ndup, ";");
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Looking for cookie in : %s\n", hdr_generic);
-
- for (; tok != NULL; tok = strtok (NULL, ";"))
+ for (tok = strtok (ndup, ";"); tok != NULL; tok = strtok (NULL, ";"))
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Got Cookie token: %s\n", tok);
return bytes;
}
+
/**
* schedule mhd
*
static void
run_httpds (void);
+
/**
* Task run whenever HTTP server operations are pending.
*
do_httpd (void *cls,
const struct GNUNET_SCHEDULER_TaskContext *tc);
+
static void
run_mhd_now (struct MhdHttpList *hd)
{
hd->httpd_task = GNUNET_SCHEDULER_add_now (&do_httpd, hd);
}
+
/**
* Ask cURL for the select sets and schedule download
*/
static void
curl_download_prepare (void);
+
/**
* Callback to free content
*
return to_copy;
}
+
/**
* Task that is run when we are ready to receive more data
* from curl
static void
curl_task_download (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
+
/**
* Ask cURL for the select sets and schedule download
*/
FD_ZERO (&rs);
FD_ZERO (&ws);
FD_ZERO (&es);
- mret = curl_multi_fdset (curl_multi, &rs, &ws, &es, &max);
-
- if (mret != CURLM_OK)
+ if (CURLM_OK != (mret = curl_multi_fdset (curl_multi, &rs, &ws, &es, &max)))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"%s failed at %s:%d: `%s'\n",
//TODO cleanup here?
return;
}
-
- mret = curl_multi_timeout (curl_multi, &to);
- rtime = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, to);
-
+ to = -1;
+ GNUNET_break (CURLM_OK == curl_multi_timeout (curl_multi, &to));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "cURL multi fds: max=%d timeout=%llu\n", max, to);
-
+ "cURL multi fds: max=%d timeout=%lld\n", max, (long long) to);
+ if (-1 == to)
+ rtime = GNUNET_TIME_UNIT_FOREVER_REL;
+ else
+ rtime = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, to);
grs = GNUNET_NETWORK_fdset_create ();
gws = GNUNET_NETWORK_fdset_create ();
GNUNET_NETWORK_fdset_copy_native (grs, &rs, max + 1);
GNUNET_NETWORK_fdset_copy_native (gws, &ws, max + 1);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Scheduling task cURL\n");
-
if (curl_download_task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel (curl_download_task);
-
+ GNUNET_SCHEDULER_cancel (curl_download_task);
if (-1 != max)
{
curl_download_task =
}
+
/**
* Initialize download and trigger curl
*
ctask);
}
+
static void*
mhd_log_callback (void* cls, const char* url)
{
}
-
/**
* Read data from socket
*
static void
do_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
+
/**
* Read from remote end
*
static void
do_read_remote (void* cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
+
/**
* Write data to remote socket
*
GNUNET_free(s5r);
}
+
/**
* Write data to socket
*
&do_read_remote, s5r);
}
+
/**
* Read from remote end
*
return MHD_add_connection (daemon, fd, addr, len);
}
+
/**
* Read file in filename
*
}
-/*
+/**
* Accept policy for mhdaemons
*
* @param cls NULL
}
-
/**
* Read data from incoming connection
*
s5r->remote_sock,
&do_read_remote, s5r);
}
-
-
}
-
}
return GNUNET_YES;
}
+
/**
* Main function that will be run
*
GNUNET_a2s ((const struct sockaddr *) &sa, sizeof (sa)));
return;
}
-
ltask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
lsock, &do_accept, NULL);
- ctasks_head = NULL;
- ctasks_tail = NULL;
-
if (0 != curl_global_init (CURL_GLOBAL_WIN32))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Proxy listens on port %u\n",
port);
-
- mhd_httpd_head = NULL;
- mhd_httpd_tail = NULL;
- total_mhd_connections = 0;
#if ! HAVE_MHD_NO_LISTEN_SOCKET
if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns-proxy",
"PROXY_UNIXPATH",
MHD_OPTION_URI_LOG_CALLBACK, &mhd_log_callback, NULL,
MHD_OPTION_END);
#endif
-
- GNUNET_assert (httpd != NULL);
+ GNUNET_break (httpd != NULL);
hd->daemon = httpd;
hd->httpd_task = GNUNET_SCHEDULER_NO_TASK;
-
GNUNET_CONTAINER_DLL_insert (mhd_httpd_head, mhd_httpd_tail, hd);
-
run_httpds ();
-
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
&do_shutdown, NULL);
-
}
&GNUNET_GETOPT_set_string, &cafile_opt},
GNUNET_GETOPT_OPTION_END
};
-
int ret;
if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
return 2;
-
-
GNUNET_log_setup ("gnunet-gns-proxy", "WARNING", NULL);
ret =
(GNUNET_OK ==
_("GNUnet GNS proxy"),
options,
&run, NULL)) ? 0 : 1;
- GNUNET_free_non_null ((char*)argv);
-
+ GNUNET_free_non_null ((char *) argv);
return ret;
}
-
-
-
+/* end of gnunet-gns-proxy.c */