libpurple/plugins/debug_example.c

Sat, 27 Aug 2016 18:16:01 -0500

author
Mike Ruprecht <cmaiku@gmail.com>
date
Sat, 27 Aug 2016 18:16:01 -0500
changeset 37959
e76677ed819c
parent 36957
95cfd176b193
child 39413
f45e8a9c6fc1
permissions
-rw-r--r--

connection: Add purple_connection_take_error()

This patch adds a purple_connection_take_error() function, which
is functionally equivalent to purple_connection_g_error(), except
that it takes ownership of the passed GError.

This is useful to simplify error handling so that the GError doesn't
have to be freed, or, in the future potentially copied, if it's no
longer needed where it's generated. It can also allow for GErrors
being generated without storing them in a variable. This would be
reasonably common if/when all PurpleConnection errors are passed
in via GError.

19875
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1 /*
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2 * Debug Example Plugin
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
3 *
19878
aa9d2cfa70bf Fix my e-mail address to match my MTN key since it now is a real e-mail address.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 19875
diff changeset
4 * Copyright (C) 2007, John Bailey <rekkanoryo@cpw.pidgin.im>
19875
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
5 *
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
7 * modify it under the terms of the GNU General Public License as
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
8 * published by the Free Software Foundation; either version 2 of the
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
9 * License, or (at your option) any later version.
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
10 *
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful, but
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
14 * General Public License for more details.
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
15 *
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
17 * along with this program; if not, write to the Free Software
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
19 * 02111-1301, USA.
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
20 *
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
21 */
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
22
35072
cb3673616d90 Added a note regarding internal.h for example plugins
Ankit Vani <a@nevitus.org>
parents: 35027
diff changeset
23 /* When writing a third-party plugin, do not include libpurple's internal.h
cb3673616d90 Added a note regarding internal.h for example plugins
Ankit Vani <a@nevitus.org>
parents: 35027
diff changeset
24 * included below. This file is for internal libpurple use only. We're including
cb3673616d90 Added a note regarding internal.h for example plugins
Ankit Vani <a@nevitus.org>
parents: 35027
diff changeset
25 * it here for our own convenience. */
cb3673616d90 Added a note regarding internal.h for example plugins
Ankit Vani <a@nevitus.org>
parents: 35027
diff changeset
26 #include "internal.h"
35026
fde23518e1e5 Moved PurpleHash to cipher.[ch]
Ankit Vani <a@nevitus.org>
parents: 34964
diff changeset
27
34964
54ebd3dcae16 Simplified example plugins by including purple.h
Ankit Vani <a@nevitus.org>
parents: 33955
diff changeset
28 /* This file defines PURPLE_PLUGINS and includes all the libpurple headers */
54ebd3dcae16 Simplified example plugins by including purple.h
Ankit Vani <a@nevitus.org>
parents: 33955
diff changeset
29 #include <purple.h>
19875
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
30
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
31 /* It's more convenient to type PLUGIN_ID all the time than it is to type
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
32 * "core-debugexample", so define this convenience macro. */
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
33 #define PLUGIN_ID "core-debugexample"
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
34
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
35 /* Common practice in third-party plugins is to define convenience macros for
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
36 * many of the fields of the plugin info struct, so we'll do that for the
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
37 * purposes of demonstration. */
36739
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
38 #define PLUGIN_AUTHORS { "John Bailey <rekkanoryo@cpw.pidgin.im>", NULL }
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
39
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
40 static PurplePluginInfo *
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
41 plugin_query(GError **error)
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
42 {
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
43 const gchar * const authors[] = PLUGIN_AUTHORS;
19875
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
44
36739
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
45 return purple_plugin_info_new(
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
46 "id", PLUGIN_ID,
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
47 "name", "Debug API Example",
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
48 "version", DISPLAY_VERSION,
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
49 "category", "Example",
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
50 "summary", "Debug API Example",
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
51 "description", "Debug API Example",
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
52 "authors", authors,
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
53 "website", "https://pidgin.im",
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
54 "abi-version", PURPLE_ABI_VERSION,
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
55 NULL
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
56 );
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
57 }
19875
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
58
36792
764b45883fba Moved internal.h inclusion over others in libpurple plugins
Ankit Vani <a@nevitus.org>
parents: 36739
diff changeset
59 /* As we've covered before, this function is called when the plugin is loaded.
764b45883fba Moved internal.h inclusion over others in libpurple plugins
Ankit Vani <a@nevitus.org>
parents: 36739
diff changeset
60 * Here we're using it to show off the capabilities of the debug API and just
764b45883fba Moved internal.h inclusion over others in libpurple plugins
Ankit Vani <a@nevitus.org>
parents: 36739
diff changeset
61 * blindly returning TRUE to tell libpurple it's safe to continue loading. */
19875
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
62 static gboolean
36739
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
63 plugin_load(PurplePlugin *plugin, GError **error)
19875
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
64 {
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
65 /* Define these for convenience--we're just using them to show the
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
66 * similarities of the debug functions to the standard printf(). */
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
67 gint i = 256;
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
68 gfloat f = 512.1024;
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
69 const gchar *s = "example string";
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
70
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
71 /* Introductory message */
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
72 purple_debug_info(PLUGIN_ID,
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
73 "Called plugin_load. Beginning debug demonstration\n");
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
74
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
75 /* Show off the debug API a bit */
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
76 purple_debug_misc(PLUGIN_ID,
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
77 "MISC level debug message. i = %d, f = %f, s = %s\n", i, f, s);
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
78
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
79 purple_debug_info(PLUGIN_ID,
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
80 "INFO level debug message. i = %d, f = %f, s = %s\n", i, f, s);
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
81
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
82 purple_debug_warning(PLUGIN_ID,
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
83 "WARNING level debug message. i = %d, f = %f, s = %s\n", i, f, s);
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
84
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
85 purple_debug_error(PLUGIN_ID,
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
86 "ERROR level debug message. i = %d, f = %f, s = %s\n", i, f, s);
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
87
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
88 purple_debug_fatal(PLUGIN_ID,
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
89 "FATAL level debug message. i = %d, f = %f, s = %s\n", i, f, s);
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
90
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
91 /* Now just return TRUE to tell libpurple to finish loading. */
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
92 return TRUE;
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
93 }
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
94
36739
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
95 static gboolean
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
96 plugin_unload(PurplePlugin *plugin, GError **error)
19875
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
97 {
36739
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
98 return TRUE;
19875
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
99 }
ace837283c37 Add the debug example plugin
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
100
36739
472bef54ba0a Started refactoring plugins to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
101 PURPLE_PLUGIN_INIT(debugexample, plugin_query, plugin_load, plugin_unload);

mercurial