pidgin.vv.yahoo.voice: afa74845: Wait for the Sofia-SIP shutdown to finis...

maiku at pidgin.im maiku at pidgin.im
Sat Aug 29 07:55:43 EDT 2009


-----------------------------------------------------------------
Revision: afa748458318b61b31b603424cd55699245c92f0
Ancestor: 77a5accab64083fba4a6d68d1275b135288234a1
Author: maiku at pidgin.im
Date: 2009-08-29T06:08:57
Branch: im.pidgin.pidgin.vv.yahoo.voice
URL: http://d.pidgin.im/viewmtn/revision/info/afa748458318b61b31b603424cd55699245c92f0

Modified files:
        libpurple/protocols/yahoo/libymsg.h
        libpurple/protocols/yahoo/yahoo_sip.c
        libpurple/protocols/yahoo/yahoo_sip.h

ChangeLog: 

Wait for the Sofia-SIP shutdown to finish AKA don't crash on exit in gdb.

-------------- next part --------------
============================================================
--- libpurple/protocols/yahoo/libymsg.h	f95356261bc098a01ea0d90e67f758fd05e39238
+++ libpurple/protocols/yahoo/libymsg.h	d4d6a3803b1e90bda4d2c91e8893a8778bfa14b7
@@ -28,6 +28,7 @@
 #include "circbuffer.h"
 #include "cmds.h"
 #include "prpl.h"
+#include "yahoo_sip.h"
 
 #define YAHOO_PAGER_HOST "scsa.msg.yahoo.com"
 #define YAHOO_PAGER_PORT 5050
@@ -150,8 +151,6 @@ struct _YchtConn;
 };
 
 struct _YchtConn;
-struct nua_s;
-struct nua_handle_s;
 
 typedef struct _YahooPersonalDetails {
 	char *id;
@@ -244,9 +243,7 @@ typedef struct {
 	GHashTable *sms_carrier;	/* sms carrier data */
 	guint yahoo_p2p_server_timeout_handle;
 
-	/* SIP variables */
-	struct nua_s *nua;
-	struct nua_handle_s *nh;
+	YahooSip *ysip;
 } YahooData;
 
 #define YAHOO_MAX_STATUS_MESSAGE_LENGTH (255)
============================================================
--- libpurple/protocols/yahoo/yahoo_sip.c	73fde3dbf78211630f110ec6c86fbecf2bd3ba9d
+++ libpurple/protocols/yahoo/yahoo_sip.c	4006c0681e970444a80985f2e9283979fbbc83fd
@@ -38,6 +38,13 @@
 #include <sofia-sip/sip_header.h>
 #include <sofia-sip/sdp.h>
 
+struct _YahooSip {
+	su_root_t *root;
+	nua_t *nua;
+	nua_handle_t *nh;
+	gboolean shutdown;
+};
+
 /* This is the y64 alphabet... it's like base64, but has a . and a _ */
 static const char base64digits[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._";
 
@@ -279,8 +286,12 @@ event_callback(nua_event_t event, int st
 		purple_timeout_add_seconds(60, send_yahooref, nh);
 	} else if (event == nua_r_unregister && status == 200) {
 		nua_shutdown(nua);
-	} else if (event == nua_r_shutdown && status == 200) {
-		nua_destroy(nua);
+	} else if (event == nua_r_shutdown && status >= 200) {
+		PurpleAccount *account = magic;
+		PurpleConnection *pc = purple_account_get_connection(account);
+		YahooData *yd = pc->proto_data;
+		YahooSip *ysip = yd->ysip;
+		ysip->shutdown = TRUE;
 	} else if (event == nua_i_invite) {
 		PurpleMedia *media;
 		PurpleAccount *account = magic;
@@ -421,18 +432,21 @@ yahoo_sip_init(PurpleAccount *account)
 {
 	PurpleConnection *pc = purple_account_get_connection(account);
 	YahooData *yd = purple_connection_get_protocol_data(pc);
+	YahooSip *ysip = yd->ysip = g_new0(YahooSip, 1);
 	GSource *gsource;
-	su_root_t *sofia_event_loop;
 	gchar *sip_str;
 
 	purple_debug_info("yahoo", "Starting Sofia-SIP\n");
 
-	sofia_event_loop = su_glib_root_create(NULL);
+	ysip->root = su_glib_root_create(NULL);
 
-	gsource = su_glib_root_gsource(sofia_event_loop);
+	gsource = su_glib_root_gsource(ysip->root);
 	g_source_attach(gsource, g_main_context_default());
 
-	yd->nua = nua_create(sofia_event_loop, event_callback, account,
+	/* Run in the same thread as purple itself */
+	su_root_threading(ysip->root, 0);
+
+	ysip->nua = nua_create(ysip->root, event_callback, account,
 			NUTAG_URL("sip:*:*;transport=tcp"),
 			NUTAG_M_PARAMS("transport=tcp"),
 			NUTAG_MEDIA_ENABLE(1),
@@ -449,12 +463,12 @@ yahoo_sip_init(PurpleAccount *account)
 	/* XXX: Use the real address here or resolve it */
 	sip_str = g_strdup_printf("sip:%s at 68.142.233.179:443;transport=tcp",
 			purple_url_encode(purple_account_get_username(account)));
-	yd->nh = nua_handle(yd->nua, NULL,
+	ysip->nh = nua_handle(ysip->nua, NULL,
 			SIPTAG_TO_STR(sip_str),
 			TAG_END());
 	g_free(sip_str);
 
-	nua_register(yd->nh,
+	nua_register(ysip->nh,
 #if 0
 			/* Possibly needed for actual invitations? */
 			NUTAG_M_DISPLAY("1"),
@@ -471,13 +485,22 @@ yahoo_sip_uninit(PurpleAccount *account)
 {
 	PurpleConnection *pc = purple_account_get_connection(account);
 	YahooData *yd = purple_connection_get_protocol_data(pc);
+	YahooSip *ysip = yd->ysip;
 
+	if (nua_handle_has_registrations(ysip->nh) == 1)
+		nua_unregister(ysip->nh, TAG_NULL());
+	else
+		nua_shutdown(ysip->nua);
+
 	/*
-	 * XXX: These don't always finish when shutting down.
-	 * I don't know if that's a problem or not...
+	 * I don't like that this is potentially an infinite loop,
+	 * but I'm not sure how else to wait for the shutdown signal
+	 * to finish. If it doesn't finish before nua_destroy is
+	 * called or nua_destroy isn't called, it crashes gdb for me.
 	 */
-	if (nua_handle_has_registrations(yd->nh) == 1)
-		nua_unregister(yd->nh, TAG_NULL());
-	else
-		nua_shutdown(yd->nua);
+	while (ysip->shutdown == FALSE)
+		su_root_sleep(ysip->root, 10L);
+
+	nua_destroy(ysip->nua);
+	g_free(ysip);
 }
============================================================
--- libpurple/protocols/yahoo/yahoo_sip.h	c0d485a2bc5210d9db0424c227a898f66475d1f7
+++ libpurple/protocols/yahoo/yahoo_sip.h	8e8e3abad02fa3680dbe8f40df75539ee7ce2460
@@ -27,6 +27,8 @@
 
 #include "account.h"
 
+typedef struct _YahooSip YahooSip;
+
 void yahoo_sip_init(PurpleAccount *account);
 void yahoo_sip_uninit(PurpleAccount *account);
 


More information about the Commits mailing list