diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2010-06-23 12:39:10 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2010-06-23 12:39:10 +0000 |
commit | 544e880ab3dd3292e2aac3877aa616d9efb53496 (patch) | |
tree | 9d1d148f4a8ca0885fa4f68be9e18f0b9c65f444 /src/transport | |
parent | ef1c9e128f922eeb930fa659e37d22256e6886d6 (diff) | |
download | gnunet-544e880ab3dd3292e2aac3877aa616d9efb53496.tar.gz gnunet-544e880ab3dd3292e2aac3877aa616d9efb53496.zip |
plugin changed to be loadable multiple times
Diffstat (limited to 'src/transport')
-rw-r--r-- | src/transport/plugin_transport_http.c | 184 | ||||
-rw-r--r-- | src/transport/test_plugin_transport_http.c | 14 |
2 files changed, 125 insertions, 73 deletions
diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c index be4d9f68d..dabb57a8e 100644 --- a/src/transport/plugin_transport_http.c +++ b/src/transport/plugin_transport_http.c | |||
@@ -318,11 +318,6 @@ struct Plugin | |||
318 | }; | 318 | }; |
319 | 319 | ||
320 | /** | 320 | /** |
321 | * Information about this plugin | ||
322 | */ | ||
323 | static struct Plugin *plugin; | ||
324 | |||
325 | /** | ||
326 | * Create a new session | 321 | * Create a new session |
327 | * | 322 | * |
328 | * @param addr_in address the peer is using inbound | 323 | * @param addr_in address the peer is using inbound |
@@ -330,10 +325,12 @@ static struct Plugin *plugin; | |||
330 | * @param peer identity | 325 | * @param peer identity |
331 | * @return created session object | 326 | * @return created session object |
332 | */ | 327 | */ |
333 | static struct Session * create_session (char * addr_in, size_t addrlen_in, char * addr_out, size_t addrlen_out, const struct GNUNET_PeerIdentity *peer) | 328 | static struct Session * create_session (void * cls, char * addr_in, size_t addrlen_in, char * addr_out, size_t addrlen_out, const struct GNUNET_PeerIdentity *peer) |
334 | { | 329 | { |
330 | struct Plugin *plugin = cls; | ||
335 | struct Session * ses = GNUNET_malloc ( sizeof( struct Session) ); | 331 | struct Session * ses = GNUNET_malloc ( sizeof( struct Session) ); |
336 | 332 | ||
333 | GNUNET_assert(cls !=NULL); | ||
337 | if (addrlen_in != 0) | 334 | if (addrlen_in != 0) |
338 | { | 335 | { |
339 | ses->addr_in = GNUNET_malloc (addrlen_in); | 336 | ses->addr_in = GNUNET_malloc (addrlen_in); |
@@ -378,9 +375,7 @@ static void requestCompletedCallback (void *cls, struct MHD_Connection * connect | |||
378 | 375 | ||
379 | static void messageTokenizerCallback (void *cls, | 376 | static void messageTokenizerCallback (void *cls, |
380 | void *client, | 377 | void *client, |
381 | const struct | 378 | const struct GNUNET_MessageHeader *message) |
382 | GNUNET_MessageHeader * | ||
383 | message) | ||
384 | { | 379 | { |
385 | struct Session * cs = cls; | 380 | struct Session * cs = cls; |
386 | GNUNET_assert(cs != NULL); | 381 | GNUNET_assert(cs != NULL); |
@@ -390,13 +385,10 @@ static void messageTokenizerCallback (void *cls, | |||
390 | ntohs(message->type), | 385 | ntohs(message->type), |
391 | ntohs(message->size), | 386 | ntohs(message->size), |
392 | GNUNET_i2s(&(cs->partner))); | 387 | GNUNET_i2s(&(cs->partner))); |
393 | plugin->env->receive(plugin->env->cls, | 388 | cs->plugin->env->receive(cs->plugin->env->cls, |
394 | &cs->partner, | 389 | &cs->partner, |
395 | message, 1, NULL, | 390 | message, 1, NULL, |
396 | NULL, 0); | 391 | NULL, 0); |
397 | |||
398 | /*(char *)cs->addr_in, | ||
399 | cs->addr_in_len);*/ | ||
400 | } | 392 | } |
401 | 393 | ||
402 | /** | 394 | /** |
@@ -406,6 +398,9 @@ static int | |||
406 | acceptPolicyCallback (void *cls, | 398 | acceptPolicyCallback (void *cls, |
407 | const struct sockaddr *addr, socklen_t addr_len) | 399 | const struct sockaddr *addr, socklen_t addr_len) |
408 | { | 400 | { |
401 | #if 0 | ||
402 | struct Plugin *plugin = cls; | ||
403 | #endif | ||
409 | /* Every connection is accepted, nothing more to do here */ | 404 | /* Every connection is accepted, nothing more to do here */ |
410 | return MHD_YES; | 405 | return MHD_YES; |
411 | } | 406 | } |
@@ -426,6 +421,7 @@ accessHandlerCallback (void *cls, | |||
426 | const char *upload_data, | 421 | const char *upload_data, |
427 | size_t * upload_data_size, void **httpSessionCache) | 422 | size_t * upload_data_size, void **httpSessionCache) |
428 | { | 423 | { |
424 | struct Plugin *plugin = cls; | ||
429 | struct MHD_Response *response; | 425 | struct MHD_Response *response; |
430 | struct Session * cs; | 426 | struct Session * cs; |
431 | const union MHD_ConnectionInfo * conn_info; | 427 | const union MHD_ConnectionInfo * conn_info; |
@@ -439,6 +435,7 @@ accessHandlerCallback (void *cls, | |||
439 | struct IPv4HttpAddress ipv4addr; | 435 | struct IPv4HttpAddress ipv4addr; |
440 | struct IPv6HttpAddress ipv6addr; | 436 | struct IPv6HttpAddress ipv6addr; |
441 | 437 | ||
438 | GNUNET_assert(cls !=NULL); | ||
442 | cur_msg = NULL; | 439 | cur_msg = NULL; |
443 | send_error_to_client = GNUNET_NO; | 440 | send_error_to_client = GNUNET_NO; |
444 | 441 | ||
@@ -482,9 +479,9 @@ accessHandlerCallback (void *cls, | |||
482 | { | 479 | { |
483 | /* create new session object */ | 480 | /* create new session object */ |
484 | if ( AF_INET6 == conn_info->client_addr->sin_family) | 481 | if ( AF_INET6 == conn_info->client_addr->sin_family) |
485 | cs = create_session((char *) &ipv6addr, sizeof(struct IPv6HttpAddress),NULL, 0, &pi_in); | 482 | cs = create_session(plugin, (char *) &ipv6addr, sizeof(struct IPv6HttpAddress),NULL, 0, &pi_in); |
486 | if ( AF_INET == conn_info->client_addr->sin_family) | 483 | if ( AF_INET == conn_info->client_addr->sin_family) |
487 | cs = create_session((char *) &ipv4addr, sizeof(struct IPv4HttpAddress),NULL, 0, &pi_in); | 484 | cs = create_session(plugin, (char *) &ipv4addr, sizeof(struct IPv4HttpAddress),NULL, 0, &pi_in); |
488 | 485 | ||
489 | /* Insert session into hashmap */ | 486 | /* Insert session into hashmap */ |
490 | GNUNET_CONTAINER_multihashmap_put ( plugin->sessions, | 487 | GNUNET_CONTAINER_multihashmap_put ( plugin->sessions, |
@@ -626,18 +623,24 @@ accessHandlerCallback (void *cls, | |||
626 | 623 | ||
627 | 624 | ||
628 | /** | 625 | /** |
629 | * Call MHD to process pending requests and then go back | 626 | * Call MHD to process pending ipv4 requests and then go back |
630 | * and schedule the next run. | 627 | * and schedule the next run. |
631 | */ | 628 | */ |
632 | static void http_daemon_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | 629 | static void http_daemon_v4_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); |
630 | /** | ||
631 | * Call MHD to process pending ipv6 requests and then go back | ||
632 | * and schedule the next run. | ||
633 | */ | ||
634 | static void http_daemon_v6_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
633 | 635 | ||
634 | /** | 636 | /** |
635 | * Function that queries MHD's select sets and | 637 | * Function that queries MHD's select sets and |
636 | * starts the task waiting for them. | 638 | * starts the task waiting for them. |
637 | */ | 639 | */ |
638 | static GNUNET_SCHEDULER_TaskIdentifier | 640 | static GNUNET_SCHEDULER_TaskIdentifier |
639 | http_daemon_prepare (struct MHD_Daemon *daemon_handle) | 641 | http_daemon_prepare (void * cls, struct MHD_Daemon *daemon_handle) |
640 | { | 642 | { |
643 | struct Plugin *plugin = cls; | ||
641 | GNUNET_SCHEDULER_TaskIdentifier ret; | 644 | GNUNET_SCHEDULER_TaskIdentifier ret; |
642 | fd_set rs; | 645 | fd_set rs; |
643 | fd_set ws; | 646 | fd_set ws; |
@@ -650,6 +653,7 @@ http_daemon_prepare (struct MHD_Daemon *daemon_handle) | |||
650 | int haveto; | 653 | int haveto; |
651 | struct GNUNET_TIME_Relative tv; | 654 | struct GNUNET_TIME_Relative tv; |
652 | 655 | ||
656 | GNUNET_assert(cls !=NULL); | ||
653 | FD_ZERO(&rs); | 657 | FD_ZERO(&rs); |
654 | FD_ZERO(&ws); | 658 | FD_ZERO(&ws); |
655 | FD_ZERO(&es); | 659 | FD_ZERO(&es); |
@@ -671,14 +675,28 @@ http_daemon_prepare (struct MHD_Daemon *daemon_handle) | |||
671 | GNUNET_NETWORK_fdset_copy_native (wrs, &rs, max); | 675 | GNUNET_NETWORK_fdset_copy_native (wrs, &rs, max); |
672 | GNUNET_NETWORK_fdset_copy_native (wws, &ws, max); | 676 | GNUNET_NETWORK_fdset_copy_native (wws, &ws, max); |
673 | GNUNET_NETWORK_fdset_copy_native (wes, &es, max); | 677 | GNUNET_NETWORK_fdset_copy_native (wes, &es, max); |
674 | ret = GNUNET_SCHEDULER_add_select (plugin->env->sched, | 678 | if (daemon_handle == plugin->http_daemon_v4) |
675 | GNUNET_SCHEDULER_PRIORITY_DEFAULT, | 679 | { |
676 | GNUNET_SCHEDULER_NO_TASK, | 680 | ret = GNUNET_SCHEDULER_add_select (plugin->env->sched, |
677 | tv, | 681 | GNUNET_SCHEDULER_PRIORITY_DEFAULT, |
678 | wrs, | 682 | GNUNET_SCHEDULER_NO_TASK, |
679 | wws, | 683 | tv, |
680 | &http_daemon_run, | 684 | wrs, |
681 | daemon_handle); | 685 | wws, |
686 | &http_daemon_v4_run, | ||
687 | plugin); | ||
688 | } | ||
689 | if (daemon_handle == plugin->http_daemon_v6) | ||
690 | { | ||
691 | ret = GNUNET_SCHEDULER_add_select (plugin->env->sched, | ||
692 | GNUNET_SCHEDULER_PRIORITY_DEFAULT, | ||
693 | GNUNET_SCHEDULER_NO_TASK, | ||
694 | tv, | ||
695 | wrs, | ||
696 | wws, | ||
697 | &http_daemon_v6_run, | ||
698 | plugin); | ||
699 | } | ||
682 | GNUNET_NETWORK_fdset_destroy (wrs); | 700 | GNUNET_NETWORK_fdset_destroy (wrs); |
683 | GNUNET_NETWORK_fdset_destroy (wws); | 701 | GNUNET_NETWORK_fdset_destroy (wws); |
684 | GNUNET_NETWORK_fdset_destroy (wes); | 702 | GNUNET_NETWORK_fdset_destroy (wes); |
@@ -689,25 +707,42 @@ http_daemon_prepare (struct MHD_Daemon *daemon_handle) | |||
689 | * Call MHD to process pending requests and then go back | 707 | * Call MHD to process pending requests and then go back |
690 | * and schedule the next run. | 708 | * and schedule the next run. |
691 | */ | 709 | */ |
692 | static void http_daemon_run (void *cls, | 710 | static void http_daemon_v4_run (void *cls, |
693 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 711 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
694 | { | 712 | { |
695 | struct MHD_Daemon *daemon_handle = cls; | 713 | struct Plugin *plugin = cls; |
696 | 714 | ||
697 | if (daemon_handle == plugin->http_daemon_v4) | 715 | GNUNET_assert(cls !=NULL); |
716 | if (plugin->http_task_v4 != GNUNET_SCHEDULER_NO_TASK) | ||
698 | plugin->http_task_v4 = GNUNET_SCHEDULER_NO_TASK; | 717 | plugin->http_task_v4 = GNUNET_SCHEDULER_NO_TASK; |
699 | 718 | ||
700 | if (daemon_handle == plugin->http_daemon_v6) | 719 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
720 | return; | ||
721 | |||
722 | GNUNET_assert (MHD_YES == MHD_run (plugin->http_daemon_v4)); | ||
723 | plugin->http_task_v4 = http_daemon_prepare (plugin, plugin->http_daemon_v4); | ||
724 | return; | ||
725 | } | ||
726 | |||
727 | |||
728 | /** | ||
729 | * Call MHD to process pending requests and then go back | ||
730 | * and schedule the next run. | ||
731 | */ | ||
732 | static void http_daemon_v6_run (void *cls, | ||
733 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
734 | { | ||
735 | struct Plugin *plugin = cls; | ||
736 | |||
737 | GNUNET_assert(cls !=NULL); | ||
738 | if (plugin->http_task_v6 != GNUNET_SCHEDULER_NO_TASK) | ||
701 | plugin->http_task_v6 = GNUNET_SCHEDULER_NO_TASK; | 739 | plugin->http_task_v6 = GNUNET_SCHEDULER_NO_TASK; |
702 | 740 | ||
703 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 741 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
704 | return; | 742 | return; |
705 | 743 | ||
706 | GNUNET_assert (MHD_YES == MHD_run (daemon_handle)); | 744 | GNUNET_assert (MHD_YES == MHD_run (plugin->http_daemon_v6)); |
707 | if (daemon_handle == plugin->http_daemon_v4) | 745 | plugin->http_task_v6 = http_daemon_prepare (plugin, plugin->http_daemon_v6); |
708 | plugin->http_task_v4 = http_daemon_prepare (daemon_handle); | ||
709 | if (daemon_handle == plugin->http_daemon_v6) | ||
710 | plugin->http_task_v6 = http_daemon_prepare (daemon_handle); | ||
711 | return; | 746 | return; |
712 | } | 747 | } |
713 | 748 | ||
@@ -828,19 +863,21 @@ static size_t send_write_callback( void *stream, size_t size, size_t nmemb, void | |||
828 | * @param ses session to send data to | 863 | * @param ses session to send data to |
829 | * @return bytes sent to peer | 864 | * @return bytes sent to peer |
830 | */ | 865 | */ |
831 | static size_t send_prepare(struct Session* ses ); | 866 | static size_t send_prepare(void *cls, struct Session* ses ); |
832 | 867 | ||
833 | /** | 868 | /** |
834 | * Function setting up curl handle and selecting message to send | 869 | * Function setting up curl handle and selecting message to send |
835 | * @param ses session to send data to | 870 | * @param ses session to send data to |
836 | * @return bytes sent to peer | 871 | * @return bytes sent to peer |
837 | */ | 872 | */ |
838 | static ssize_t send_select_init (struct Session* ses ) | 873 | static ssize_t send_select_init (void *cls, struct Session* ses ) |
839 | { | 874 | { |
875 | struct Plugin *plugin = cls; | ||
840 | int bytes_sent = 0; | 876 | int bytes_sent = 0; |
841 | CURLMcode mret; | 877 | CURLMcode mret; |
842 | struct HTTP_Message * msg; | 878 | struct HTTP_Message * msg; |
843 | 879 | ||
880 | GNUNET_assert(cls !=NULL); | ||
844 | if ( NULL == ses->curl_handle) | 881 | if ( NULL == ses->curl_handle) |
845 | ses->curl_handle = curl_easy_init(); | 882 | ses->curl_handle = curl_easy_init(); |
846 | if( NULL == ses->curl_handle) | 883 | if( NULL == ses->curl_handle) |
@@ -877,13 +914,14 @@ static ssize_t send_select_init (struct Session* ses ) | |||
877 | curl_multi_strerror (mret)); | 914 | curl_multi_strerror (mret)); |
878 | return -1; | 915 | return -1; |
879 | } | 916 | } |
880 | bytes_sent = send_prepare (ses ); | 917 | bytes_sent = send_prepare (plugin, ses ); |
881 | return bytes_sent; | 918 | return bytes_sent; |
882 | } | 919 | } |
883 | 920 | ||
884 | static void send_execute (void *cls, | 921 | static void send_execute (void *cls, |
885 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 922 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
886 | { | 923 | { |
924 | struct Plugin *plugin = cls; | ||
887 | static unsigned int handles_last_run; | 925 | static unsigned int handles_last_run; |
888 | int running; | 926 | int running; |
889 | struct CURLMsg *msg; | 927 | struct CURLMsg *msg; |
@@ -891,6 +929,7 @@ static void send_execute (void *cls, | |||
891 | struct Session * cs = NULL; | 929 | struct Session * cs = NULL; |
892 | long http_result; | 930 | long http_result; |
893 | 931 | ||
932 | GNUNET_assert(cls !=NULL); | ||
894 | plugin->http_task_send = GNUNET_SCHEDULER_NO_TASK; | 933 | plugin->http_task_send = GNUNET_SCHEDULER_NO_TASK; |
895 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 934 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
896 | return; | 935 | return; |
@@ -960,7 +999,7 @@ static void send_execute (void *cls, | |||
960 | /* send pending messages */ | 999 | /* send pending messages */ |
961 | if (cs->pending_outbound_msg_tail!= NULL) | 1000 | if (cs->pending_outbound_msg_tail!= NULL) |
962 | { | 1001 | { |
963 | send_select_init (cs); | 1002 | send_select_init (plugin, cs); |
964 | } | 1003 | } |
965 | return; | 1004 | return; |
966 | default: | 1005 | default: |
@@ -973,7 +1012,7 @@ static void send_execute (void *cls, | |||
973 | handles_last_run = running; | 1012 | handles_last_run = running; |
974 | } | 1013 | } |
975 | while (mret == CURLM_CALL_MULTI_PERFORM); | 1014 | while (mret == CURLM_CALL_MULTI_PERFORM); |
976 | send_prepare(cls); | 1015 | send_prepare(plugin, cls); |
977 | } | 1016 | } |
978 | 1017 | ||
979 | 1018 | ||
@@ -982,8 +1021,9 @@ static void send_execute (void *cls, | |||
982 | * @param ses session to send data to | 1021 | * @param ses session to send data to |
983 | * @return bytes sent to peer | 1022 | * @return bytes sent to peer |
984 | */ | 1023 | */ |
985 | static size_t send_prepare(struct Session* ses ) | 1024 | static size_t send_prepare(void *cls, struct Session* ses ) |
986 | { | 1025 | { |
1026 | struct Plugin *plugin = cls; | ||
987 | fd_set rs; | 1027 | fd_set rs; |
988 | fd_set ws; | 1028 | fd_set ws; |
989 | fd_set es; | 1029 | fd_set es; |
@@ -993,6 +1033,7 @@ static size_t send_prepare(struct Session* ses ) | |||
993 | long to; | 1033 | long to; |
994 | CURLMcode mret; | 1034 | CURLMcode mret; |
995 | 1035 | ||
1036 | GNUNET_assert(cls !=NULL); | ||
996 | max = -1; | 1037 | max = -1; |
997 | FD_ZERO (&rs); | 1038 | FD_ZERO (&rs); |
998 | FD_ZERO (&ws); | 1039 | FD_ZERO (&ws); |
@@ -1027,7 +1068,7 @@ static size_t send_prepare(struct Session* ses ) | |||
1027 | grs, | 1068 | grs, |
1028 | gws, | 1069 | gws, |
1029 | &send_execute, | 1070 | &send_execute, |
1030 | ses); | 1071 | plugin); |
1031 | GNUNET_NETWORK_fdset_destroy (gws); | 1072 | GNUNET_NETWORK_fdset_destroy (gws); |
1032 | GNUNET_NETWORK_fdset_destroy (grs); | 1073 | GNUNET_NETWORK_fdset_destroy (grs); |
1033 | 1074 | ||
@@ -1063,31 +1104,33 @@ static size_t send_prepare(struct Session* ses ) | |||
1063 | */ | 1104 | */ |
1064 | static ssize_t | 1105 | static ssize_t |
1065 | http_plugin_send (void *cls, | 1106 | http_plugin_send (void *cls, |
1066 | const struct GNUNET_PeerIdentity *target, | 1107 | const struct GNUNET_PeerIdentity *target, |
1067 | const char *msgbuf, | 1108 | const char *msgbuf, |
1068 | size_t msgbuf_size, | 1109 | size_t msgbuf_size, |
1069 | unsigned int priority, | 1110 | unsigned int priority, |
1070 | struct GNUNET_TIME_Relative to, | 1111 | struct GNUNET_TIME_Relative to, |
1071 | struct Session *session, | 1112 | struct Session *session, |
1072 | const void *addr, | 1113 | const void *addr, |
1073 | size_t addrlen, | 1114 | size_t addrlen, |
1074 | int force_address, | 1115 | int force_address, |
1075 | GNUNET_TRANSPORT_TransmitContinuation cont, | 1116 | GNUNET_TRANSPORT_TransmitContinuation cont, |
1076 | void *cont_cls) | 1117 | void *cont_cls) |
1077 | { | 1118 | { |
1078 | char * address; | 1119 | struct Plugin *plugin = cls; |
1079 | char * url; | 1120 | char *address; |
1080 | struct Session* cs; | 1121 | char *url; |
1081 | struct HTTP_Message * msg; | 1122 | struct Session *cs; |
1123 | struct HTTP_Message *msg; | ||
1082 | unsigned int res; | 1124 | unsigned int res; |
1083 | 1125 | ||
1126 | GNUNET_assert(cls !=NULL); | ||
1084 | url = NULL; | 1127 | url = NULL; |
1085 | address = NULL; | 1128 | address = NULL; |
1086 | 1129 | ||
1087 | cs = GNUNET_CONTAINER_multihashmap_get (plugin->sessions, &target->hashPubKey); | 1130 | cs = GNUNET_CONTAINER_multihashmap_get (plugin->sessions, &target->hashPubKey); |
1088 | if ( cs == NULL) | 1131 | if ( cs == NULL) |
1089 | { | 1132 | { |
1090 | cs = create_session((char *) addr, addrlen, NULL, 0, target); | 1133 | cs = create_session(plugin, (char *) addr, addrlen, NULL, 0, target); |
1091 | cs->is_active = GNUNET_YES; | 1134 | cs->is_active = GNUNET_YES; |
1092 | res = GNUNET_CONTAINER_multihashmap_put ( plugin->sessions, | 1135 | res = GNUNET_CONTAINER_multihashmap_put ( plugin->sessions, |
1093 | &cs->partner.hashPubKey, | 1136 | &cs->partner.hashPubKey, |
@@ -1142,7 +1185,7 @@ http_plugin_send (void *cls, | |||
1142 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"HTTP Plugin: url `%s'\n",url); | 1185 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"HTTP Plugin: url `%s'\n",url); |
1143 | if (msg == cs->pending_outbound_msg_tail) | 1186 | if (msg == cs->pending_outbound_msg_tail) |
1144 | { | 1187 | { |
1145 | return send_select_init (cs); | 1188 | return send_select_init (plugin, cs); |
1146 | } | 1189 | } |
1147 | return msgbuf_size; | 1190 | return msgbuf_size; |
1148 | } | 1191 | } |
@@ -1200,6 +1243,7 @@ http_plugin_address_pretty_printer (void *cls, | |||
1200 | unsigned int port; | 1243 | unsigned int port; |
1201 | unsigned int res; | 1244 | unsigned int res; |
1202 | 1245 | ||
1246 | GNUNET_assert(cls !=NULL); | ||
1203 | if (addrlen == sizeof (struct IPv6HttpAddress)) | 1247 | if (addrlen == sizeof (struct IPv6HttpAddress)) |
1204 | { | 1248 | { |
1205 | address = GNUNET_malloc (INET6_ADDRSTRLEN); | 1249 | address = GNUNET_malloc (INET6_ADDRSTRLEN); |
@@ -1248,10 +1292,12 @@ static int | |||
1248 | http_plugin_address_suggested (void *cls, | 1292 | http_plugin_address_suggested (void *cls, |
1249 | void *addr, size_t addrlen) | 1293 | void *addr, size_t addrlen) |
1250 | { | 1294 | { |
1295 | struct Plugin *plugin = cls; | ||
1251 | struct IPv4HttpAddress *v4; | 1296 | struct IPv4HttpAddress *v4; |
1252 | struct IPv6HttpAddress *v6; | 1297 | struct IPv6HttpAddress *v6; |
1253 | unsigned int port; | 1298 | unsigned int port; |
1254 | 1299 | ||
1300 | GNUNET_assert(cls !=NULL); | ||
1255 | if ((addrlen != sizeof (struct IPv4HttpAddress)) && | 1301 | if ((addrlen != sizeof (struct IPv4HttpAddress)) && |
1256 | (addrlen != sizeof (struct IPv6HttpAddress))) | 1302 | (addrlen != sizeof (struct IPv6HttpAddress))) |
1257 | { | 1303 | { |
@@ -1314,6 +1360,7 @@ http_plugin_address_to_string (void *cls, | |||
1314 | unsigned int port; | 1360 | unsigned int port; |
1315 | unsigned int res; | 1361 | unsigned int res; |
1316 | 1362 | ||
1363 | GNUNET_assert(cls !=NULL); | ||
1317 | if (addrlen == sizeof (struct IPv6HttpAddress)) | 1364 | if (addrlen == sizeof (struct IPv6HttpAddress)) |
1318 | { | 1365 | { |
1319 | address = GNUNET_malloc (INET6_ADDRSTRLEN); | 1366 | address = GNUNET_malloc (INET6_ADDRSTRLEN); |
@@ -1358,12 +1405,14 @@ process_interfaces (void *cls, | |||
1358 | int isDefault, | 1405 | int isDefault, |
1359 | const struct sockaddr *addr, socklen_t addrlen) | 1406 | const struct sockaddr *addr, socklen_t addrlen) |
1360 | { | 1407 | { |
1408 | struct Plugin *plugin = cls; | ||
1361 | struct IPv4HttpAddress t4; | 1409 | struct IPv4HttpAddress t4; |
1362 | struct IPv6HttpAddress t6; | 1410 | struct IPv6HttpAddress t6; |
1363 | int af; | 1411 | int af; |
1364 | void *arg; | 1412 | void *arg; |
1365 | uint16_t args; | 1413 | uint16_t args; |
1366 | 1414 | ||
1415 | GNUNET_assert(cls !=NULL); | ||
1367 | af = addr->sa_family; | 1416 | af = addr->sa_family; |
1368 | if (af == AF_INET) | 1417 | if (af == AF_INET) |
1369 | { | 1418 | { |
@@ -1444,6 +1493,7 @@ libgnunet_plugin_transport_http_done (void *cls) | |||
1444 | struct Plugin *plugin = api->cls; | 1493 | struct Plugin *plugin = api->cls; |
1445 | CURLMcode mret; | 1494 | CURLMcode mret; |
1446 | 1495 | ||
1496 | GNUNET_assert(cls !=NULL); | ||
1447 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Unloading http plugin...\n"); | 1497 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Unloading http plugin...\n"); |
1448 | 1498 | ||
1449 | if ( plugin->http_task_v4 != GNUNET_SCHEDULER_NO_TASK) | 1499 | if ( plugin->http_task_v4 != GNUNET_SCHEDULER_NO_TASK) |
@@ -1499,10 +1549,12 @@ void * | |||
1499 | libgnunet_plugin_transport_http_init (void *cls) | 1549 | libgnunet_plugin_transport_http_init (void *cls) |
1500 | { | 1550 | { |
1501 | struct GNUNET_TRANSPORT_PluginEnvironment *env = cls; | 1551 | struct GNUNET_TRANSPORT_PluginEnvironment *env = cls; |
1552 | struct Plugin *plugin; | ||
1502 | struct GNUNET_TRANSPORT_PluginFunctions *api; | 1553 | struct GNUNET_TRANSPORT_PluginFunctions *api; |
1503 | struct GNUNET_TIME_Relative gn_timeout; | 1554 | struct GNUNET_TIME_Relative gn_timeout; |
1504 | long long unsigned int port; | 1555 | long long unsigned int port; |
1505 | 1556 | ||
1557 | GNUNET_assert(cls !=NULL); | ||
1506 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Starting http plugin...\n"); | 1558 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Starting http plugin...\n"); |
1507 | 1559 | ||
1508 | plugin = GNUNET_malloc (sizeof (struct Plugin)); | 1560 | plugin = GNUNET_malloc (sizeof (struct Plugin)); |
@@ -1543,7 +1595,7 @@ libgnunet_plugin_transport_http_init (void *cls) | |||
1543 | plugin->http_daemon_v6 = MHD_start_daemon (MHD_USE_IPv6, | 1595 | plugin->http_daemon_v6 = MHD_start_daemon (MHD_USE_IPv6, |
1544 | port, | 1596 | port, |
1545 | &acceptPolicyCallback, | 1597 | &acceptPolicyCallback, |
1546 | NULL , &accessHandlerCallback, NULL, | 1598 | plugin , &accessHandlerCallback, plugin, |
1547 | MHD_OPTION_CONNECTION_LIMIT, (unsigned int) 16, | 1599 | MHD_OPTION_CONNECTION_LIMIT, (unsigned int) 16, |
1548 | MHD_OPTION_PER_IP_CONNECTION_LIMIT, (unsigned int) 1, | 1600 | MHD_OPTION_PER_IP_CONNECTION_LIMIT, (unsigned int) 1, |
1549 | MHD_OPTION_CONNECTION_TIMEOUT, (gn_timeout.value / 1000), | 1601 | MHD_OPTION_CONNECTION_TIMEOUT, (gn_timeout.value / 1000), |
@@ -1553,7 +1605,7 @@ libgnunet_plugin_transport_http_init (void *cls) | |||
1553 | plugin->http_daemon_v4 = MHD_start_daemon (MHD_NO_FLAG, | 1605 | plugin->http_daemon_v4 = MHD_start_daemon (MHD_NO_FLAG, |
1554 | port, | 1606 | port, |
1555 | &acceptPolicyCallback, | 1607 | &acceptPolicyCallback, |
1556 | NULL , &accessHandlerCallback, NULL, | 1608 | plugin , &accessHandlerCallback, plugin, |
1557 | MHD_OPTION_CONNECTION_LIMIT, (unsigned int) 16, | 1609 | MHD_OPTION_CONNECTION_LIMIT, (unsigned int) 16, |
1558 | MHD_OPTION_PER_IP_CONNECTION_LIMIT, (unsigned int) 1, | 1610 | MHD_OPTION_PER_IP_CONNECTION_LIMIT, (unsigned int) 1, |
1559 | MHD_OPTION_CONNECTION_TIMEOUT, (gn_timeout.value / 1000), | 1611 | MHD_OPTION_CONNECTION_TIMEOUT, (gn_timeout.value / 1000), |
@@ -1562,9 +1614,9 @@ libgnunet_plugin_transport_http_init (void *cls) | |||
1562 | MHD_OPTION_END); | 1614 | MHD_OPTION_END); |
1563 | } | 1615 | } |
1564 | if (plugin->http_daemon_v4 != NULL) | 1616 | if (plugin->http_daemon_v4 != NULL) |
1565 | plugin->http_task_v4 = http_daemon_prepare (plugin->http_daemon_v4); | 1617 | plugin->http_task_v4 = http_daemon_prepare (plugin, plugin->http_daemon_v4); |
1566 | if (plugin->http_daemon_v6 != NULL) | 1618 | if (plugin->http_daemon_v6 != NULL) |
1567 | plugin->http_task_v6 = http_daemon_prepare (plugin->http_daemon_v6); | 1619 | plugin->http_task_v6 = http_daemon_prepare (plugin, plugin->http_daemon_v6); |
1568 | 1620 | ||
1569 | if (plugin->http_task_v4 != GNUNET_SCHEDULER_NO_TASK) | 1621 | if (plugin->http_task_v4 != GNUNET_SCHEDULER_NO_TASK) |
1570 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Starting MHD with IPv4 on port %u\n",port); | 1622 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Starting MHD with IPv4 on port %u\n",port); |
diff --git a/src/transport/test_plugin_transport_http.c b/src/transport/test_plugin_transport_http.c index 6ac925512..6042ad154 100644 --- a/src/transport/test_plugin_transport_http.c +++ b/src/transport/test_plugin_transport_http.c | |||
@@ -1170,9 +1170,9 @@ run (void *cls, | |||
1170 | while (cur != NULL) | 1170 | while (cur != NULL) |
1171 | { | 1171 | { |
1172 | 1172 | ||
1173 | api->address_pretty_printer (NULL,"http",cur->addr,cur->addrlen,GNUNET_NO,TEST_TIMEOUT,&pretty_printer_cb,NULL); | 1173 | api->address_pretty_printer (api->cls, "http",cur->addr,cur->addrlen, GNUNET_NO,TEST_TIMEOUT, &pretty_printer_cb,NULL); |
1174 | addr_str = api->address_to_string (NULL,cur->addr,cur->addrlen); | 1174 | addr_str = api->address_to_string (api->cls, cur->addr, cur->addrlen); |
1175 | suggest_res = api->check_address (NULL,cur->addr,cur->addrlen); | 1175 | suggest_res = api->check_address (api->cls, cur->addr, cur->addrlen); |
1176 | 1176 | ||
1177 | GNUNET_assert (GNUNET_OK == suggest_res); | 1177 | GNUNET_assert (GNUNET_OK == suggest_res); |
1178 | GNUNET_assert (NULL != addr_str); | 1178 | GNUNET_assert (NULL != addr_str); |
@@ -1190,19 +1190,19 @@ run (void *cls, | |||
1190 | struct IPv4HttpAddress failing_addr; | 1190 | struct IPv4HttpAddress failing_addr; |
1191 | failing_addr.ipv4_addr = htonl(INADDR_LOOPBACK); | 1191 | failing_addr.ipv4_addr = htonl(INADDR_LOOPBACK); |
1192 | failing_addr.u_port = htons(0); | 1192 | failing_addr.u_port = htons(0); |
1193 | suggest_res = api->check_address (NULL,&failing_addr,sizeof (struct IPv4HttpAddress)); | 1193 | suggest_res = api->check_address (api->cls,&failing_addr,sizeof (struct IPv4HttpAddress)); |
1194 | GNUNET_assert (GNUNET_SYSERR == suggest_res); | 1194 | GNUNET_assert (GNUNET_SYSERR == suggest_res); |
1195 | 1195 | ||
1196 | /* Suggesting addresses with wrong size*/ | 1196 | /* Suggesting addresses with wrong size*/ |
1197 | failing_addr.ipv4_addr = htonl(INADDR_LOOPBACK); | 1197 | failing_addr.ipv4_addr = htonl(INADDR_LOOPBACK); |
1198 | failing_addr.u_port = htons(0); | 1198 | failing_addr.u_port = htons(0); |
1199 | suggest_res = api->check_address (NULL,&failing_addr,sizeof (struct IPv6HttpAddress)); | 1199 | suggest_res = api->check_address (api->cls,&failing_addr,sizeof (struct IPv6HttpAddress)); |
1200 | GNUNET_assert (GNUNET_SYSERR == suggest_res); | 1200 | GNUNET_assert (GNUNET_SYSERR == suggest_res); |
1201 | 1201 | ||
1202 | /* Suggesting addresses with wrong address*/ | 1202 | /* Suggesting addresses with wrong address*/ |
1203 | failing_addr.ipv4_addr = htonl(INADDR_LOOPBACK); | 1203 | failing_addr.ipv4_addr = htonl(INADDR_LOOPBACK); |
1204 | failing_addr.u_port = htons(12389); | 1204 | failing_addr.u_port = htons(12389); |
1205 | suggest_res = api->check_address (NULL,&failing_addr,sizeof (struct IPv4HttpAddress)); | 1205 | suggest_res = api->check_address (api->cls,&failing_addr,sizeof (struct IPv4HttpAddress)); |
1206 | GNUNET_assert (GNUNET_SYSERR == suggest_res); | 1206 | GNUNET_assert (GNUNET_SYSERR == suggest_res); |
1207 | 1207 | ||
1208 | /* test sending to client */ | 1208 | /* test sending to client */ |
@@ -1235,7 +1235,7 @@ run (void *cls, | |||
1235 | test_valid_ident.test_executed = GNUNET_NO; | 1235 | test_valid_ident.test_executed = GNUNET_NO; |
1236 | test_valid_ident.test_failed = GNUNET_YES; | 1236 | test_valid_ident.test_failed = GNUNET_YES; |
1237 | 1237 | ||
1238 | test_addr = (char *) api->address_to_string (NULL,addr_head->addr,addr_head->addrlen); | 1238 | test_addr = (char *) api->address_to_string (api->cls,addr_head->addr,addr_head->addrlen); |
1239 | run_connection_tests(); | 1239 | run_connection_tests(); |
1240 | 1240 | ||
1241 | /* testing finished */ | 1241 | /* testing finished */ |