Mercurial > pidgin
comparison libpurple/protocols/jabber/bosh.c @ 25183:62d9bce9ff74
Reorder some functions to eliminate prototypes and
export jabber_bosh_connection_refresh()
author | Paul Aurich <paul@darkrain42.org> |
---|---|
date | Fri, 05 Dec 2008 00:08:19 +0000 |
parents | 17b60b844803 |
children | 1ce32c6752fc |
comparison
equal
deleted
inserted
replaced
25182:17b60b844803 | 25183:62d9bce9ff74 |
---|---|
100 static void jabber_bosh_connection_auth_response(PurpleBOSHConnection *conn, xmlnode *node); | 100 static void jabber_bosh_connection_auth_response(PurpleBOSHConnection *conn, xmlnode *node); |
101 static void jabber_bosh_connection_boot_response(PurpleBOSHConnection *conn, xmlnode *node); | 101 static void jabber_bosh_connection_boot_response(PurpleBOSHConnection *conn, xmlnode *node); |
102 static void jabber_bosh_connection_http_received_cb(PurpleHTTPRequest *req, PurpleHTTPResponse *res, void *userdata); | 102 static void jabber_bosh_connection_http_received_cb(PurpleHTTPRequest *req, PurpleHTTPResponse *res, void *userdata); |
103 static void jabber_bosh_connection_send_native(PurpleBOSHConnection *conn, xmlnode *node); | 103 static void jabber_bosh_connection_send_native(PurpleBOSHConnection *conn, xmlnode *node); |
104 | 104 |
105 static void jabber_bosh_http_connection_receive_parse_header(PurpleHTTPResponse *response, char **data, int *len); | |
106 static PurpleHTTPConnection* jabber_bosh_http_connection_init(const char *host, int port); | |
107 static void jabber_bosh_http_connection_connect(PurpleHTTPConnection *conn); | 105 static void jabber_bosh_http_connection_connect(PurpleHTTPConnection *conn); |
108 static void jabber_bosh_http_connection_send_request(PurpleHTTPConnection *conn, PurpleHTTPRequest *req); | 106 static void jabber_bosh_http_connection_send_request(PurpleHTTPConnection *conn, PurpleHTTPRequest *req); |
109 static void jabber_bosh_http_connection_destroy(PurpleHTTPConnection *conn); | 107 |
110 | |
111 static PurpleHTTPRequest* jabber_bosh_http_request_init(const char *method, const char *path, PurpleHTTPRequestCallback cb, void *userdata); | |
112 static void jabber_bosh_http_request_add_to_header(PurpleHTTPRequest *req, const char *field, const char *value); | 108 static void jabber_bosh_http_request_add_to_header(PurpleHTTPRequest *req, const char *field, const char *value); |
113 static void jabber_bosh_http_request_set_data(PurpleHTTPRequest *req, char *data, int len); | |
114 static void jabber_bosh_http_request_destroy(PurpleHTTPRequest *req); | |
115 | |
116 static PurpleHTTPResponse* jabber_bosh_http_response_init(void); | |
117 static void jabber_bosh_http_response_destroy(PurpleHTTPResponse *res); | |
118 | 109 |
119 void jabber_bosh_init(void) | 110 void jabber_bosh_init(void) |
120 { | 111 { |
121 GHashTable *ui_info = purple_core_get_ui_info(); | 112 GHashTable *ui_info = purple_core_get_ui_info(); |
122 const char *ui_version = NULL; | 113 const char *ui_version = NULL; |
134 { | 125 { |
135 g_free(bosh_useragent); | 126 g_free(bosh_useragent); |
136 bosh_useragent = NULL; | 127 bosh_useragent = NULL; |
137 } | 128 } |
138 | 129 |
139 PurpleBOSHConnection* jabber_bosh_connection_init(JabberStream *js, const char *url) | 130 static PurpleHTTPRequest* |
131 jabber_bosh_http_request_init(const char *method, const char *path, | |
132 PurpleHTTPRequestCallback cb, void *userdata) | |
133 { | |
134 PurpleHTTPRequest *req = g_new(PurpleHTTPRequest, 1); | |
135 req->method = g_strdup(method); | |
136 req->path = g_strdup(path); | |
137 req->cb = cb; | |
138 req->userdata = userdata; | |
139 req->header = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); | |
140 return req; | |
141 } | |
142 | |
143 static void | |
144 jabber_bosh_http_request_destroy(PurpleHTTPRequest *req) | |
145 { | |
146 g_hash_table_destroy(req->header); | |
147 g_free(req->method); | |
148 g_free(req->path); | |
149 g_free(req->data); | |
150 g_free(req); | |
151 } | |
152 | |
153 static PurpleHTTPResponse* | |
154 jabber_bosh_http_response_init(void) | |
155 { | |
156 PurpleHTTPResponse *res = g_new0(PurpleHTTPResponse, 1); | |
157 res->header = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); | |
158 return res; | |
159 } | |
160 | |
161 static void | |
162 jabber_bosh_http_response_destroy(PurpleHTTPResponse *res) | |
163 { | |
164 g_hash_table_destroy(res->header); | |
165 g_free(res->data); | |
166 g_free(res); | |
167 } | |
168 | |
169 static PurpleHTTPConnection* | |
170 jabber_bosh_http_connection_init(const char *host, int port) | |
171 { | |
172 PurpleHTTPConnection *conn = g_new0(PurpleHTTPConnection, 1); | |
173 conn->host = g_strdup(host); | |
174 conn->port = port; | |
175 conn->fd = -1; | |
176 conn->requests = g_queue_new(); | |
177 | |
178 return conn; | |
179 } | |
180 | |
181 static void | |
182 jabber_bosh_http_connection_destroy(PurpleHTTPConnection *conn) | |
183 { | |
184 g_free(conn->current_data); | |
185 g_free(conn->host); | |
186 | |
187 if (conn->requests) { | |
188 g_queue_foreach(conn->requests, (GFunc)jabber_bosh_http_request_destroy, NULL); | |
189 g_queue_free(conn->requests); | |
190 } | |
191 | |
192 if (conn->current_response) | |
193 jabber_bosh_http_response_destroy(conn->current_response); | |
194 | |
195 if (conn->ie_handle) | |
196 purple_input_remove(conn->ie_handle); | |
197 if (conn->fd > 0) | |
198 close(conn->fd); | |
199 | |
200 g_free(conn); | |
201 } | |
202 | |
203 PurpleBOSHConnection* | |
204 jabber_bosh_connection_init(JabberStream *js, const char *url) | |
140 { | 205 { |
141 PurpleBOSHConnection *conn; | 206 PurpleBOSHConnection *conn; |
142 char *host, *path, *user, *passwd; | 207 char *host, *path, *user, *passwd; |
143 int port; | 208 int port; |
144 | 209 |
169 conn->conn_a->userdata = conn; | 234 conn->conn_a->userdata = conn; |
170 | 235 |
171 return conn; | 236 return conn; |
172 } | 237 } |
173 | 238 |
174 void jabber_bosh_connection_destroy(PurpleBOSHConnection *conn) | 239 void |
240 jabber_bosh_connection_destroy(PurpleBOSHConnection *conn) | |
175 { | 241 { |
176 g_free(conn->host); | 242 g_free(conn->host); |
177 g_free(conn->path); | 243 g_free(conn->path); |
178 | 244 |
179 if (conn->conn_a) | 245 if (conn->conn_a) |
408 bosh_conn->receive_cb = jabber_bosh_connection_received; | 474 bosh_conn->receive_cb = jabber_bosh_connection_received; |
409 bosh_conn->connect_cb(bosh_conn); | 475 bosh_conn->connect_cb(bosh_conn); |
410 } else jabber_bosh_connection_boot(bosh_conn); | 476 } else jabber_bosh_connection_boot(bosh_conn); |
411 } | 477 } |
412 | 478 |
413 static void jabber_bosh_connection_refresh(PurpleHTTPConnection *conn) { | 479 void jabber_bosh_connection_refresh(PurpleBOSHConnection *conn) |
414 PurpleBOSHConnection *bosh_conn = conn->userdata; | 480 { |
415 jabber_bosh_connection_send(bosh_conn, NULL); | 481 jabber_bosh_connection_send(conn, NULL); |
416 } | 482 } |
417 | 483 |
418 static void jabber_bosh_http_connection_disconnected(PurpleHTTPConnection *conn) { | 484 static void jabber_bosh_http_connection_disconnected(PurpleHTTPConnection *conn) { |
419 PurpleBOSHConnection *bosh_conn = conn->userdata; | 485 PurpleBOSHConnection *bosh_conn = conn->userdata; |
420 bosh_conn->conn_a->connect_cb = jabber_bosh_connection_connected; | 486 bosh_conn->conn_a->connect_cb = jabber_bosh_connection_connected; |
536 } else { | 602 } else { |
537 purple_debug_info("jabber", "jabber_bosh_http_connection_receive: problem receiving data (%d)\n", len); | 603 purple_debug_info("jabber", "jabber_bosh_http_connection_receive: problem receiving data (%d)\n", len); |
538 } | 604 } |
539 } | 605 } |
540 | 606 |
541 static PurpleHTTPConnection* jabber_bosh_http_connection_init(const char *host, int port) | |
542 { | |
543 PurpleHTTPConnection *conn = g_new0(PurpleHTTPConnection, 1); | |
544 conn->host = g_strdup(host); | |
545 conn->port = port; | |
546 conn->fd = -1; | |
547 conn->requests = g_queue_new(); | |
548 | |
549 return conn; | |
550 } | |
551 | |
552 static void jabber_bosh_http_connection_destroy(PurpleHTTPConnection *conn) | |
553 { | |
554 g_free(conn->current_data); | |
555 g_free(conn->host); | |
556 | |
557 if (conn->requests) { | |
558 g_queue_foreach(conn->requests, (GFunc)jabber_bosh_http_request_destroy, NULL); | |
559 g_queue_free(conn->requests); | |
560 } | |
561 | |
562 if (conn->current_response) | |
563 jabber_bosh_http_response_destroy(conn->current_response); | |
564 | |
565 if (conn->ie_handle) | |
566 purple_input_remove(conn->ie_handle); | |
567 if (conn->fd > 0) | |
568 close(conn->fd); | |
569 | |
570 g_free(conn); | |
571 } | |
572 | |
573 static void jabber_bosh_http_connection_callback(gpointer data, gint source, const gchar *error) | 607 static void jabber_bosh_http_connection_callback(gpointer data, gint source, const gchar *error) |
574 { | 608 { |
575 PurpleHTTPConnection *conn = data; | 609 PurpleHTTPConnection *conn = data; |
576 PurpleBOSHConnection *bosh_conn = conn->userdata; | 610 PurpleBOSHConnection *bosh_conn = conn->userdata; |
577 PurpleConnection *gc = bosh_conn->js->gc; | 611 PurpleConnection *gc = bosh_conn->js->gc; |
630 g_free(tmp); | 664 g_free(tmp); |
631 if (write(conn->fd, packet, strlen(packet)) == -1) purple_debug_info("jabber", "send error\n"); | 665 if (write(conn->fd, packet, strlen(packet)) == -1) purple_debug_info("jabber", "send error\n"); |
632 g_queue_push_tail(conn->requests, req); | 666 g_queue_push_tail(conn->requests, req); |
633 } | 667 } |
634 | 668 |
635 static PurpleHTTPRequest* jabber_bosh_http_request_init(const char *method, | |
636 const char *path, PurpleHTTPRequestCallback cb, void *userdata) | |
637 { | |
638 PurpleHTTPRequest *req = g_new(PurpleHTTPRequest, 1); | |
639 req->method = g_strdup(method); | |
640 req->path = g_strdup(path); | |
641 req->cb = cb; | |
642 req->userdata = userdata; | |
643 req->header = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); | |
644 return req; | |
645 } | |
646 | |
647 static void jabber_bosh_http_request_add_to_header(PurpleHTTPRequest *req, const char *field, const char *value) { | 669 static void jabber_bosh_http_request_add_to_header(PurpleHTTPRequest *req, const char *field, const char *value) { |
648 char *f = g_strdup(field); | 670 char *f = g_strdup(field); |
649 char *v = g_strdup(value); | 671 char *v = g_strdup(value); |
650 g_hash_table_replace(req->header, f, v); | 672 g_hash_table_replace(req->header, f, v); |
651 } | 673 } |
652 | 674 |
653 void jabber_bosh_http_request_set_data(PurpleHTTPRequest *req, char *data, int len) { | |
654 req->data = data; | |
655 req->data_len = len; | |
656 } | |
657 | |
658 static void jabber_bosh_http_request_destroy(PurpleHTTPRequest *req) | |
659 { | |
660 g_hash_table_destroy(req->header); | |
661 g_free(req->method); | |
662 g_free(req->path); | |
663 g_free(req->data); | |
664 g_free(req); | |
665 } | |
666 | |
667 static PurpleHTTPResponse* jabber_bosh_http_response_init(void) | |
668 { | |
669 PurpleHTTPResponse *res = g_new0(PurpleHTTPResponse, 1); | |
670 res->header = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); | |
671 return res; | |
672 } | |
673 | |
674 static void jabber_bosh_http_response_destroy(PurpleHTTPResponse *res) | |
675 { | |
676 g_hash_table_destroy(res->header); | |
677 g_free(res->data); | |
678 g_free(res); | |
679 } |