comparison libpurple/protocols/jabber/bosh.c @ 25605:f747c682a0d9

* calling PurpleBOSHConnection's receive_cb
author Tobias Markmann <tfar@soc.pidgin.im>
date Tue, 12 Aug 2008 12:40:48 +0000
parents e28f1711f402
children b175b16768ac
comparison
equal deleted inserted replaced
25604:e28f1711f402 25605:f747c682a0d9
53 53
54 conn->conn_a = g_new0(PurpleHTTPConnection, 1); 54 conn->conn_a = g_new0(PurpleHTTPConnection, 1);
55 jabber_bosh_http_connection_init(conn->conn_a, conn->account, conn->host, conn->port); 55 jabber_bosh_http_connection_init(conn->conn_a, conn->account, conn->host, conn->port);
56 conn->conn_a->userdata = conn; 56 conn->conn_a->userdata = conn;
57 } 57 }
58
59 void jabber_bosh_connection_bood_response(PurpleBOSHConnection *conn, xmlnode *node) {
60
61 }
62
63 void jabber_bosh_connection_received(PurpleBOSHConnection *conn, xmlnode *node) {
64 xmlnode_free(node);
65 }
66
58 67
59 static void jabber_bosh_connection_boot(PurpleBOSHConnection *conn) { 68 static void jabber_bosh_connection_boot(PurpleBOSHConnection *conn) {
60 char *tmp; 69 char *tmp;
61 xmlnode *init = xmlnode_new("body"); 70 xmlnode *init = xmlnode_new("body");
62 xmlnode_set_attrib(init, "content", "text/xml; charset=utf-8"); 71 xmlnode_set_attrib(init, "content", "text/xml; charset=utf-8");
73 xmlnode_set_attrib(init, "wait", "60"); /* this should be adjusted automatically according to real time network behavior */ 82 xmlnode_set_attrib(init, "wait", "60"); /* this should be adjusted automatically according to real time network behavior */
74 xmlnode_set_attrib(init, "ack", "0"); 83 xmlnode_set_attrib(init, "ack", "0");
75 xmlnode_set_attrib(init, "xmlns", "http://jabber.org/protocol/httpbind"); 84 xmlnode_set_attrib(init, "xmlns", "http://jabber.org/protocol/httpbind");
76 xmlnode_set_attrib(init, "hold", "1"); 85 xmlnode_set_attrib(init, "hold", "1");
77 86
87 conn->receive_cb = jabber_bosh_connection_bood_response;
78 jabber_bosh_connection_send(conn, init); 88 jabber_bosh_connection_send(conn, init);
79 } 89 }
80 90
81 void jabber_bosh_connection_login_cb(PurpleHTTPRequest *req, PurpleHTTPResponse *res, void *userdata) { 91 void jabber_bosh_connection_http_received_cb(PurpleHTTPRequest *req, PurpleHTTPResponse *res, void *userdata) {
82 purple_debug_info("jabber", "RECEIVED FIRST HTTP RESPONSE\n"); 92 PurpleBOSHConnection *conn = userdata;
83 printf("\nDATA\n\n%s\n", res->data); 93 if (conn->receive_cb) {
94 xmlnode *node = xmlnode_from_str(res->data, res->data_len);
95 char *txt = xmlnode_to_formatted_str(node, NULL);
96 printf("\njabber_bosh_connection_http_received_cb\n%s\n", txt);
97 g_free(txt);
98 conn->receive_cb(conn, node);
99 } else purple_debug_info("jabber", "missing receive_cb of PurpleBOSHConnection.\n");
84 } 100 }
85 101
86 void jabber_bosh_connection_send(PurpleBOSHConnection *conn, xmlnode *node) { 102 void jabber_bosh_connection_send(PurpleBOSHConnection *conn, xmlnode *node) {
87 PurpleHTTPRequest *request = g_new0(PurpleHTTPRequest, 1); 103 PurpleHTTPRequest *request = g_new0(PurpleHTTPRequest, 1);
88 jabber_bosh_http_request_init(request, "POST", g_strdup_printf("/%s", conn->path), jabber_bosh_connection_login_cb, conn); 104 jabber_bosh_http_request_init(request, "POST", g_strdup_printf("/%s", conn->path), jabber_bosh_connection_http_received_cb, conn);
89 jabber_bosh_http_request_add_to_header(request, "Content-Encoding", "text/xml; charset=utf-8"); 105 jabber_bosh_http_request_add_to_header(request, "Content-Encoding", "text/xml; charset=utf-8");
90 request->data = xmlnode_to_str(node, &(request->data_len)); 106 request->data = xmlnode_to_str(node, &(request->data_len));
91 jabber_bosh_http_request_add_to_header(request, "Content-Length", g_strdup_printf("%d", (int)strlen(request->data))); 107 jabber_bosh_http_request_add_to_header(request, "Content-Length", g_strdup_printf("%d", (int)strlen(request->data)));
92 jabber_bosh_http_connection_send_request(conn->conn_a, request); 108 jabber_bosh_http_connection_send_request(conn->conn_a, request);
93 } 109 }
94 110
95 static void jabber_bosh_connection_connected(PurpleHTTPConnection *conn) { 111 static void jabber_bosh_connection_connected(PurpleHTTPConnection *conn) {
96 PurpleBOSHConnection *bosh_conn = conn->userdata; 112 PurpleBOSHConnection *bosh_conn = conn->userdata;
97 113 bosh_conn->receive_cb = jabber_bosh_connection_received;
98 if (bosh_conn->ready && bosh_conn->connect_cb) bosh_conn->connect_cb(bosh_conn); 114 if (bosh_conn->ready && bosh_conn->connect_cb) bosh_conn->connect_cb(bosh_conn);
99 else jabber_bosh_connection_boot(bosh_conn); 115 else jabber_bosh_connection_boot(bosh_conn);
100 } 116 }
101 117
102 void jabber_bosh_connection_connect(PurpleBOSHConnection *conn) { 118 void jabber_bosh_connection_connect(PurpleBOSHConnection *conn) {