summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>2012-10-05 06:56:13 +0000
committerMike Blumenkrantz <michael.blumenkrantz@gmail.com>2012-10-05 06:56:13 +0000
commit4f3d17626624e1b60db4eb9e0e4acd2c2909bcd7 (patch)
tree41f23a5bc08cac57080383886dbfa788d5192b33
parentb8d65ef52c7f8e2ef2575d5f67a3b4aab092ba11 (diff)
add pulse_disconnect() function and properly send disconnect events when disconnecting during pulse auth
SVN revision: 77505
-rw-r--r--Pulse.h1
-rw-r--r--msg.c15
-rw-r--r--pa.c32
3 files changed, 30 insertions, 18 deletions
diff --git a/Pulse.h b/Pulse.h
index dc6e1a4..bbfabde 100644
--- a/Pulse.h
+++ b/Pulse.h
@@ -37,6 +37,7 @@ void pulse_shutdown(void);
37 37
38Pulse *pulse_new(void); 38Pulse *pulse_new(void);
39Eina_Bool pulse_connect(Pulse *conn); 39Eina_Bool pulse_connect(Pulse *conn);
40void pulse_disconnect(Pulse *conn);
40void pulse_free(Pulse *conn); 41void pulse_free(Pulse *conn);
41void pulse_cb_set(Pulse *conn, uint32_t tagnum, Pulse_Cb cb); 42void pulse_cb_set(Pulse *conn, uint32_t tagnum, Pulse_Cb cb);
42void pulse_server_info_free(Pulse_Server_Info *ev); 43void pulse_server_info_free(Pulse_Server_Info *ev);
diff --git a/msg.c b/msg.c
index 6b6a002..adb6952 100644
--- a/msg.c
+++ b/msg.c
@@ -33,8 +33,7 @@ msg_recv_creds(Pulse *conn, Pulse_Tag *tag)
33 if (errno != EAGAIN) 33 if (errno != EAGAIN)
34 { 34 {
35 ERR("%d: %s", errno, strerror(errno)); 35 ERR("%d: %s", errno, strerror(errno));
36 ecore_main_fd_handler_del(conn->fdh); 36 pulse_disconnect(conn);
37 conn->fdh = NULL;
38 } 37 }
39 } 38 }
40 else 39 else
@@ -84,8 +83,7 @@ msg_recv(Pulse *conn, Pulse_Tag *tag)
84 if (errno != EAGAIN) 83 if (errno != EAGAIN)
85 { 84 {
86 ERR("%d: %s", errno, strerror(errno)); 85 ERR("%d: %s", errno, strerror(errno));
87 ecore_main_fd_handler_del(conn->fdh); 86 pulse_disconnect(conn);
88 conn->fdh = NULL;
89 } 87 }
90 } 88 }
91 else 89 else
@@ -138,8 +136,7 @@ msg_sendmsg_creds(Pulse *conn, Pulse_Tag *tag)
138 if (errno != EAGAIN) 136 if (errno != EAGAIN)
139 { 137 {
140 ERR("%d: %s", errno, strerror(errno)); 138 ERR("%d: %s", errno, strerror(errno));
141 ecore_main_fd_handler_del(conn->fdh); 139 pulse_disconnect(conn);
142 conn->fdh = NULL;
143 } 140 }
144 } 141 }
145 else 142 else
@@ -165,8 +162,7 @@ msg_send_creds(Pulse *conn, Pulse_Tag *tag)
165 if (errno != EAGAIN) 162 if (errno != EAGAIN)
166 { 163 {
167 ERR("%d: %s", errno, strerror(errno)); 164 ERR("%d: %s", errno, strerror(errno));
168 ecore_main_fd_handler_del(conn->fdh); 165 pulse_disconnect(conn);
169 conn->fdh = NULL;
170 } 166 }
171 } 167 }
172 else 168 else
@@ -198,8 +194,7 @@ msg_send(Pulse *conn, Pulse_Tag *tag)
198 if (errno != EAGAIN) 194 if (errno != EAGAIN)
199 { 195 {
200 ERR("%d: %s", errno, strerror(errno)); 196 ERR("%d: %s", errno, strerror(errno));
201 ecore_main_fd_handler_del(conn->fdh); 197 pulse_disconnect(conn);
202 conn->fdh = NULL;
203 } 198 }
204 } 199 }
205 else 200 else
diff --git a/pa.c b/pa.c
index 5bc6a3d..497beb8 100644
--- a/pa.c
+++ b/pa.c
@@ -196,10 +196,7 @@ pulse_recv(Pulse *conn, Ecore_Fd_Handler *fdh)
196 if (!tag->dsize) 196 if (!tag->dsize)
197 { 197 {
198 ERR("Kicked!"); 198 ERR("Kicked!");
199 conn->state = PA_STATE_INIT; 199 pulse_disconnect(conn);
200 ecore_main_fd_handler_del(conn->fdh);
201 close(conn->fd);
202 ecore_event_add(PULSE_EVENT_DISCONNECTED, conn, pulse_fake_free, NULL);
203 return NULL; 200 return NULL;
204 } 201 }
205 tag->data = malloc(tag->dsize); 202 tag->data = malloc(tag->dsize);
@@ -273,6 +270,7 @@ fdh_func(Pulse *conn, Ecore_Fd_Handler *fdh)
273 270
274 if (!wprev->auth) 271 if (!wprev->auth)
275 msg_sendmsg_creds(conn, wprev); 272 msg_sendmsg_creds(conn, wprev);
273
276 274
277 if (wprev->auth && msg_send(conn, wprev)) 275 if (wprev->auth && msg_send(conn, wprev))
278 { 276 {
@@ -353,10 +351,7 @@ con(Pulse *conn, int type __UNUSED__, Ecore_Con_Event_Server_Add *ev)
353 fd = ecore_con_server_fd_get(ev->server); 351 fd = ecore_con_server_fd_get(ev->server);
354 if (fd == -1) 352 if (fd == -1)
355 { 353 {
356 conn->state = PA_STATE_INIT; 354 pulse_disconnect(conn);
357 ecore_con_server_del(ev->server);
358 conn->svr = NULL;
359 ecore_event_add(PULSE_EVENT_DISCONNECTED, conn, pulse_fake_free, NULL);
360 return ECORE_CALLBACK_RENEW; 355 return ECORE_CALLBACK_RENEW;
361 } 356 }
362 conn->fd = dup(fd); 357 conn->fd = dup(fd);
@@ -752,6 +747,27 @@ pulse_connect(Pulse *conn)
752} 747}
753 748
754void 749void
750pulse_disconnect(Pulse *conn)
751{
752 EINA_SAFETY_ON_NULL_RETURN(conn);
753 if (conn->state == PA_STATE_INIT) return;
754 conn->state = PA_STATE_INIT;
755 if (conn->fdh)
756 {
757 ecore_main_fd_handler_del(conn->fdh);
758 conn->fdh = NULL;
759 close(conn->fd);
760 conn->fd = -1;
761 }
762 else if (conn->svr)
763 {
764 ecore_con_server_del(conn->svr);
765 conn->svr = NULL;
766 }
767 ecore_event_add(PULSE_EVENT_DISCONNECTED, conn, pulse_fake_free, NULL);
768}
769
770void
755pulse_server_info_free(Pulse_Server_Info *ev) 771pulse_server_info_free(Pulse_Server_Info *ev)
756{ 772{
757 if (!ev) return; 773 if (!ev) return;