annotate plugins/perl/perl-handlers.c @ 13854:a4c30c1d9de8

[gaim-migrate @ 16313] Unnecessary variables are bad, mmkay. committer: Tailor Script <tailor@pidgin.im>
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Fri, 23 Jun 2006 00:57:30 +0000
parents ba9946650bf7
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6520
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
1 #include "perl-common.h"
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
2 #include "perl-handlers.h"
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
3
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
4 #include "debug.h"
6549
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
5 #include "signals.h"
6520
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
6
12882
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
7 extern PerlInterpreter *my_perl;
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
8 static GList *cmd_handlers = NULL;
6549
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
9 static GList *signal_handlers = NULL;
12882
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
10 static GList *timeout_handlers = NULL;
6520
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
11
12165
f8e22fef03fc [gaim-migrate @ 14466]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11170
diff changeset
12 /* perl < 5.8.0 doesn't define PERL_MAGIC_ext */
f8e22fef03fc [gaim-migrate @ 14466]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11170
diff changeset
13 #ifndef PERL_MAGIC_ext
f8e22fef03fc [gaim-migrate @ 14466]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11170
diff changeset
14 #define PERL_MAGIC_ext '~'
f8e22fef03fc [gaim-migrate @ 14466]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11170
diff changeset
15 #endif
f8e22fef03fc [gaim-migrate @ 14466]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11170
diff changeset
16
12803
050b29b7232a [gaim-migrate @ 15150]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12165
diff changeset
17 void
12988
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
18 gaim_perl_plugin_action_cb(GaimPluginAction *action)
12803
050b29b7232a [gaim-migrate @ 15150]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12165
diff changeset
19 {
12988
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
20 SV **callback;
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
21 HV *hv = NULL;
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
22 gchar *hvname;
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
23 GaimPlugin *plugin;
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
24 GaimPerlScript *gps;
12803
050b29b7232a [gaim-migrate @ 15150]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12165
diff changeset
25 dSP;
12988
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
26
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
27 plugin = action->plugin;
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
28 gps = (GaimPerlScript *)plugin->info->extra_info;
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
29 hvname = g_strdup_printf("%s::plugin_actions", gps->package);
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
30 hv = get_hv(hvname, FALSE);
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
31 g_free(hvname);
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
32
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
33 if (hv == NULL)
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
34 croak("No plugin_actions hash found in \"%s\" plugin.", gaim_plugin_get_name(plugin));
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
35
12803
050b29b7232a [gaim-migrate @ 15150]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12165
diff changeset
36 ENTER;
050b29b7232a [gaim-migrate @ 15150]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12165
diff changeset
37 SAVETMPS;
12988
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
38
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
39 callback = hv_fetch(hv, action->label, strlen(action->label), 0);
11170
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents: 11123
diff changeset
40
12988
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
41 if (callback == NULL || *callback == NULL)
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
42 croak("No plugin_action function named \"%s\" in \"%s\" plugin.", action->label, gaim_plugin_get_name(plugin));
11170
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents: 11123
diff changeset
43
12988
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
44 PUSHMARK(sp);
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
45 XPUSHs(gaim_perl_bless_object(gps->plugin, "Gaim::Plugin"));
12803
050b29b7232a [gaim-migrate @ 15150]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12165
diff changeset
46 PUTBACK;
11170
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents: 11123
diff changeset
47
12988
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
48 call_sv(*callback, G_VOID | G_DISCARD);
12803
050b29b7232a [gaim-migrate @ 15150]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12165
diff changeset
49 SPAGAIN;
11170
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents: 11123
diff changeset
50
12803
050b29b7232a [gaim-migrate @ 15150]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12165
diff changeset
51 PUTBACK;
050b29b7232a [gaim-migrate @ 15150]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12165
diff changeset
52 FREETMPS;
050b29b7232a [gaim-migrate @ 15150]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12165
diff changeset
53 LEAVE;
11170
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents: 11123
diff changeset
54 }
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents: 11123
diff changeset
55
12803
050b29b7232a [gaim-migrate @ 15150]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12165
diff changeset
56 GList *
12988
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
57 gaim_perl_plugin_actions(GaimPlugin *plugin, gpointer context)
12803
050b29b7232a [gaim-migrate @ 15150]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12165
diff changeset
58 {
12988
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
59 GList *l = NULL;
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
60 GaimPerlScript *gps;
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
61 int i = 0, count = 0;
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
62 dSP;
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
63
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
64 gps = (GaimPerlScript *)plugin->info->extra_info;
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
65
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
66 ENTER;
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
67 SAVETMPS;
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
68
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
69 PUSHMARK(SP);
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
70 XPUSHs(sv_2mortal(gaim_perl_bless_object(plugin, "Gaim::Plugin")));
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
71 /* XXX This *will* cease working correctly if context gets changed to
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
72 * ever be able to hold anything other than a GaimConnection */
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
73 if (context != NULL)
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
74 XPUSHs(sv_2mortal(gaim_perl_bless_object(context, "Gaim::Connection")));
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
75 else
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
76 XPUSHs(&PL_sv_undef);
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
77 PUTBACK;
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
78
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
79 count = call_pv(gps->plugin_action_sub, G_ARRAY);
11170
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents: 11123
diff changeset
80
12988
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
81 SPAGAIN;
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
82
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
83 if (count == 0)
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
84 croak("The plugin_actions sub didn't return anything.\n");
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
85
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
86 for (i = 0; i < count; i++) {
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
87 SV *sv;
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
88 gchar *label;
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
89 GaimPluginAction *act = NULL;
11170
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents: 11123
diff changeset
90
12988
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
91 sv = POPs;
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
92 label = SvPV_nolen(sv);
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
93 /* XXX I think this leaks, but doing it without the strdup
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
94 * just showed garbage */
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
95 act = gaim_plugin_action_new(g_strdup(label), gaim_perl_plugin_action_cb);
13353
ba9946650bf7 [gaim-migrate @ 15725]
Richard Laager <rlaager@wiktel.com>
parents: 13190
diff changeset
96 l = g_list_prepend(l, act);
12988
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
97 }
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
98
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
99 PUTBACK;
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
100 FREETMPS;
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
101 LEAVE;
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
102
b457aa723bab [gaim-migrate @ 15341]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12882
diff changeset
103 return l;
11170
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents: 11123
diff changeset
104 }
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents: 11123
diff changeset
105
12803
050b29b7232a [gaim-migrate @ 15150]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12165
diff changeset
106 GtkWidget *
050b29b7232a [gaim-migrate @ 15150]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12165
diff changeset
107 gaim_perl_gtk_get_plugin_frame(GaimPlugin *plugin)
050b29b7232a [gaim-migrate @ 15150]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12165
diff changeset
108 {
11170
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents: 11123
diff changeset
109 SV * sv;
12874
e65a7a7eabaf [gaim-migrate @ 15226]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12872
diff changeset
110 int count;
11170
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents: 11123
diff changeset
111 MAGIC *mg;
12874
e65a7a7eabaf [gaim-migrate @ 15226]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12872
diff changeset
112 GtkWidget *ret;
e65a7a7eabaf [gaim-migrate @ 15226]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12872
diff changeset
113 GaimPerlScript *gps;
11170
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents: 11123
diff changeset
114 dSP;
12874
e65a7a7eabaf [gaim-migrate @ 15226]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12872
diff changeset
115
e65a7a7eabaf [gaim-migrate @ 15226]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12872
diff changeset
116 gps = (GaimPerlScript *)plugin->info->extra_info;
11170
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents: 11123
diff changeset
117
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents: 11123
diff changeset
118 ENTER;
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents: 11123
diff changeset
119 SAVETMPS;
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents: 11123
diff changeset
120
12874
e65a7a7eabaf [gaim-migrate @ 15226]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12872
diff changeset
121 count = call_pv(gps->gtk_prefs_sub, G_SCALAR | G_NOARGS);
11170
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents: 11123
diff changeset
122 if (count != 1)
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents: 11123
diff changeset
123 croak("call_pv: Did not return the correct number of values.\n");
12803
050b29b7232a [gaim-migrate @ 15150]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12165
diff changeset
124
11170
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents: 11123
diff changeset
125 /* the frame was created in a perl sub and is returned */
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents: 11123
diff changeset
126 SPAGAIN;
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents: 11123
diff changeset
127
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents: 11123
diff changeset
128 /* We have a Gtk2::Frame on top of the stack */
12803
050b29b7232a [gaim-migrate @ 15150]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12165
diff changeset
129 sv = POPs;
11170
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents: 11123
diff changeset
130
12874
e65a7a7eabaf [gaim-migrate @ 15226]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12872
diff changeset
131 /* The magic field hides the pointer to the actual GtkWidget */
11170
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents: 11123
diff changeset
132 mg = mg_find(SvRV(sv), PERL_MAGIC_ext);
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents: 11123
diff changeset
133 ret = (GtkWidget *)mg->mg_ptr;
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents: 11123
diff changeset
134
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents: 11123
diff changeset
135 PUTBACK;
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents: 11123
diff changeset
136 FREETMPS;
12803
050b29b7232a [gaim-migrate @ 15150]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12165
diff changeset
137 LEAVE;
050b29b7232a [gaim-migrate @ 15150]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12165
diff changeset
138
11170
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents: 11123
diff changeset
139 return ret;
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents: 11123
diff changeset
140 }
0e9e2b923d09 [gaim-migrate @ 13271]
John H. Kelm <johnkelm@gmail.com>
parents: 11123
diff changeset
141
12803
050b29b7232a [gaim-migrate @ 15150]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12165
diff changeset
142 GaimPluginPrefFrame *
050b29b7232a [gaim-migrate @ 15150]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12165
diff changeset
143 gaim_perl_get_plugin_frame(GaimPlugin *plugin)
050b29b7232a [gaim-migrate @ 15150]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12165
diff changeset
144 {
050b29b7232a [gaim-migrate @ 15150]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12165
diff changeset
145 /* Sets up the Perl Stack for our call back into the script to run the
050b29b7232a [gaim-migrate @ 15150]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12165
diff changeset
146 * plugin_pref... sub */
12872
59ff3e1c874e [gaim-migrate @ 15224]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12871
diff changeset
147 int count;
59ff3e1c874e [gaim-migrate @ 15224]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12871
diff changeset
148 GaimPerlScript *gps;
11123
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
149 GaimPluginPrefFrame *ret_frame;
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
150 dSP;
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
151
12872
59ff3e1c874e [gaim-migrate @ 15224]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12871
diff changeset
152 gps = (GaimPerlScript *)plugin->info->extra_info;
59ff3e1c874e [gaim-migrate @ 15224]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12871
diff changeset
153
11123
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
154 ENTER;
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
155 SAVETMPS;
12803
050b29b7232a [gaim-migrate @ 15150]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12165
diff changeset
156 /* Some perl magic to run perl_plugin_pref_frame_SV perl sub and
050b29b7232a [gaim-migrate @ 15150]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12165
diff changeset
157 * return the frame */
11123
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
158 PUSHMARK(SP);
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
159 PUTBACK;
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
160
12872
59ff3e1c874e [gaim-migrate @ 15224]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12871
diff changeset
161 count = call_pv(gps->prefs_sub, G_SCALAR | G_NOARGS);
11123
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
162
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
163 SPAGAIN;
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
164
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
165 if (count != 1)
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
166 croak("call_pv: Did not return the correct number of values.\n");
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
167 /* the frame was created in a perl sub and is returned */
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
168 ret_frame = (GaimPluginPrefFrame *)gaim_perl_ref_object(POPs);
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
169
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
170 /* Tidy up the Perl stack */
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
171 PUTBACK;
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
172 FREETMPS;
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
173 LEAVE;
12871
2422097a7a5e [gaim-migrate @ 15223]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12804
diff changeset
174
11123
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
175 return ret_frame;
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
176 }
6520
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
177
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
178 static void
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
179 destroy_timeout_handler(GaimPerlTimeoutHandler *handler)
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
180 {
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
181 timeout_handlers = g_list_remove(timeout_handlers, handler);
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
182
6568
33486b749aa9 [gaim-migrate @ 7090]
Christian Hammond <chipx86@chipx86.com>
parents: 6567
diff changeset
183 if (handler->callback != NULL)
33486b749aa9 [gaim-migrate @ 7090]
Christian Hammond <chipx86@chipx86.com>
parents: 6567
diff changeset
184 SvREFCNT_dec(handler->callback);
33486b749aa9 [gaim-migrate @ 7090]
Christian Hammond <chipx86@chipx86.com>
parents: 6567
diff changeset
185
33486b749aa9 [gaim-migrate @ 7090]
Christian Hammond <chipx86@chipx86.com>
parents: 6567
diff changeset
186 if (handler->data != NULL)
33486b749aa9 [gaim-migrate @ 7090]
Christian Hammond <chipx86@chipx86.com>
parents: 6567
diff changeset
187 SvREFCNT_dec(handler->data);
33486b749aa9 [gaim-migrate @ 7090]
Christian Hammond <chipx86@chipx86.com>
parents: 6567
diff changeset
188
6520
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
189 g_free(handler);
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
190 }
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
191
6549
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
192 static void
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
193 destroy_signal_handler(GaimPerlSignalHandler *handler)
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
194 {
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
195 signal_handlers = g_list_remove(signal_handlers, handler);
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
196
6567
6e25e1e08ffb [gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents: 6566
diff changeset
197 if (handler->callback != NULL)
6e25e1e08ffb [gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents: 6566
diff changeset
198 SvREFCNT_dec(handler->callback);
6e25e1e08ffb [gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents: 6566
diff changeset
199
6e25e1e08ffb [gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents: 6566
diff changeset
200 if (handler->data != NULL)
6e25e1e08ffb [gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents: 6566
diff changeset
201 SvREFCNT_dec(handler->data);
6e25e1e08ffb [gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents: 6566
diff changeset
202
6549
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
203 g_free(handler->signal);
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
204 g_free(handler);
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
205 }
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
206
6520
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
207 static int
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
208 perl_timeout_cb(gpointer data)
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
209 {
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
210 GaimPerlTimeoutHandler *handler = (GaimPerlTimeoutHandler *)data;
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
211
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
212 dSP;
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
213 ENTER;
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
214 SAVETMPS;
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
215 PUSHMARK(sp);
6568
33486b749aa9 [gaim-migrate @ 7090]
Christian Hammond <chipx86@chipx86.com>
parents: 6567
diff changeset
216 XPUSHs((SV *)handler->data);
6520
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
217 PUTBACK;
6568
33486b749aa9 [gaim-migrate @ 7090]
Christian Hammond <chipx86@chipx86.com>
parents: 6567
diff changeset
218 call_sv(handler->callback, G_EVAL | G_SCALAR);
6520
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
219 SPAGAIN;
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
220
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
221 PUTBACK;
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
222 FREETMPS;
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
223 LEAVE;
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
224
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
225 destroy_timeout_handler(handler);
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
226
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
227 return 0;
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
228 }
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
229
6921
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
230 typedef void *DATATYPE;
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
231
6549
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
232 static void *
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
233 perl_signal_cb(va_list args, void *data)
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
234 {
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
235 GaimPerlSignalHandler *handler = (GaimPerlSignalHandler *)data;
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
236 void *ret_val = NULL;
6566
f6c2a7b5afa7 [gaim-migrate @ 7088]
Christian Hammond <chipx86@chipx86.com>
parents: 6554
diff changeset
237 int i;
6549
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
238 int count;
6566
f6c2a7b5afa7 [gaim-migrate @ 7088]
Christian Hammond <chipx86@chipx86.com>
parents: 6554
diff changeset
239 int value_count;
f6c2a7b5afa7 [gaim-migrate @ 7088]
Christian Hammond <chipx86@chipx86.com>
parents: 6554
diff changeset
240 GaimValue *ret_value, **values;
6919
1aa771990188 [gaim-migrate @ 7466]
Christian Hammond <chipx86@chipx86.com>
parents: 6568
diff changeset
241 SV **sv_args;
6921
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
242 DATATYPE **copy_args;
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
243 STRLEN na;
6549
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
244
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
245 dSP;
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
246 ENTER;
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
247 SAVETMPS;
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
248 PUSHMARK(sp);
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
249
6566
f6c2a7b5afa7 [gaim-migrate @ 7088]
Christian Hammond <chipx86@chipx86.com>
parents: 6554
diff changeset
250 gaim_signal_get_values(handler->instance, handler->signal,
12804
86d67bd4ef24 [gaim-migrate @ 15151]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12803
diff changeset
251 &ret_value, &value_count, &values);
6566
f6c2a7b5afa7 [gaim-migrate @ 7088]
Christian Hammond <chipx86@chipx86.com>
parents: 6554
diff changeset
252
6921
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
253 sv_args = g_new(SV *, value_count);
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
254 copy_args = g_new(void **, value_count);
6919
1aa771990188 [gaim-migrate @ 7466]
Christian Hammond <chipx86@chipx86.com>
parents: 6568
diff changeset
255
12803
050b29b7232a [gaim-migrate @ 15150]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12165
diff changeset
256 for (i = 0; i < value_count; i++) {
12804
86d67bd4ef24 [gaim-migrate @ 15151]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12803
diff changeset
257 sv_args[i] = gaim_perl_sv_from_vargs(values[i],
86d67bd4ef24 [gaim-migrate @ 15151]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12803
diff changeset
258 (va_list*)&args,
86d67bd4ef24 [gaim-migrate @ 15151]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12803
diff changeset
259 &copy_args[i]);
6549
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
260
6920
13f78c350cd3 [gaim-migrate @ 7467]
Christian Hammond <chipx86@chipx86.com>
parents: 6919
diff changeset
261 XPUSHs(sv_args[i]);
6566
f6c2a7b5afa7 [gaim-migrate @ 7088]
Christian Hammond <chipx86@chipx86.com>
parents: 6554
diff changeset
262 }
f6c2a7b5afa7 [gaim-migrate @ 7088]
Christian Hammond <chipx86@chipx86.com>
parents: 6554
diff changeset
263
6549
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
264 XPUSHs((SV *)handler->data);
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
265
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
266 PUTBACK;
6567
6e25e1e08ffb [gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents: 6566
diff changeset
267
12803
050b29b7232a [gaim-migrate @ 15150]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12165
diff changeset
268 if (ret_value != NULL) {
6921
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
269 count = call_sv(handler->callback, G_EVAL | G_SCALAR);
6567
6e25e1e08ffb [gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents: 6566
diff changeset
270
6e25e1e08ffb [gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents: 6566
diff changeset
271 SPAGAIN;
6549
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
272
6567
6e25e1e08ffb [gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents: 6566
diff changeset
273 if (count != 1)
6e25e1e08ffb [gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents: 6566
diff changeset
274 croak("Uh oh! call_sv returned %i != 1", i);
6e25e1e08ffb [gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents: 6566
diff changeset
275 else
6920
13f78c350cd3 [gaim-migrate @ 7467]
Christian Hammond <chipx86@chipx86.com>
parents: 6919
diff changeset
276 ret_val = gaim_perl_data_from_sv(ret_value, POPs);
12803
050b29b7232a [gaim-migrate @ 15150]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12165
diff changeset
277 } else {
6567
6e25e1e08ffb [gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents: 6566
diff changeset
278 call_sv(handler->callback, G_SCALAR);
6549
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
279
6921
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
280 SPAGAIN;
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
281 }
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
282
12803
050b29b7232a [gaim-migrate @ 15150]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12165
diff changeset
283 if (SvTRUE(ERRSV)) {
050b29b7232a [gaim-migrate @ 15150]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12165
diff changeset
284 gaim_debug_error("perl",
050b29b7232a [gaim-migrate @ 15150]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12165
diff changeset
285 "Perl function exited abnormally: %s\n",
050b29b7232a [gaim-migrate @ 15150]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12165
diff changeset
286 SvPV(ERRSV, na));
6921
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
287 }
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
288
6919
1aa771990188 [gaim-migrate @ 7466]
Christian Hammond <chipx86@chipx86.com>
parents: 6568
diff changeset
289 /* See if any parameters changed. */
12803
050b29b7232a [gaim-migrate @ 15150]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12165
diff changeset
290 for (i = 0; i < value_count; i++) {
050b29b7232a [gaim-migrate @ 15150]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12165
diff changeset
291 if (gaim_value_is_outgoing(values[i])) {
050b29b7232a [gaim-migrate @ 15150]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12165
diff changeset
292 switch (gaim_value_get_type(values[i])) {
6921
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
293 case GAIM_TYPE_BOOLEAN:
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
294 *((gboolean *)copy_args[i]) = SvIV(sv_args[i]);
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
295 break;
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
296
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
297 case GAIM_TYPE_INT:
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
298 *((int *)copy_args[i]) = SvIV(sv_args[i]);
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
299 break;
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
300
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
301 case GAIM_TYPE_UINT:
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
302 *((unsigned int *)copy_args[i]) = SvUV(sv_args[i]);
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
303 break;
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
304
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
305 case GAIM_TYPE_LONG:
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
306 *((long *)copy_args[i]) = SvIV(sv_args[i]);
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
307 break;
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
308
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
309 case GAIM_TYPE_ULONG:
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
310 *((unsigned long *)copy_args[i]) = SvUV(sv_args[i]);
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
311 break;
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
312
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
313 case GAIM_TYPE_INT64:
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
314 *((gint64 *)copy_args[i]) = SvIV(sv_args[i]);
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
315 break;
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
316
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
317 case GAIM_TYPE_UINT64:
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
318 *((guint64 *)copy_args[i]) = SvUV(sv_args[i]);
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
319 break;
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
320
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
321 case GAIM_TYPE_STRING:
12803
050b29b7232a [gaim-migrate @ 15150]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12165
diff changeset
322 if (strcmp(*((char **)copy_args[i]), SvPVX(sv_args[i]))) {
6925
3ec6aac0ff67 [gaim-migrate @ 7472]
Christian Hammond <chipx86@chipx86.com>
parents: 6924
diff changeset
323 g_free(*((char **)copy_args[i]));
3ec6aac0ff67 [gaim-migrate @ 7472]
Christian Hammond <chipx86@chipx86.com>
parents: 6924
diff changeset
324 *((char **)copy_args[i]) =
3ec6aac0ff67 [gaim-migrate @ 7472]
Christian Hammond <chipx86@chipx86.com>
parents: 6924
diff changeset
325 g_strdup(SvPV(sv_args[i], na));
3ec6aac0ff67 [gaim-migrate @ 7472]
Christian Hammond <chipx86@chipx86.com>
parents: 6924
diff changeset
326 }
6921
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
327 break;
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
328
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
329 case GAIM_TYPE_POINTER:
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
330 *((void **)copy_args[i]) = (void *)SvIV(sv_args[i]);
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
331 break;
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
332
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
333 case GAIM_TYPE_BOXED:
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
334 *((void **)copy_args[i]) = (void *)SvIV(sv_args[i]);
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
335 break;
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
336
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
337 default:
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
338 break;
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
339 }
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
340
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
341 #if 0
6920
13f78c350cd3 [gaim-migrate @ 7467]
Christian Hammond <chipx86@chipx86.com>
parents: 6919
diff changeset
342 *((void **)copy_args[i]) = gaim_perl_data_from_sv(values[i],
13f78c350cd3 [gaim-migrate @ 7467]
Christian Hammond <chipx86@chipx86.com>
parents: 6919
diff changeset
343 sv_args[i]);
6921
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
344 #endif
6919
1aa771990188 [gaim-migrate @ 7466]
Christian Hammond <chipx86@chipx86.com>
parents: 6568
diff changeset
345 }
1aa771990188 [gaim-migrate @ 7466]
Christian Hammond <chipx86@chipx86.com>
parents: 6568
diff changeset
346 }
1aa771990188 [gaim-migrate @ 7466]
Christian Hammond <chipx86@chipx86.com>
parents: 6568
diff changeset
347
6921
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
348 PUTBACK;
6549
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
349 FREETMPS;
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
350 LEAVE;
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
351
6919
1aa771990188 [gaim-migrate @ 7466]
Christian Hammond <chipx86@chipx86.com>
parents: 6568
diff changeset
352 g_free(sv_args);
6920
13f78c350cd3 [gaim-migrate @ 7467]
Christian Hammond <chipx86@chipx86.com>
parents: 6919
diff changeset
353 g_free(copy_args);
6919
1aa771990188 [gaim-migrate @ 7466]
Christian Hammond <chipx86@chipx86.com>
parents: 6568
diff changeset
354
1aa771990188 [gaim-migrate @ 7466]
Christian Hammond <chipx86@chipx86.com>
parents: 6568
diff changeset
355 gaim_debug_misc("perl", "ret_val = %p\n", ret_val);
1aa771990188 [gaim-migrate @ 7466]
Christian Hammond <chipx86@chipx86.com>
parents: 6568
diff changeset
356
6549
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
357 return ret_val;
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
358 }
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
359
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
360 static GaimPerlSignalHandler *
6567
6e25e1e08ffb [gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents: 6566
diff changeset
361 find_signal_handler(GaimPlugin *plugin, void *instance, const char *signal)
6549
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
362 {
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
363 GaimPerlSignalHandler *handler;
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
364 GList *l;
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
365
12803
050b29b7232a [gaim-migrate @ 15150]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12165
diff changeset
366 for (l = signal_handlers; l != NULL; l = l->next) {
6549
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
367 handler = (GaimPerlSignalHandler *)l->data;
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
368
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
369 if (handler->plugin == plugin &&
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
370 handler->instance == instance &&
12803
050b29b7232a [gaim-migrate @ 15150]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12165
diff changeset
371 !strcmp(handler->signal, signal)) {
6549
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
372 return handler;
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
373 }
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
374 }
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
375
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
376 return NULL;
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
377 }
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
378
6520
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
379 void
6568
33486b749aa9 [gaim-migrate @ 7090]
Christian Hammond <chipx86@chipx86.com>
parents: 6567
diff changeset
380 gaim_perl_timeout_add(GaimPlugin *plugin, int seconds, SV *callback, SV *data)
6520
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
381 {
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
382 GaimPerlTimeoutHandler *handler;
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
383
12803
050b29b7232a [gaim-migrate @ 15150]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12165
diff changeset
384 if (plugin == NULL) {
6549
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
385 croak("Invalid handle in adding perl timeout handler.\n");
6520
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
386 return;
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
387 }
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
388
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
389 handler = g_new0(GaimPerlTimeoutHandler, 1);
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
390
6568
33486b749aa9 [gaim-migrate @ 7090]
Christian Hammond <chipx86@chipx86.com>
parents: 6567
diff changeset
391 handler->plugin = plugin;
33486b749aa9 [gaim-migrate @ 7090]
Christian Hammond <chipx86@chipx86.com>
parents: 6567
diff changeset
392 handler->callback = (callback != NULL && callback != &PL_sv_undef
13017
7fdd1c0c585c [gaim-migrate @ 15370]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12988
diff changeset
393 ? newSVsv(callback) : NULL);
6568
33486b749aa9 [gaim-migrate @ 7090]
Christian Hammond <chipx86@chipx86.com>
parents: 6567
diff changeset
394 handler->data = (data != NULL && data != &PL_sv_undef
13017
7fdd1c0c585c [gaim-migrate @ 15370]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12988
diff changeset
395 ? newSVsv(data) : NULL);
6520
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
396
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
397 timeout_handlers = g_list_append(timeout_handlers, handler);
6568
33486b749aa9 [gaim-migrate @ 7090]
Christian Hammond <chipx86@chipx86.com>
parents: 6567
diff changeset
398
6520
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
399 handler->iotag = g_timeout_add(seconds * 1000, perl_timeout_cb, handler);
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
400 }
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
401
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
402 void
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
403 gaim_perl_timeout_clear_for_plugin(GaimPlugin *plugin)
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
404 {
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
405 GaimPerlTimeoutHandler *handler;
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
406 GList *l, *l_next;
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
407
12803
050b29b7232a [gaim-migrate @ 15150]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12165
diff changeset
408 for (l = timeout_handlers; l != NULL; l = l_next) {
6520
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
409 l_next = l->next;
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
410
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
411 handler = (GaimPerlTimeoutHandler *)l->data;
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
412
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
413 if (handler->plugin == plugin)
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
414 destroy_timeout_handler(handler);
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
415 }
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
416 }
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
417
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
418 void
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
419 gaim_perl_timeout_clear(void)
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
420 {
6549
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
421 while (timeout_handlers != NULL)
6520
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
422 destroy_timeout_handler(timeout_handlers->data);
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
423 }
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
424
6549
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
425 void
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
426 gaim_perl_signal_connect(GaimPlugin *plugin, void *instance,
13190
60b863ecd89b [gaim-migrate @ 15553]
Etan Reisner <pidgin@unreliablesource.net>
parents: 13017
diff changeset
427 const char *signal, SV *callback, SV *data,
60b863ecd89b [gaim-migrate @ 15553]
Etan Reisner <pidgin@unreliablesource.net>
parents: 13017
diff changeset
428 int priority)
6549
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
429 {
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
430 GaimPerlSignalHandler *handler;
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
431
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
432 handler = g_new0(GaimPerlSignalHandler, 1);
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
433 handler->plugin = plugin;
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
434 handler->instance = instance;
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
435 handler->signal = g_strdup(signal);
12803
050b29b7232a [gaim-migrate @ 15150]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12165
diff changeset
436 handler->callback = (callback != NULL &&
050b29b7232a [gaim-migrate @ 15150]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12165
diff changeset
437 callback != &PL_sv_undef ? newSVsv(callback)
050b29b7232a [gaim-migrate @ 15150]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12165
diff changeset
438 : NULL);
050b29b7232a [gaim-migrate @ 15150]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12165
diff changeset
439 handler->data = (data != NULL &&
050b29b7232a [gaim-migrate @ 15150]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12165
diff changeset
440 data != &PL_sv_undef ? newSVsv(data) : NULL);
6549
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
441
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
442 signal_handlers = g_list_append(signal_handlers, handler);
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
443
13190
60b863ecd89b [gaim-migrate @ 15553]
Etan Reisner <pidgin@unreliablesource.net>
parents: 13017
diff changeset
444 gaim_signal_connect_priority_vargs(instance, signal, plugin,
60b863ecd89b [gaim-migrate @ 15553]
Etan Reisner <pidgin@unreliablesource.net>
parents: 13017
diff changeset
445 GAIM_CALLBACK(perl_signal_cb),
60b863ecd89b [gaim-migrate @ 15553]
Etan Reisner <pidgin@unreliablesource.net>
parents: 13017
diff changeset
446 handler, priority);
6549
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
447 }
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
448
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
449 void
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
450 gaim_perl_signal_disconnect(GaimPlugin *plugin, void *instance,
12803
050b29b7232a [gaim-migrate @ 15150]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12165
diff changeset
451 const char *signal)
6549
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
452 {
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
453 GaimPerlSignalHandler *handler;
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
454
6567
6e25e1e08ffb [gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents: 6566
diff changeset
455 handler = find_signal_handler(plugin, instance, signal);
6549
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
456
12803
050b29b7232a [gaim-migrate @ 15150]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12165
diff changeset
457 if (handler == NULL) {
6549
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
458 croak("Invalid signal handler information in "
12803
050b29b7232a [gaim-migrate @ 15150]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12165
diff changeset
459 "disconnecting a perl signal handler.\n");
6549
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
460 return;
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
461 }
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
462
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
463 destroy_signal_handler(handler);
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
464 }
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
465
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
466 void
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
467 gaim_perl_signal_clear_for_plugin(GaimPlugin *plugin)
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
468 {
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
469 GaimPerlSignalHandler *handler;
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
470 GList *l, *l_next;
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
471
12803
050b29b7232a [gaim-migrate @ 15150]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12165
diff changeset
472 for (l = signal_handlers; l != NULL; l = l_next) {
6549
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
473 l_next = l->next;
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
474
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
475 handler = (GaimPerlSignalHandler *)l->data;
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
476
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
477 if (handler->plugin == plugin)
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
478 destroy_signal_handler(handler);
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
479 }
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
480 }
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
481
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
482 void
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
483 gaim_perl_signal_clear(void)
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
484 {
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
485 while (signal_handlers != NULL)
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
486 destroy_signal_handler(signal_handlers->data);
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
487 }
12882
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
488
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
489 static GaimCmdRet
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
490 perl_cmd_cb(GaimConversation *conv, const gchar *command,
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
491 gchar **args, gchar **error, void *data)
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
492 {
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
493 int i = 0, count, ret_value = GAIM_CMD_RET_OK;
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
494 SV *cmdSV, *tmpSV, *convSV;
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
495 GaimPerlCmdHandler *handler = (GaimPerlCmdHandler *)data;
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
496
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
497 dSP;
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
498 ENTER;
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
499 SAVETMPS;
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
500 PUSHMARK(SP);
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
501
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
502 /* Push the conversation onto the perl stack */
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
503 convSV = sv_2mortal(gaim_perl_bless_object(conv, "Gaim::Conversation"));
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
504 XPUSHs(convSV);
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
505
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
506 /* Push the command string onto the perl stack */
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
507 cmdSV = newSVpv(command, 0);
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
508 cmdSV = sv_2mortal(cmdSV);
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
509 XPUSHs(cmdSV);
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
510
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
511 /* Push the data onto the perl stack */
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
512 XPUSHs((SV *)handler->data);
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
513
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
514 /* Push any arguments we may have */
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
515 for (i = 0; args[i] != NULL; i++) {
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
516 /* XXX The mortality of these created SV's should prevent
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
517 * memory issues, if I read/understood everything correctly...
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
518 */
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
519 tmpSV = newSVpv(args[i], 0);
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
520 tmpSV = sv_2mortal(tmpSV);
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
521 XPUSHs(tmpSV);
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
522 }
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
523
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
524 PUTBACK;
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
525 count = call_sv(handler->callback, G_EVAL|G_SCALAR);
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
526
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
527 if (count != 1)
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
528 croak("call_sv: Did not return the correct number of values.\n");
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
529
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
530 SPAGAIN;
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
531
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
532 ret_value = POPi;
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
533
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
534 PUTBACK;
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
535 FREETMPS;
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
536 LEAVE;
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
537
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
538 return ret_value;
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
539 }
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
540
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
541 GaimCmdId
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
542 gaim_perl_cmd_register(GaimPlugin *plugin, const gchar *command,
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
543 const gchar *args, GaimCmdPriority priority,
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
544 GaimCmdFlag flag, const gchar *prpl_id, SV *callback,
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
545 const gchar *helpstr, SV *data)
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
546 {
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
547 GaimPerlCmdHandler *handler;
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
548
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
549 handler = g_new0(GaimPerlCmdHandler, 1);
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
550 handler->plugin = plugin;
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
551 handler->cmd = g_strdup(command);
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
552 handler->prpl_id = g_strdup(prpl_id);
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
553
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
554 if (callback != NULL && callback != &PL_sv_undef)
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
555 handler->callback = newSVsv(callback);
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
556 else
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
557 handler->callback = NULL;
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
558
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
559 if (data != NULL && data != &PL_sv_undef)
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
560 handler->data = newSVsv(data);
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
561 else
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
562 handler->data = NULL;
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
563
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
564 cmd_handlers = g_list_append(cmd_handlers, handler);
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
565
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
566 handler->id = gaim_cmd_register(command, args, priority, flag, prpl_id,
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
567 GAIM_CMD_FUNC(perl_cmd_cb), helpstr,
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
568 handler);
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
569
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
570 return handler->id;
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
571 }
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
572
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
573 static void
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
574 destroy_cmd_handler(GaimPerlCmdHandler *handler)
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
575 {
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
576 cmd_handlers = g_list_remove(cmd_handlers, handler);
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
577
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
578 if (handler->callback != NULL)
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
579 SvREFCNT_dec(handler->callback);
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
580
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
581 if (handler->data != NULL)
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
582 SvREFCNT_dec(handler->data);
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
583
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
584 g_free(handler->cmd);
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
585 g_free(handler->prpl_id);
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
586 g_free(handler);
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
587 }
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
588
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
589 void
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
590 gaim_perl_cmd_clear_for_plugin(GaimPlugin *plugin)
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
591 {
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
592 GList *l, *l_next;
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
593
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
594 for (l = cmd_handlers; l != NULL; l = l_next) {
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
595 GaimPerlCmdHandler *handler = (GaimPerlCmdHandler *)l->data;
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
596
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
597 l_next = l->next;
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
598
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
599 if (handler->plugin == plugin)
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
600 destroy_cmd_handler(handler);
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
601 }
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
602 }
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
603
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
604 static GaimPerlCmdHandler *
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
605 find_cmd_handler(GaimCmdId id)
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
606 {
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
607 GList *l;
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
608
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
609 for (l = cmd_handlers; l != NULL; l = l->next) {
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
610 GaimPerlCmdHandler *handler = (GaimPerlCmdHandler *)l->data;
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
611
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
612 if (handler->id == id)
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
613 return handler;
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
614 }
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
615
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
616 return NULL;
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
617 }
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
618
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
619 void
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
620 gaim_perl_cmd_unregister(GaimCmdId id)
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
621 {
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
622 GaimPerlCmdHandler *handler;
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
623
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
624 handler = find_cmd_handler(id);
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
625
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
626 if (handler == NULL) {
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
627 croak("Invalid command id in removing a perl command handler.\n");
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
628 return;
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
629 }
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
630
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
631 gaim_cmd_unregister(id);
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
632 destroy_cmd_handler(handler);
e1603fd610fa [gaim-migrate @ 15234]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12874
diff changeset
633 }