libpurple/plugins/notify_example.c

Sun, 16 Aug 2020 18:58:39 -0500

author
Elliott Sales de Andrade <quantum.analyst@gmail.com>
date
Sun, 16 Aug 2020 18:58:39 -0500
changeset 40514
30d9cbf04922
parent 40439
e9838d634d5e
permissions
-rw-r--r--

Fix some leaks.

Also, expand `g_ascii_dtostr` buffers to `G_ASCII_DTOSTR_BUF_SIZE`.

This is the size it's guaranteed to be under, so might as well have it be that size. It not too much bigger than the existing choice anyway.

Testing Done:
Compile only.

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

19880
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
1 /*
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
2 * Notify API Example Plugin
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
3 *
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
4 * Copyright (C) 2007, John Bailey <rekkanoryo@cpw.pidgin.im>
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
5 *
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
7 * modify it under the terms of the GNU General Public License as
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
8 * published by the Free Software Foundation; either version 2 of the
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
9 * License, or (at your option) any later version.
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
10 *
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful, but
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
14 * General Public License for more details.
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
15 *
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
17 * along with this program; if not, write to the Free Software
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
19 * 02111-1301, USA.
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
20 *
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
21 */
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
22
40439
e9838d634d5e Make sure that internal.h can only be included by libpurple and split out some pieces to purpleprivate.h
Gary Kramlich <grim@reaperworld.com>
parents: 39413
diff changeset
23 #include <glib/gi18n-lib.h>
35027
bf4e1f00ec72 Included internal.h in notify_example
Ankit Vani <a@nevitus.org>
parents: 34964
diff changeset
24
39413
f45e8a9c6fc1 Remove/edit comments which mention PURPLE_PLUGINS define
Mike Ruprecht <cmaiku@gmail.com>
parents: 36974
diff changeset
25 /* This file includes all the libpurple headers */
34964
54ebd3dcae16 Simplified example plugins by including purple.h
Ankit Vani <a@nevitus.org>
parents: 34963
diff changeset
26 #include <purple.h>
19880
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
27
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
28 #define PLUGIN_ID "core-notifyexample"
36741
c96edeed7ea7 Refactored notify_example, one_time_password, pluginpref_example plugins to use the new API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
29 #define PLUGIN_AUTHORS { "John Bailey <rekkanoryo@cpw.pidgin.im>", NULL }
19880
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
30
20011
4a21c1668afb Comment tweaks to be closer to the version handed out via the wiki as well as
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 19880
diff changeset
31 /* The next four functions and the calls within them should cause dialog boxes to appear
4a21c1668afb Comment tweaks to be closer to the version handed out via the wiki as well as
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 19880
diff changeset
32 * when you select the plugin action from the Tools->Notify Example menu */
19880
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
33 static void
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
34 notify_error_cb(PurplePluginAction *action)
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
35 {
34963
de6836a8b324 Removed unnecessary globally defined plugin variable in example plugins
Ankit Vani <a@nevitus.org>
parents: 34449
diff changeset
36 purple_notify_error(action->plugin, "Test Notification", "Test Notification",
34449
bbcb198650b7 Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33955
diff changeset
37 "This is a test error notification", NULL);
19880
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
38 }
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
39
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
40 static void
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
41 notify_info_cb(PurplePluginAction *action)
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
42 {
34963
de6836a8b324 Removed unnecessary globally defined plugin variable in example plugins
Ankit Vani <a@nevitus.org>
parents: 34449
diff changeset
43 purple_notify_info(action->plugin, "Test Notification", "Test Notification",
34449
bbcb198650b7 Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33955
diff changeset
44 "This is a test informative notification", NULL);
19880
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
45 }
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
46
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
47 static void
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
48 notify_warn_cb(PurplePluginAction *action)
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
49 {
34963
de6836a8b324 Removed unnecessary globally defined plugin variable in example plugins
Ankit Vani <a@nevitus.org>
parents: 34449
diff changeset
50 purple_notify_warning(action->plugin, "Test Notification", "Test Notification",
34449
bbcb198650b7 Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33955
diff changeset
51 "This is a test warning notification", NULL);
19880
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
52 }
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
53
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
54 static void
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
55 notify_format_cb(PurplePluginAction *action)
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
56 {
34963
de6836a8b324 Removed unnecessary globally defined plugin variable in example plugins
Ankit Vani <a@nevitus.org>
parents: 34449
diff changeset
57 purple_notify_formatted(action->plugin, "Test Notification", "Test Notification",
19880
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
58 "Test Notification",
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
59 "<I>This is a test notification with formatted text.</I>", NULL, NULL);
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
60 }
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
61
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
62 static void
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
63 notify_uri_cb(PurplePluginAction *action)
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
64 {
20011
4a21c1668afb Comment tweaks to be closer to the version handed out via the wiki as well as
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 19880
diff changeset
65 /* This one should open your web browser of choice. */
35160
3a32622cd352 Prefer https pidgin.im rather than http
Mark Doliner <mark@kingant.net>
parents: 35072
diff changeset
66 purple_notify_uri(action->plugin, "https://pidgin.im/");
19880
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
67 }
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
68
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
69 static GList *
36742
5d43951cabc0 More refactoring
Ankit Vani <a@nevitus.org>
parents: 36741
diff changeset
70 plugin_actions(PurplePlugin *plugin)
19880
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
71 {
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
72 GList *actions = NULL;
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
73
20011
4a21c1668afb Comment tweaks to be closer to the version handed out via the wiki as well as
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 19880
diff changeset
74 /* Here we take advantage of return values to avoid the need for a temp variable */
19880
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
75 actions = g_list_prepend(actions,
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
76 purple_plugin_action_new("Show Error Notification", notify_error_cb));
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
77
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
78 actions = g_list_prepend(actions,
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
79 purple_plugin_action_new("Show Info Notification", notify_info_cb));
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
80
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
81 actions = g_list_prepend(actions,
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
82 purple_plugin_action_new("Show Warning Notification", notify_warn_cb));
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
83
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
84 actions = g_list_prepend(actions,
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
85 purple_plugin_action_new("Show Formatted Notification", notify_format_cb));
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
86
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
87 actions = g_list_prepend(actions,
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
88 purple_plugin_action_new("Show URI Notification", notify_uri_cb));
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
89
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
90 return g_list_reverse(actions);
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
91 }
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
92
36741
c96edeed7ea7 Refactored notify_example, one_time_password, pluginpref_example plugins to use the new API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
93 static PurplePluginInfo *
c96edeed7ea7 Refactored notify_example, one_time_password, pluginpref_example plugins to use the new API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
94 plugin_query(GError **error)
c96edeed7ea7 Refactored notify_example, one_time_password, pluginpref_example plugins to use the new API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
95 {
c96edeed7ea7 Refactored notify_example, one_time_password, pluginpref_example plugins to use the new API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
96 const gchar * const authors[] = PLUGIN_AUTHORS;
c96edeed7ea7 Refactored notify_example, one_time_password, pluginpref_example plugins to use the new API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
97
c96edeed7ea7 Refactored notify_example, one_time_password, pluginpref_example plugins to use the new API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
98 return purple_plugin_info_new(
c96edeed7ea7 Refactored notify_example, one_time_password, pluginpref_example plugins to use the new API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
99 "id", PLUGIN_ID,
c96edeed7ea7 Refactored notify_example, one_time_password, pluginpref_example plugins to use the new API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
100 "name", "Notify API Example",
c96edeed7ea7 Refactored notify_example, one_time_password, pluginpref_example plugins to use the new API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
101 "version", DISPLAY_VERSION,
c96edeed7ea7 Refactored notify_example, one_time_password, pluginpref_example plugins to use the new API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
102 "category", "Example",
c96edeed7ea7 Refactored notify_example, one_time_password, pluginpref_example plugins to use the new API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
103 "summary", "Notify API Example",
c96edeed7ea7 Refactored notify_example, one_time_password, pluginpref_example plugins to use the new API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
104 "description", "Notify API Example",
c96edeed7ea7 Refactored notify_example, one_time_password, pluginpref_example plugins to use the new API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
105 "authors", authors,
c96edeed7ea7 Refactored notify_example, one_time_password, pluginpref_example plugins to use the new API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
106 "website", "https://pidgin.im",
c96edeed7ea7 Refactored notify_example, one_time_password, pluginpref_example plugins to use the new API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
107 "abi-version", PURPLE_ABI_VERSION,
36934
e7268aeb3b89 Renamed plugin info callback properties to end with "-cb", and their respective symbols.
Ankit Vani <a@nevitus.org>
parents: 36909
diff changeset
108 "actions-cb", plugin_actions,
36741
c96edeed7ea7 Refactored notify_example, one_time_password, pluginpref_example plugins to use the new API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
109 NULL
c96edeed7ea7 Refactored notify_example, one_time_password, pluginpref_example plugins to use the new API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
110 );
c96edeed7ea7 Refactored notify_example, one_time_password, pluginpref_example plugins to use the new API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
111 }
c96edeed7ea7 Refactored notify_example, one_time_password, pluginpref_example plugins to use the new API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
112
19880
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
113 static gboolean
36741
c96edeed7ea7 Refactored notify_example, one_time_password, pluginpref_example plugins to use the new API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
114 plugin_load(PurplePlugin *plugin, GError **error)
19880
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
115 {
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
116 return TRUE;
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
117 }
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
118
36741
c96edeed7ea7 Refactored notify_example, one_time_password, pluginpref_example plugins to use the new API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
119 static gboolean
c96edeed7ea7 Refactored notify_example, one_time_password, pluginpref_example plugins to use the new API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
120 plugin_unload(PurplePlugin *plugin, GError **error)
19880
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
121 {
36741
c96edeed7ea7 Refactored notify_example, one_time_password, pluginpref_example plugins to use the new API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
122 return TRUE;
19880
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
123 }
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
124
36741
c96edeed7ea7 Refactored notify_example, one_time_password, pluginpref_example plugins to use the new API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
125 PURPLE_PLUGIN_INIT(notifyexample, plugin_query, plugin_load, plugin_unload);
19880
7008830b4cc4 Adding a notify API example plugin.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
diff changeset
126

mercurial