aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2012-07-12 16:10:25 +0000
committerMartin Schanzenbach <mschanzenbach@posteo.de>2012-07-12 16:10:25 +0000
commit88f513fd13ba4f0746fe967948f72f969e833f37 (patch)
treee911a931c5849d35dfd379ff958bd50a4664ec19 /src
parent1fddb8b6a805f84e16915f20a068ede483043156 (diff)
downloadgnunet-88f513fd13ba4f0746fe967948f72f969e833f37.tar.gz
gnunet-88f513fd13ba4f0746fe967948f72f969e833f37.zip
-broken
Diffstat (limited to 'src')
-rw-r--r--src/gns/gnunet-gns-proxy.c80
1 files changed, 53 insertions, 27 deletions
diff --git a/src/gns/gnunet-gns-proxy.c b/src/gns/gnunet-gns-proxy.c
index fadb4cfe2..eeef1a8a2 100644
--- a/src/gns/gnunet-gns-proxy.c
+++ b/src/gns/gnunet-gns-proxy.c
@@ -765,17 +765,19 @@ mhd_content_cb (void *cls,
765 struct ProxyCurlTask *ctask = cls; 765 struct ProxyCurlTask *ctask = cls;
766 struct ProxyREMatch *re_match = ctask->pp_match_head; 766 struct ProxyREMatch *re_match = ctask->pp_match_head;
767 ssize_t copied = 0; 767 ssize_t copied = 0;
768 size_t bytes_to_copy = ctask->buffer_write_ptr - ctask->buffer_read_ptr; 768 long long int bytes_to_copy = ctask->buffer_write_ptr - ctask->buffer_read_ptr;
769 769
770 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 770 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
771 "MHD: content cb for %s\n", ctask->url); 771 "MHD: content cb for %s. To copy: %lld\n",
772 ctask->url, bytes_to_copy);
773 GNUNET_assert (bytes_to_copy >= 0);
772 774
773 if ((GNUNET_YES == ctask->download_is_finished) && 775 if ((GNUNET_YES == ctask->download_is_finished) &&
774 (GNUNET_NO == ctask->download_error) && 776 (GNUNET_NO == ctask->download_error) &&
775 (0 == bytes_to_copy) && 777 (0 == bytes_to_copy) &&
776 (BUF_WAIT_FOR_CURL == ctask->buf_status)) 778 (BUF_WAIT_FOR_CURL == ctask->buf_status))
777 { 779 {
778 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 780 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
779 "MHD: sending response for %s\n", ctask->url); 781 "MHD: sending response for %s\n", ctask->url);
780 ctask->download_in_progress = GNUNET_NO; 782 ctask->download_in_progress = GNUNET_NO;
781 run_mhd_now (ctask->mhd); 783 run_mhd_now (ctask->mhd);
@@ -789,7 +791,7 @@ mhd_content_cb (void *cls,
789 (0 == bytes_to_copy) && 791 (0 == bytes_to_copy) &&
790 (BUF_WAIT_FOR_CURL == ctask->buf_status)) 792 (BUF_WAIT_FOR_CURL == ctask->buf_status))
791 { 793 {
792 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 794 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
793 "MHD: sending error response\n"); 795 "MHD: sending error response\n");
794 ctask->download_in_progress = GNUNET_NO; 796 ctask->download_in_progress = GNUNET_NO;
795 run_mhd_now (ctask->mhd); 797 run_mhd_now (ctask->mhd);
@@ -807,14 +809,12 @@ mhd_content_cb (void *cls,
807 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 809 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
808 "MHD: Processing PP %s\n", 810 "MHD: Processing PP %s\n",
809 re_match->hostname); 811 re_match->hostname);
810 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
811 "re start %d\n",
812 re_match->start);
813 bytes_to_copy = re_match->start - ctask->buffer_read_ptr; 812 bytes_to_copy = re_match->start - ctask->buffer_read_ptr;
813 GNUNET_assert (bytes_to_copy >= 0);
814 814
815 if (bytes_to_copy+copied > max) 815 if (bytes_to_copy+copied > max)
816 { 816 {
817 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 817 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
818 "MHD: buffer in response too small for %d. Using available space (%d). (%s)\n", 818 "MHD: buffer in response too small for %d. Using available space (%d). (%s)\n",
819 bytes_to_copy, 819 bytes_to_copy,
820 max, 820 max,
@@ -822,12 +822,12 @@ mhd_content_cb (void *cls,
822 memcpy (buf+copied, ctask->buffer_read_ptr, max-copied); 822 memcpy (buf+copied, ctask->buffer_read_ptr, max-copied);
823 ctask->buffer_read_ptr += max-copied; 823 ctask->buffer_read_ptr += max-copied;
824 copied = max; 824 copied = max;
825 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 825 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
826 "MHD: copied %d bytes\n", copied); 826 "MHD: copied %d bytes\n", copied);
827 return copied; 827 return copied;
828 } 828 }
829 829
830 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 830 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
831 "MHD: copying %d bytes to mhd response at offset %d\n", 831 "MHD: copying %d bytes to mhd response at offset %d\n",
832 bytes_to_copy, ctask->buffer_read_ptr); 832 bytes_to_copy, ctask->buffer_read_ptr);
833 memcpy (buf+copied, ctask->buffer_read_ptr, bytes_to_copy); 833 memcpy (buf+copied, ctask->buffer_read_ptr, bytes_to_copy);
@@ -835,9 +835,9 @@ mhd_content_cb (void *cls,
835 835
836 if (GNUNET_NO == re_match->done) 836 if (GNUNET_NO == re_match->done)
837 { 837 {
838 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 838 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
839 "MHD: Waiting for PP of %s\n", re_match->hostname); 839 "MHD: Waiting for PP of %s\n", re_match->hostname);
840 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 840 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
841 "MHD: copied %d bytes\n", copied); 841 "MHD: copied %d bytes\n", copied);
842 ctask->buffer_read_ptr += bytes_to_copy; 842 ctask->buffer_read_ptr += bytes_to_copy;
843 return copied; 843 return copied;
@@ -845,6 +845,7 @@ mhd_content_cb (void *cls,
845 845
846 if (strlen (re_match->result) > (max - copied)) 846 if (strlen (re_match->result) > (max - copied))
847 { 847 {
848 //FIXME partially copy domain here
848 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 849 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
849 "MHD: buffer in response too small for %s! (%s)\n", 850 "MHD: buffer in response too small for %s! (%s)\n",
850 re_match->result, 851 re_match->result,
@@ -861,9 +862,6 @@ mhd_content_cb (void *cls,
861 memcpy (buf+copied, re_match->result, strlen (re_match->result)); 862 memcpy (buf+copied, re_match->result, strlen (re_match->result));
862 copied += strlen (re_match->result); 863 copied += strlen (re_match->result);
863 ctask->buffer_read_ptr = re_match->end; 864 ctask->buffer_read_ptr = re_match->end;
864 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
865 "Setting buffer ptr to re end %d\n",
866 re_match->end);
867 GNUNET_CONTAINER_DLL_remove (ctask->pp_match_head, 865 GNUNET_CONTAINER_DLL_remove (ctask->pp_match_head,
868 ctask->pp_match_tail, 866 ctask->pp_match_tail,
869 re_match); 867 re_match);
@@ -871,7 +869,14 @@ mhd_content_cb (void *cls,
871 } 869 }
872 870
873 bytes_to_copy = ctask->buffer_write_ptr - ctask->buffer_read_ptr; 871 bytes_to_copy = ctask->buffer_write_ptr - ctask->buffer_read_ptr;
872
873 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
874 "MHD: copied: %d left: %d, space left in buf: %d\n",
875 copied,
876 bytes_to_copy, max-copied);
874 877
878 GNUNET_assert (0 <= bytes_to_copy);
879
875 if (GNUNET_NO == ctask->download_is_finished) 880 if (GNUNET_NO == ctask->download_is_finished)
876 { 881 {
877 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 882 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -893,9 +898,10 @@ mhd_content_cb (void *cls,
893 ctask->buf_status = BUF_WAIT_FOR_CURL; 898 ctask->buf_status = BUF_WAIT_FOR_CURL;
894 899
895 if ((NULL != ctask->curl) && 900 if ((NULL != ctask->curl) &&
896 (GNUNET_NO == ctask->download_is_finished)) 901 (GNUNET_NO == ctask->download_is_finished) &&
902 ((ctask->buffer_write_ptr - ctask->buffer_read_ptr) <= 0))
897 curl_easy_pause (ctask->curl, CURLPAUSE_CONT); 903 curl_easy_pause (ctask->curl, CURLPAUSE_CONT);
898 904
899 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 905 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
900 "MHD: copied %d bytes\n", copied); 906 "MHD: copied %d bytes\n", copied);
901 run_mhd_now (ctask->mhd); 907 run_mhd_now (ctask->mhd);
@@ -912,6 +918,7 @@ static void
912process_shorten (void* cls, const char* short_name) 918process_shorten (void* cls, const char* short_name)
913{ 919{
914 struct ProxyREMatch *re_match = cls; 920 struct ProxyREMatch *re_match = cls;
921 char result[sizeof (re_match->result)];
915 922
916 if (NULL == short_name) 923 if (NULL == short_name)
917 { 924 {
@@ -925,15 +932,20 @@ process_shorten (void* cls, const char* short_name)
925 return; 932 return;
926 } 933 }
927 934
935 if (0 == strcmp (short_name, re_match->ctask->leho))
936 strcpy (result, re_match->ctask->host);
937 else
938 strcpy (result, short_name);
939
928 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 940 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
929 "PP: Shorten %s -> %s\n", 941 "PP: Shorten %s -> %s\n",
930 re_match->hostname, 942 re_match->hostname,
931 short_name); 943 result);
932 //this is evil.. what about https 944 //this is evil.. what about https
933 if (re_match->ctask->mhd->is_ssl) 945 if (re_match->ctask->mhd->is_ssl)
934 sprintf (re_match->result, "href=\"https://%s", short_name); 946 sprintf (re_match->result, "href=\"https://%s", result);
935 else 947 else
936 sprintf (re_match->result, "href=\"http://%s", short_name); 948 sprintf (re_match->result, "href=\"http://%s", result);
937 949
938 re_match->done = GNUNET_YES; 950 re_match->done = GNUNET_YES;
939 run_mhd_now (re_match->ctask->mhd); 951 run_mhd_now (re_match->ctask->mhd);
@@ -986,6 +998,8 @@ postprocess_buffer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
986 re_match->done = GNUNET_NO; 998 re_match->done = GNUNET_NO;
987 re_match->ctask = ctask; 999 re_match->ctask = ctask;
988 strcpy (re_match->hostname, re_hostname); 1000 strcpy (re_match->hostname, re_hostname);
1001 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1002 "Got hostname %s\n", re_hostname);
989 re_ptr += m[3].rm_eo; 1003 re_ptr += m[3].rm_eo;
990 1004
991 if (GNUNET_YES == is_tld (re_match->hostname, GNUNET_GNS_TLD_PLUS)) 1005 if (GNUNET_YES == is_tld (re_match->hostname, GNUNET_GNS_TLD_PLUS))
@@ -1027,11 +1041,15 @@ curl_download_cb (void *ptr, size_t size, size_t nmemb, void* ctx)
1027 size_t buf_space = sizeof (ctask->buffer) - 1041 size_t buf_space = sizeof (ctask->buffer) -
1028 (ctask->buffer_write_ptr-ctask->buffer); 1042 (ctask->buffer_write_ptr-ctask->buffer);
1029 1043
1044 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1045 "CURL: Got %d. %d free in buffer\n",
1046 total, buf_space);
1047
1030 if (total > (buf_space - CURL_BUF_PADDING)) 1048 if (total > (buf_space - CURL_BUF_PADDING))
1031 { 1049 {
1032 if (ctask->buf_status == BUF_WAIT_FOR_CURL) 1050 if (ctask->buf_status == BUF_WAIT_FOR_CURL)
1033 { 1051 {
1034 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1052 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1035 "CURL: Buffer full starting postprocessing\n"); 1053 "CURL: Buffer full starting postprocessing\n");
1036 ctask->buf_status = BUF_WAIT_FOR_PP; 1054 ctask->buf_status = BUF_WAIT_FOR_PP;
1037 ctask->pp_task = GNUNET_SCHEDULER_add_now (&postprocess_buffer, 1055 ctask->pp_task = GNUNET_SCHEDULER_add_now (&postprocess_buffer,
@@ -1254,9 +1272,12 @@ curl_task_download (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1254 1272
1255 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1273 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1256 "CURL: Completed ctask!\n"); 1274 "CURL: Completed ctask!\n");
1257 ctask->buf_status = BUF_WAIT_FOR_PP; 1275 if (GNUNET_SCHEDULER_NO_TASK == ctask->pp_task)
1258 ctask->pp_task = GNUNET_SCHEDULER_add_now (&postprocess_buffer, 1276 {
1259 ctask); 1277 ctask->buf_status = BUF_WAIT_FOR_PP;
1278 ctask->pp_task = GNUNET_SCHEDULER_add_now (&postprocess_buffer,
1279 ctask);
1280 }
1260 1281
1261 //ctask->ready_to_queue = MHD_YES; 1282 //ctask->ready_to_queue = MHD_YES;
1262 ctask->download_is_finished = GNUNET_YES; 1283 ctask->download_is_finished = GNUNET_YES;
@@ -1535,6 +1556,7 @@ create_response (void *cls,
1535 ctask->curl_response_code = MHD_HTTP_OK; 1556 ctask->curl_response_code = MHD_HTTP_OK;
1536 ctask->buffer_read_ptr = ctask->buffer; 1557 ctask->buffer_read_ptr = ctask->buffer;
1537 ctask->buffer_write_ptr = ctask->buffer; 1558 ctask->buffer_write_ptr = ctask->buffer;
1559 ctask->pp_task = GNUNET_SCHEDULER_NO_TASK;
1538 1560
1539 MHD_get_connection_values (con, 1561 MHD_get_connection_values (con,
1540 MHD_HEADER_KIND, 1562 MHD_HEADER_KIND,
@@ -1577,12 +1599,16 @@ create_response (void *cls,
1577 } 1599 }
1578 1600
1579 ctask = (struct ProxyCurlTask *) *con_cls; 1601 ctask = (struct ProxyCurlTask *) *con_cls;
1580 GNUNET_break (GNUNET_YES != ctask->fin); 1602
1581 if (GNUNET_YES != ctask->ready_to_queue) 1603 if (GNUNET_YES != ctask->ready_to_queue)
1582 return MHD_YES; /* wait longer */ 1604 return MHD_YES; /* wait longer */
1605
1606 if (GNUNET_YES == ctask->fin)
1607 return MHD_YES;
1608
1583 ctask->fin = GNUNET_YES; 1609 ctask->fin = GNUNET_YES;
1584 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1610 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1585 "MHD: Queueing response\n"); 1611 "MHD: Queueing response for %s\n", ctask->url);
1586 ret = MHD_queue_response (con, ctask->curl_response_code, ctask->response); 1612 ret = MHD_queue_response (con, ctask->curl_response_code, ctask->response);
1587 run_mhd_now (ctask->mhd); 1613 run_mhd_now (ctask->mhd);
1588 return ret; 1614 return ret;