comparison libpurple/protocols/simple/simple.c @ 22061:5295c7f113da

Patch from Will Hawkins to implement sending a SIP-If-Match header on subsequent PUBLISHes after receiving a SIP-Etag header. I made some minor tweaks to this, hopefully I didn't break anything. Fixes #4422.
author Daniel Atallah <daniel.atallah@gmail.com>
date Thu, 10 Jan 2008 20:24:58 +0000
parents c38d72677c8a
children 252b96b6a32c
comparison
equal deleted inserted replaced
22059:fdebef95b300 22061:5295c7f113da
1354 send_sip_request(sip->gc, "NOTIFY", watcher->name, watcher->name, hdr, doc, &watcher->dialog, NULL); 1354 send_sip_request(sip->gc, "NOTIFY", watcher->name, watcher->name, hdr, doc, &watcher->dialog, NULL);
1355 g_free(doc); 1355 g_free(doc);
1356 } 1356 }
1357 1357
1358 static gboolean process_publish_response(struct simple_account_data *sip, struct sipmsg *msg, struct transaction *tc) { 1358 static gboolean process_publish_response(struct simple_account_data *sip, struct sipmsg *msg, struct transaction *tc) {
1359
1360 const gchar *etag = NULL;
1361
1359 if(msg->response != 200 && msg->response != 408) { 1362 if(msg->response != 200 && msg->response != 408) {
1360 /* never send again */ 1363 /* never send again */
1361 sip->republish = -1; 1364 sip->republish = -1;
1362 } 1365 }
1366
1367 etag = sipmsg_find_header(msg, "SIP-Etag");
1368 if (etag) {
1369 /* we must store the etag somewhere. */
1370 g_free(sip->publish_etag);
1371 sip->publish_etag = g_strdup(etag);
1372 }
1373
1363 return TRUE; 1374 return TRUE;
1364 } 1375 }
1365 1376
1366 static void send_open_publish(struct simple_account_data *sip) { 1377 static void send_open_publish(struct simple_account_data *sip) {
1367 gchar *add_headers = NULL; 1378 gchar *add_headers = NULL;
1368 gchar *uri = g_strdup_printf("sip:%s@%s", sip->username, sip->servername); 1379 gchar *uri = g_strdup_printf("sip:%s@%s", sip->username, sip->servername);
1369 gchar *doc = gen_pidf(sip, TRUE); 1380 gchar *doc = gen_pidf(sip, TRUE);
1370 1381
1371 add_headers = g_strdup_printf("%s%d%s", 1382 add_headers = g_strdup_printf("%s%s%s%s%d\r\n%s",
1372 "Expires: ", 1383 sip->publish_etag ? "SIP-If-Match: " : "",
1373 PUBLISH_EXPIRATION, 1384 sip->publish_etag ? sip->publish_etag : "",
1374 "\r\nEvent: presence\r\n" 1385 sip->publish_etag ? "\r\n" : "",
1386 "Expires: ", PUBLISH_EXPIRATION,
1387 "Event: presence\r\n"
1375 "Content-Type: application/pidf+xml\r\n"); 1388 "Content-Type: application/pidf+xml\r\n");
1376 1389
1377 send_sip_request(sip->gc, "PUBLISH", uri, uri, 1390 send_sip_request(sip->gc, "PUBLISH", uri, uri,
1378 add_headers, doc, NULL, process_publish_response); 1391 add_headers, doc, NULL, process_publish_response);
1379 sip->republish = time(NULL) + PUBLISH_EXPIRATION - 50; 1392 sip->republish = time(NULL) + PUBLISH_EXPIRATION - 50;
1382 g_free(add_headers); 1395 g_free(add_headers);
1383 } 1396 }
1384 1397
1385 static void send_closed_publish(struct simple_account_data *sip) { 1398 static void send_closed_publish(struct simple_account_data *sip) {
1386 gchar *uri = g_strdup_printf("sip:%s@%s", sip->username, sip->servername); 1399 gchar *uri = g_strdup_printf("sip:%s@%s", sip->username, sip->servername);
1387 gchar *doc = gen_pidf(sip, FALSE); 1400 gchar *add_headers, *doc;
1388 send_sip_request(sip->gc, "PUBLISH", uri, uri, 1401
1389 "Expires: 600\r\nEvent: presence\r\n" 1402 add_headers = g_strdup_printf("%s%s%s%s",
1390 "Content-Type: application/pidf+xml\r\n", 1403 sip->publish_etag ? "SIP-If-Match: " : "",
1404 sip->publish_etag ? sip->publish_etag : "",
1405 sip->publish_etag ? "\r\n" : "",
1406 "Expires: 600\r\n"
1407 "Event: presence\r\n"
1408 "Content-Type: application/pidf+xml\r\n");
1409
1410 doc = gen_pidf(sip, FALSE);
1411 send_sip_request(sip->gc, "PUBLISH", uri, uri, add_headers,
1391 doc, NULL, process_publish_response); 1412 doc, NULL, process_publish_response);
1392 /*sip->republish = time(NULL) + 500;*/ 1413 /*sip->republish = time(NULL) + 500;*/
1393 g_free(uri); 1414 g_free(uri);
1394 g_free(doc); 1415 g_free(doc);
1416 g_free(add_headers);
1395 } 1417 }
1396 1418
1397 static void process_incoming_subscribe(struct simple_account_data *sip, struct sipmsg *msg) { 1419 static void process_incoming_subscribe(struct simple_account_data *sip, struct sipmsg *msg) {
1398 const char *from_hdr = sipmsg_find_header(msg, "From"); 1420 const char *from_hdr = sipmsg_find_header(msg, "From");
1399 gchar *from = parse_from(from_hdr); 1421 gchar *from = parse_from(from_hdr);
1946 g_free(sip->proxy.nonce); 1968 g_free(sip->proxy.nonce);
1947 g_free(sip->proxy.opaque); 1969 g_free(sip->proxy.opaque);
1948 g_free(sip->proxy.target); 1970 g_free(sip->proxy.target);
1949 g_free(sip->proxy.realm); 1971 g_free(sip->proxy.realm);
1950 g_free(sip->proxy.digest_session_key); 1972 g_free(sip->proxy.digest_session_key);
1973 g_free(sip->publish_etag);
1951 if(sip->txbuf) 1974 if(sip->txbuf)
1952 purple_circ_buffer_destroy(sip->txbuf); 1975 purple_circ_buffer_destroy(sip->txbuf);
1953 g_free(sip->realhostname); 1976 g_free(sip->realhostname);
1954 if(sip->listenpa) purple_input_remove(sip->listenpa); 1977 if(sip->listenpa) purple_input_remove(sip->listenpa);
1955 if(sip->tx_handler) purple_input_remove(sip->tx_handler); 1978 if(sip->tx_handler) purple_input_remove(sip->tx_handler);