libpurple/eventloop.c

Mon, 12 Sep 2022 22:54:13 -0500

author
Gary Kramlich <grim@reaperworld.com>
date
Mon, 12 Sep 2022 22:54:13 -0500
changeset 41685
ca22b00972d4
parent 39556
622bf98df0ac
child 41762
5c21747ff7dc
permissions
-rw-r--r--

Stop including internal.h everywhere when we really don't need it.

Testing Done:
Compiled, but didn't test on windows. As such I left all the networking stuff untouched as that's where windows will really need it and that can be done in another rr.

Reviewed at https://reviews.imfreedom.org/r/1764/

20147
66f05a854eee applied changes from 8a731bbd0197fbcc91a705c2d8f528154216defa
Richard Laager <rlaager@pidgin.im>
parents: 19859
diff changeset
1 /* purple
8273
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
2 *
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15754
diff changeset
3 * Purple is the legal property of its developers, whose names are too numerous
8273
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
4 * to list here. Please refer to the COPYRIGHT file distributed with this
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
5 * source distribution.
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
6 *
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
7 * This program is free software; you can redistribute it and/or modify
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
8 * it under the terms of the GNU General Public License as published by
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
9 * the Free Software Foundation; either version 2 of the License, or
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
10 * (at your option) any later version.
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
11 *
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful,
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
15 * GNU General Public License for more details.
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
16 *
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
17 * You should have received a copy of the GNU General Public License
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
18 * along with this program; if not, write to the Free Software
19859
71d37b57eff2 The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 19733
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
8273
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
20 */
41685
ca22b00972d4 Stop including internal.h everywhere when we really don't need it.
Gary Kramlich <grim@reaperworld.com>
parents: 39556
diff changeset
21
ca22b00972d4 Stop including internal.h everywhere when we really don't need it.
Gary Kramlich <grim@reaperworld.com>
parents: 39556
diff changeset
22 #include <unistd.h>
ca22b00972d4 Stop including internal.h everywhere when we really don't need it.
Gary Kramlich <grim@reaperworld.com>
parents: 39556
diff changeset
23
8273
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
24 #include "eventloop.h"
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
25
38418
9d86663a7437 eventloop: Replace eventloop input functions with Pidgin versions
Mike Ruprecht <cmaiku@gmail.com>
parents: 38417
diff changeset
26 #define PURPLE_GLIB_READ_COND (G_IO_IN | G_IO_HUP | G_IO_ERR)
9d86663a7437 eventloop: Replace eventloop input functions with Pidgin versions
Mike Ruprecht <cmaiku@gmail.com>
parents: 38417
diff changeset
27 #define PURPLE_GLIB_WRITE_COND (G_IO_OUT | G_IO_HUP | G_IO_ERR | G_IO_NVAL)
9d86663a7437 eventloop: Replace eventloop input functions with Pidgin versions
Mike Ruprecht <cmaiku@gmail.com>
parents: 38417
diff changeset
28
39556
622bf98df0ac Remove unnecessary struct tags.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38434
diff changeset
29 typedef struct {
38418
9d86663a7437 eventloop: Replace eventloop input functions with Pidgin versions
Mike Ruprecht <cmaiku@gmail.com>
parents: 38417
diff changeset
30 PurpleInputFunction function;
9d86663a7437 eventloop: Replace eventloop input functions with Pidgin versions
Mike Ruprecht <cmaiku@gmail.com>
parents: 38417
diff changeset
31 guint result;
9d86663a7437 eventloop: Replace eventloop input functions with Pidgin versions
Mike Ruprecht <cmaiku@gmail.com>
parents: 38417
diff changeset
32 gpointer data;
9d86663a7437 eventloop: Replace eventloop input functions with Pidgin versions
Mike Ruprecht <cmaiku@gmail.com>
parents: 38417
diff changeset
33 } PurpleIOClosure;
9d86663a7437 eventloop: Replace eventloop input functions with Pidgin versions
Mike Ruprecht <cmaiku@gmail.com>
parents: 38417
diff changeset
34
9d86663a7437 eventloop: Replace eventloop input functions with Pidgin versions
Mike Ruprecht <cmaiku@gmail.com>
parents: 38417
diff changeset
35 static gboolean
9d86663a7437 eventloop: Replace eventloop input functions with Pidgin versions
Mike Ruprecht <cmaiku@gmail.com>
parents: 38417
diff changeset
36 purple_io_invoke(GIOChannel *source, GIOCondition condition, gpointer data)
9d86663a7437 eventloop: Replace eventloop input functions with Pidgin versions
Mike Ruprecht <cmaiku@gmail.com>
parents: 38417
diff changeset
37 {
9d86663a7437 eventloop: Replace eventloop input functions with Pidgin versions
Mike Ruprecht <cmaiku@gmail.com>
parents: 38417
diff changeset
38 PurpleIOClosure *closure = data;
9d86663a7437 eventloop: Replace eventloop input functions with Pidgin versions
Mike Ruprecht <cmaiku@gmail.com>
parents: 38417
diff changeset
39 PurpleInputCondition purple_cond = 0;
9d86663a7437 eventloop: Replace eventloop input functions with Pidgin versions
Mike Ruprecht <cmaiku@gmail.com>
parents: 38417
diff changeset
40
9d86663a7437 eventloop: Replace eventloop input functions with Pidgin versions
Mike Ruprecht <cmaiku@gmail.com>
parents: 38417
diff changeset
41 if (condition & PURPLE_GLIB_READ_COND)
9d86663a7437 eventloop: Replace eventloop input functions with Pidgin versions
Mike Ruprecht <cmaiku@gmail.com>
parents: 38417
diff changeset
42 purple_cond |= PURPLE_INPUT_READ;
9d86663a7437 eventloop: Replace eventloop input functions with Pidgin versions
Mike Ruprecht <cmaiku@gmail.com>
parents: 38417
diff changeset
43 if (condition & PURPLE_GLIB_WRITE_COND)
9d86663a7437 eventloop: Replace eventloop input functions with Pidgin versions
Mike Ruprecht <cmaiku@gmail.com>
parents: 38417
diff changeset
44 purple_cond |= PURPLE_INPUT_WRITE;
9d86663a7437 eventloop: Replace eventloop input functions with Pidgin versions
Mike Ruprecht <cmaiku@gmail.com>
parents: 38417
diff changeset
45
9d86663a7437 eventloop: Replace eventloop input functions with Pidgin versions
Mike Ruprecht <cmaiku@gmail.com>
parents: 38417
diff changeset
46 #ifdef _WIN32
9d86663a7437 eventloop: Replace eventloop input functions with Pidgin versions
Mike Ruprecht <cmaiku@gmail.com>
parents: 38417
diff changeset
47 if(!purple_cond) {
9d86663a7437 eventloop: Replace eventloop input functions with Pidgin versions
Mike Ruprecht <cmaiku@gmail.com>
parents: 38417
diff changeset
48 return TRUE;
9d86663a7437 eventloop: Replace eventloop input functions with Pidgin versions
Mike Ruprecht <cmaiku@gmail.com>
parents: 38417
diff changeset
49 }
9d86663a7437 eventloop: Replace eventloop input functions with Pidgin versions
Mike Ruprecht <cmaiku@gmail.com>
parents: 38417
diff changeset
50 #endif /* _WIN32 */
9d86663a7437 eventloop: Replace eventloop input functions with Pidgin versions
Mike Ruprecht <cmaiku@gmail.com>
parents: 38417
diff changeset
51
9d86663a7437 eventloop: Replace eventloop input functions with Pidgin versions
Mike Ruprecht <cmaiku@gmail.com>
parents: 38417
diff changeset
52 closure->function(closure->data, g_io_channel_unix_get_fd(source),
9d86663a7437 eventloop: Replace eventloop input functions with Pidgin versions
Mike Ruprecht <cmaiku@gmail.com>
parents: 38417
diff changeset
53 purple_cond);
9d86663a7437 eventloop: Replace eventloop input functions with Pidgin versions
Mike Ruprecht <cmaiku@gmail.com>
parents: 38417
diff changeset
54
9d86663a7437 eventloop: Replace eventloop input functions with Pidgin versions
Mike Ruprecht <cmaiku@gmail.com>
parents: 38417
diff changeset
55 return TRUE;
9d86663a7437 eventloop: Replace eventloop input functions with Pidgin versions
Mike Ruprecht <cmaiku@gmail.com>
parents: 38417
diff changeset
56 }
9d86663a7437 eventloop: Replace eventloop input functions with Pidgin versions
Mike Ruprecht <cmaiku@gmail.com>
parents: 38417
diff changeset
57
8280
f448633d3f3a [gaim-migrate @ 9004]
Scott Lamb
parents: 8273
diff changeset
58 guint
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15754
diff changeset
59 purple_input_add(int source, PurpleInputCondition condition, PurpleInputFunction func, gpointer user_data)
8273
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
60 {
38418
9d86663a7437 eventloop: Replace eventloop input functions with Pidgin versions
Mike Ruprecht <cmaiku@gmail.com>
parents: 38417
diff changeset
61 PurpleIOClosure *closure = g_new0(PurpleIOClosure, 1);
9d86663a7437 eventloop: Replace eventloop input functions with Pidgin versions
Mike Ruprecht <cmaiku@gmail.com>
parents: 38417
diff changeset
62 GIOChannel *channel;
9d86663a7437 eventloop: Replace eventloop input functions with Pidgin versions
Mike Ruprecht <cmaiku@gmail.com>
parents: 38417
diff changeset
63 GIOCondition cond = 0;
9d86663a7437 eventloop: Replace eventloop input functions with Pidgin versions
Mike Ruprecht <cmaiku@gmail.com>
parents: 38417
diff changeset
64
9d86663a7437 eventloop: Replace eventloop input functions with Pidgin versions
Mike Ruprecht <cmaiku@gmail.com>
parents: 38417
diff changeset
65 closure->function = func;
9d86663a7437 eventloop: Replace eventloop input functions with Pidgin versions
Mike Ruprecht <cmaiku@gmail.com>
parents: 38417
diff changeset
66 closure->data = user_data;
9d86663a7437 eventloop: Replace eventloop input functions with Pidgin versions
Mike Ruprecht <cmaiku@gmail.com>
parents: 38417
diff changeset
67
9d86663a7437 eventloop: Replace eventloop input functions with Pidgin versions
Mike Ruprecht <cmaiku@gmail.com>
parents: 38417
diff changeset
68 if (condition & PURPLE_INPUT_READ)
9d86663a7437 eventloop: Replace eventloop input functions with Pidgin versions
Mike Ruprecht <cmaiku@gmail.com>
parents: 38417
diff changeset
69 cond |= PURPLE_GLIB_READ_COND;
9d86663a7437 eventloop: Replace eventloop input functions with Pidgin versions
Mike Ruprecht <cmaiku@gmail.com>
parents: 38417
diff changeset
70 if (condition & PURPLE_INPUT_WRITE)
9d86663a7437 eventloop: Replace eventloop input functions with Pidgin versions
Mike Ruprecht <cmaiku@gmail.com>
parents: 38417
diff changeset
71 cond |= PURPLE_GLIB_WRITE_COND;
8273
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
72
38418
9d86663a7437 eventloop: Replace eventloop input functions with Pidgin versions
Mike Ruprecht <cmaiku@gmail.com>
parents: 38417
diff changeset
73 #ifdef _WIN32
9d86663a7437 eventloop: Replace eventloop input functions with Pidgin versions
Mike Ruprecht <cmaiku@gmail.com>
parents: 38417
diff changeset
74 channel = g_io_channel_win32_new_socket(source);
9d86663a7437 eventloop: Replace eventloop input functions with Pidgin versions
Mike Ruprecht <cmaiku@gmail.com>
parents: 38417
diff changeset
75 #else
9d86663a7437 eventloop: Replace eventloop input functions with Pidgin versions
Mike Ruprecht <cmaiku@gmail.com>
parents: 38417
diff changeset
76 channel = g_io_channel_unix_new(source);
9d86663a7437 eventloop: Replace eventloop input functions with Pidgin versions
Mike Ruprecht <cmaiku@gmail.com>
parents: 38417
diff changeset
77 #endif
9d86663a7437 eventloop: Replace eventloop input functions with Pidgin versions
Mike Ruprecht <cmaiku@gmail.com>
parents: 38417
diff changeset
78
9d86663a7437 eventloop: Replace eventloop input functions with Pidgin versions
Mike Ruprecht <cmaiku@gmail.com>
parents: 38417
diff changeset
79 closure->result = g_io_add_watch_full(channel, G_PRIORITY_DEFAULT,
9d86663a7437 eventloop: Replace eventloop input functions with Pidgin versions
Mike Ruprecht <cmaiku@gmail.com>
parents: 38417
diff changeset
80 cond, purple_io_invoke, closure, g_free);
9d86663a7437 eventloop: Replace eventloop input functions with Pidgin versions
Mike Ruprecht <cmaiku@gmail.com>
parents: 38417
diff changeset
81
9d86663a7437 eventloop: Replace eventloop input functions with Pidgin versions
Mike Ruprecht <cmaiku@gmail.com>
parents: 38417
diff changeset
82 g_io_channel_unref(channel);
9d86663a7437 eventloop: Replace eventloop input functions with Pidgin versions
Mike Ruprecht <cmaiku@gmail.com>
parents: 38417
diff changeset
83 return closure->result;
8273
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
84 }
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
85
15729
6932ac4e5b3d Change out source_remove and input_remove eventloop functions to return
Mark Doliner <markdoliner@pidgin.im>
parents: 15435
diff changeset
86 gboolean
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15754
diff changeset
87 purple_input_remove(guint tag)
8273
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
88 {
38418
9d86663a7437 eventloop: Replace eventloop input functions with Pidgin versions
Mike Ruprecht <cmaiku@gmail.com>
parents: 38417
diff changeset
89 return g_source_remove(tag);
8273
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
90 }
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
91
15746
017e33725857 Added a new GaimEventLoopUiOps item, input_get_error(). This function allows the UI to return the current error status on a socket/input. If the UI does not implement it (as Pidgin and gntgaim do not, since glib's handling of sockets is sane), it is just a wrapper around getsockopt(). Implemented or not, its return values should match those of getsockopt() with a level of SOL_SOCKET and an option of SO_ERROR. For curious souls, Adium will be using this to provide a working version of getsockopt(); the CoreFoundation CFSocket class which is used for socket read/write calls getsockopt() with SO_ERROR itself, thereby clearing the error flag [as documented in getsockopt()'s behavior], so depending upon it for determining if an error occurred leads to significant misbehavior.
Evan Schoenberg <evands@pidgin.im>
parents: 15729
diff changeset
92 int
33291
b70ab10887a7 New custom resolver, that uses libpurple for DNS queries. Get rid of old win32 resolver. Refs#343. Fixes #6263
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 28981
diff changeset
93 purple_input_pipe(int pipefd[2])
b70ab10887a7 New custom resolver, that uses libpurple for DNS queries. Get rid of old win32 resolver. Refs#343. Fixes #6263
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 28981
diff changeset
94 {
b70ab10887a7 New custom resolver, that uses libpurple for DNS queries. Get rid of old win32 resolver. Refs#343. Fixes #6263
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 28981
diff changeset
95 #ifdef _WIN32
b70ab10887a7 New custom resolver, that uses libpurple for DNS queries. Get rid of old win32 resolver. Refs#343. Fixes #6263
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 28981
diff changeset
96 return wpurple_input_pipe(pipefd);
b70ab10887a7 New custom resolver, that uses libpurple for DNS queries. Get rid of old win32 resolver. Refs#343. Fixes #6263
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 28981
diff changeset
97 #else
b70ab10887a7 New custom resolver, that uses libpurple for DNS queries. Get rid of old win32 resolver. Refs#343. Fixes #6263
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 28981
diff changeset
98 return pipe(pipefd);
b70ab10887a7 New custom resolver, that uses libpurple for DNS queries. Get rid of old win32 resolver. Refs#343. Fixes #6263
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 28981
diff changeset
99 #endif
b70ab10887a7 New custom resolver, that uses libpurple for DNS queries. Get rid of old win32 resolver. Refs#343. Fixes #6263
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 28981
diff changeset
100 }

mercurial