diff options
Diffstat (limited to 'src/transport/plugin_transport_http_client.c')
-rw-r--r-- | src/transport/plugin_transport_http_client.c | 58 |
1 files changed, 32 insertions, 26 deletions
diff --git a/src/transport/plugin_transport_http_client.c b/src/transport/plugin_transport_http_client.c index c3a34a3fd..07a0de2ac 100644 --- a/src/transport/plugin_transport_http_client.c +++ b/src/transport/plugin_transport_http_client.c | |||
@@ -107,6 +107,7 @@ struct HTTP_Message | |||
107 | */ | 107 | */ |
108 | struct Session; | 108 | struct Session; |
109 | 109 | ||
110 | |||
110 | /** | 111 | /** |
111 | * A connection handle | 112 | * A connection handle |
112 | * | 113 | * |
@@ -125,7 +126,6 @@ struct ConnectionHandle | |||
125 | }; | 126 | }; |
126 | 127 | ||
127 | 128 | ||
128 | |||
129 | /** | 129 | /** |
130 | * Session handle for connections. | 130 | * Session handle for connections. |
131 | */ | 131 | */ |
@@ -623,12 +623,12 @@ client_delete_session (struct Session *s) | |||
623 | * Disconnect a session | 623 | * Disconnect a session |
624 | * | 624 | * |
625 | * @param s session | 625 | * @param s session |
626 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | 626 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
627 | */ | 627 | */ |
628 | static int | 628 | static int |
629 | client_disconnect (struct Session *s) | 629 | http_client_session_disconnect (struct HTTP_Client_Plugin *plugin, |
630 | struct Session *s) | ||
630 | { | 631 | { |
631 | struct HTTP_Client_Plugin *plugin = s->plugin; | ||
632 | struct HTTP_Message *msg; | 632 | struct HTTP_Message *msg; |
633 | struct HTTP_Message *t; | 633 | struct HTTP_Message *t; |
634 | int res = GNUNET_OK; | 634 | int res = GNUNET_OK; |
@@ -730,7 +730,8 @@ client_disconnect (struct Session *s) | |||
730 | * @param target peer from which to disconnect | 730 | * @param target peer from which to disconnect |
731 | */ | 731 | */ |
732 | static void | 732 | static void |
733 | http_client_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target) | 733 | http_client_peer_disconnect (void *cls, |
734 | const struct GNUNET_PeerIdentity *target) | ||
734 | { | 735 | { |
735 | struct HTTP_Client_Plugin *plugin = cls; | 736 | struct HTTP_Client_Plugin *plugin = cls; |
736 | struct Session *next = NULL; | 737 | struct Session *next = NULL; |
@@ -749,12 +750,13 @@ http_client_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *targ | |||
749 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 750 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
750 | "Disconnecting session %p to `%pos'\n", | 751 | "Disconnecting session %p to `%pos'\n", |
751 | pos, GNUNET_i2s (target)); | 752 | pos, GNUNET_i2s (target)); |
752 | GNUNET_assert (GNUNET_OK == client_disconnect (pos)); | 753 | GNUNET_assert (GNUNET_OK == http_client_session_disconnect (plugin, |
754 | pos)); | ||
753 | } | 755 | } |
754 | } | 756 | } |
755 | |||
756 | } | 757 | } |
757 | 758 | ||
759 | |||
758 | /** | 760 | /** |
759 | * Check if a sessions exists for an specific address | 761 | * Check if a sessions exists for an specific address |
760 | * | 762 | * |
@@ -1221,7 +1223,7 @@ client_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1221 | /* Disconnect other transmission direction and tell transport */ | 1223 | /* Disconnect other transmission direction and tell transport */ |
1222 | s->get.easyhandle = NULL; | 1224 | s->get.easyhandle = NULL; |
1223 | s->get.s = NULL; | 1225 | s->get.s = NULL; |
1224 | client_disconnect (s); | 1226 | http_client_session_disconnect (plugin, s); |
1225 | } | 1227 | } |
1226 | } | 1228 | } |
1227 | } | 1229 | } |
@@ -1535,8 +1537,8 @@ http_client_plugin_get_session (void *cls, | |||
1535 | return NULL; | 1537 | return NULL; |
1536 | } | 1538 | } |
1537 | 1539 | ||
1538 | s = GNUNET_malloc (sizeof (struct Session)); | 1540 | s = GNUNET_new (struct Session); |
1539 | memcpy (&s->target, &address->peer, sizeof (struct GNUNET_PeerIdentity)); | 1541 | s->target = address->peer; |
1540 | s->plugin = plugin; | 1542 | s->plugin = plugin; |
1541 | s->addr = GNUNET_malloc (address->address_length); | 1543 | s->addr = GNUNET_malloc (address->address_length); |
1542 | memcpy (s->addr, address->address, address->address_length); | 1544 | memcpy (s->addr, address->address, address->address_length); |
@@ -1574,7 +1576,7 @@ http_client_plugin_get_session (void *cls, | |||
1574 | * Setup http_client plugin | 1576 | * Setup http_client plugin |
1575 | * | 1577 | * |
1576 | * @param plugin the plugin handle | 1578 | * @param plugin the plugin handle |
1577 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | 1579 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
1578 | */ | 1580 | */ |
1579 | static int | 1581 | static int |
1580 | client_start (struct HTTP_Client_Plugin *plugin) | 1582 | client_start (struct HTTP_Client_Plugin *plugin) |
@@ -1598,7 +1600,6 @@ client_start (struct HTTP_Client_Plugin *plugin) | |||
1598 | static void | 1600 | static void |
1599 | client_session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 1601 | client_session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
1600 | { | 1602 | { |
1601 | GNUNET_assert (NULL != cls); | ||
1602 | struct Session *s = cls; | 1603 | struct Session *s = cls; |
1603 | 1604 | ||
1604 | s->timeout_task = GNUNET_SCHEDULER_NO_TASK; | 1605 | s->timeout_task = GNUNET_SCHEDULER_NO_TASK; |
@@ -1609,7 +1610,8 @@ client_session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc | |||
1609 | GNUNET_YES)); | 1610 | GNUNET_YES)); |
1610 | 1611 | ||
1611 | /* call session destroy function */ | 1612 | /* call session destroy function */ |
1612 | GNUNET_assert (GNUNET_OK == client_disconnect (s)); | 1613 | GNUNET_assert (GNUNET_OK == http_client_session_disconnect (s->plugin, |
1614 | s)); | ||
1613 | } | 1615 | } |
1614 | 1616 | ||
1615 | 1617 | ||
@@ -1729,13 +1731,13 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls) | |||
1729 | next = plugin->head; | 1731 | next = plugin->head; |
1730 | while (NULL != (pos = next)) | 1732 | while (NULL != (pos = next)) |
1731 | { | 1733 | { |
1732 | next = pos->next; | 1734 | next = pos->next; |
1733 | client_disconnect (pos); | 1735 | http_client_session_disconnect (plugin, pos); |
1734 | } | 1736 | } |
1735 | if (GNUNET_SCHEDULER_NO_TASK != plugin->client_perform_task) | 1737 | if (GNUNET_SCHEDULER_NO_TASK != plugin->client_perform_task) |
1736 | { | 1738 | { |
1737 | GNUNET_SCHEDULER_cancel (plugin->client_perform_task); | 1739 | GNUNET_SCHEDULER_cancel (plugin->client_perform_task); |
1738 | plugin->client_perform_task = GNUNET_SCHEDULER_NO_TASK; | 1740 | plugin->client_perform_task = GNUNET_SCHEDULER_NO_TASK; |
1739 | } | 1741 | } |
1740 | 1742 | ||
1741 | 1743 | ||
@@ -1760,7 +1762,7 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls) | |||
1760 | * Configure plugin | 1762 | * Configure plugin |
1761 | * | 1763 | * |
1762 | * @param plugin the plugin handle | 1764 | * @param plugin the plugin handle |
1763 | * @return GNUNET_OK on success, GNUNET_SYSERR on failure | 1765 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure |
1764 | */ | 1766 | */ |
1765 | static int | 1767 | static int |
1766 | client_configure_plugin (struct HTTP_Client_Plugin *plugin) | 1768 | client_configure_plugin (struct HTTP_Client_Plugin *plugin) |
@@ -1780,13 +1782,16 @@ client_configure_plugin (struct HTTP_Client_Plugin *plugin) | |||
1780 | return GNUNET_OK; | 1782 | return GNUNET_OK; |
1781 | } | 1783 | } |
1782 | 1784 | ||
1783 | const char *http_plugin_address_to_string (void *cls, | 1785 | |
1784 | const void *addr, | 1786 | static const char * |
1785 | size_t addrlen) | 1787 | http_plugin_address_to_string (void *cls, |
1788 | const void *addr, | ||
1789 | size_t addrlen) | ||
1786 | { | 1790 | { |
1787 | return http_common_plugin_address_to_string (cls, PLUGIN_NAME, addr, addrlen); | 1791 | return http_common_plugin_address_to_string (cls, PLUGIN_NAME, addr, addrlen); |
1788 | } | 1792 | } |
1789 | 1793 | ||
1794 | |||
1790 | /** | 1795 | /** |
1791 | * Entry point for the plugin. | 1796 | * Entry point for the plugin. |
1792 | */ | 1797 | */ |
@@ -1801,7 +1806,7 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls) | |||
1801 | { | 1806 | { |
1802 | /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully | 1807 | /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully |
1803 | initialze the plugin or the API */ | 1808 | initialze the plugin or the API */ |
1804 | api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); | 1809 | api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); |
1805 | api->cls = NULL; | 1810 | api->cls = NULL; |
1806 | api->address_to_string = &http_plugin_address_to_string; | 1811 | api->address_to_string = &http_plugin_address_to_string; |
1807 | api->string_to_address = &http_common_plugin_string_to_address; | 1812 | api->string_to_address = &http_common_plugin_string_to_address; |
@@ -1809,13 +1814,14 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls) | |||
1809 | return api; | 1814 | return api; |
1810 | } | 1815 | } |
1811 | 1816 | ||
1812 | plugin = GNUNET_malloc (sizeof (struct HTTP_Client_Plugin)); | 1817 | plugin = GNUNET_new (struct HTTP_Client_Plugin); |
1813 | p = plugin; | 1818 | p = plugin; |
1814 | plugin->env = env; | 1819 | plugin->env = env; |
1815 | api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); | 1820 | api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); |
1816 | api->cls = plugin; | 1821 | api->cls = plugin; |
1817 | api->send = &http_client_plugin_send; | 1822 | api->send = &http_client_plugin_send; |
1818 | api->disconnect = &http_client_plugin_disconnect; | 1823 | api->disconnect_session = &http_client_session_disconnect; |
1824 | api->disconnect_peer = &http_client_peer_disconnect; | ||
1819 | api->check_address = &http_client_plugin_address_suggested; | 1825 | api->check_address = &http_client_plugin_address_suggested; |
1820 | api->get_session = &http_client_plugin_get_session; | 1826 | api->get_session = &http_client_plugin_get_session; |
1821 | api->address_to_string = &http_plugin_address_to_string; | 1827 | api->address_to_string = &http_plugin_address_to_string; |