|
Evan@653
|
1 |
/** |
|
Evan@653
|
2 |
* @file cmds.h Commands API |
|
Evan@653
|
3 |
* @ingroup core |
|
Evan@653
|
4 |
* @see @ref cmd-signals |
|
Evan@653
|
5 |
*/ |
|
Evan@653
|
6 |
|
|
Evan@653
|
7 |
/* Copyright (C) 2003 Timothy Ringenbach <omarvo@hotmail.com> |
|
Evan@653
|
8 |
* |
|
Evan@653
|
9 |
* This program is free software; you can redistribute it and/or modify |
|
Evan@653
|
10 |
* it under the terms of the GNU General Public License as published by |
|
Evan@653
|
11 |
* the Free Software Foundation; either version 2 of the License, or |
|
Evan@653
|
12 |
* (at your option) any later version. |
|
Evan@653
|
13 |
* |
|
Evan@653
|
14 |
* This program is distributed in the hope that it will be useful, |
|
Evan@653
|
15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
Evan@653
|
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
Evan@653
|
17 |
* GNU General Public License for more details. |
|
Evan@653
|
18 |
* |
|
Evan@653
|
19 |
* You should have received a copy of the GNU General Public License |
|
Evan@653
|
20 |
* along with this program; if not, write to the Free Software |
|
Evan@653
|
21 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
|
Evan@653
|
22 |
* |
|
Evan@653
|
23 |
*/ |
|
Evan@653
|
24 |
#ifndef _PURPLE_CMDS_H_ |
|
Evan@653
|
25 |
#define _PURPLE_CMDS_H_ |
|
Evan@653
|
26 |
|
|
Evan@653
|
27 |
#include "conversation.h" |
|
Evan@653
|
28 |
|
|
Evan@653
|
29 |
/**************************************************************************/ |
|
Evan@653
|
30 |
/** @name Structures */ |
|
Evan@653
|
31 |
/**************************************************************************/ |
|
Evan@653
|
32 |
/*@{*/ |
|
Evan@653
|
33 |
|
|
Evan@653
|
34 |
/** The possible results of running a command with purple_cmd_do_command(). */ |
|
Evan@653
|
35 |
typedef enum _PurpleCmdStatus { |
|
Evan@653
|
36 |
PURPLE_CMD_STATUS_OK, |
|
Evan@653
|
37 |
PURPLE_CMD_STATUS_FAILED, |
|
Evan@653
|
38 |
PURPLE_CMD_STATUS_NOT_FOUND, |
|
Evan@653
|
39 |
PURPLE_CMD_STATUS_WRONG_ARGS, |
|
Evan@653
|
40 |
PURPLE_CMD_STATUS_WRONG_PRPL, |
|
Evan@653
|
41 |
PURPLE_CMD_STATUS_WRONG_TYPE |
|
Evan@653
|
42 |
} PurpleCmdStatus; |
|
Evan@653
|
43 |
|
|
Evan@653
|
44 |
/** Commands registered with the core return one of these values when run. |
|
Evan@653
|
45 |
* Normally, a command will want to return one of the first two; in some |
|
Evan@653
|
46 |
* unusual cases, you might want to have several functions called for a |
|
Evan@653
|
47 |
* particular command; in this case, they should return |
|
Evan@653
|
48 |
* #PURPLE_CMD_RET_CONTINUE to cause the core to fall through to other |
|
Evan@653
|
49 |
* commands with the same name. |
|
Evan@653
|
50 |
*/ |
|
Evan@653
|
51 |
typedef enum _PurpleCmdRet { |
|
Evan@653
|
52 |
PURPLE_CMD_RET_OK, /**< Everything's okay; Don't look for another command to call. */ |
|
Evan@653
|
53 |
PURPLE_CMD_RET_FAILED, /**< The command failed, but stop looking.*/ |
|
Evan@653
|
54 |
PURPLE_CMD_RET_CONTINUE /**< Continue, looking for other commands with the same name to call. */ |
|
Evan@653
|
55 |
} PurpleCmdRet; |
|
Evan@653
|
56 |
|
|
Evan@653
|
57 |
#define PURPLE_CMD_FUNC(func) ((PurpleCmdFunc)func) |
|
Evan@653
|
58 |
|
|
Evan@653
|
59 |
/** A function implementing a command, as passed to purple_cmd_register(). |
|
Evan@653
|
60 |
* |
|
Evan@653
|
61 |
* @todo document the arguments to these functions. |
|
Evan@653
|
62 |
* */ |
|
Evan@653
|
63 |
typedef PurpleCmdRet (*PurpleCmdFunc)(PurpleConversation *, const gchar *cmd, |
|
Evan@653
|
64 |
gchar **args, gchar **error, void *data); |
|
Evan@653
|
65 |
/** A unique integer representing a command registered with |
|
Evan@653
|
66 |
* purple_cmd_register(), which can subsequently be passed to |
|
Evan@653
|
67 |
* purple_cmd_unregister() to unregister that command. |
|
Evan@653
|
68 |
*/ |
|
Evan@653
|
69 |
typedef guint PurpleCmdId; |
|
Evan@653
|
70 |
|
|
Evan@653
|
71 |
typedef enum _PurpleCmdPriority { |
|
Evan@653
|
72 |
PURPLE_CMD_P_VERY_LOW = -1000, |
|
Evan@653
|
73 |
PURPLE_CMD_P_LOW = 0, |
|
Evan@653
|
74 |
PURPLE_CMD_P_DEFAULT = 1000, |
|
Evan@653
|
75 |
PURPLE_CMD_P_PRPL = 2000, |
|
Evan@653
|
76 |
PURPLE_CMD_P_PLUGIN = 3000, |
|
Evan@653
|
77 |
PURPLE_CMD_P_ALIAS = 4000, |
|
Evan@653
|
78 |
PURPLE_CMD_P_HIGH = 5000, |
|
Evan@653
|
79 |
PURPLE_CMD_P_VERY_HIGH = 6000 |
|
Evan@653
|
80 |
} PurpleCmdPriority; |
|
Evan@653
|
81 |
|
|
Evan@653
|
82 |
/** Flags used to set various properties of commands. Every command should |
|
Evan@653
|
83 |
* have at least one of #PURPLE_CMD_FLAG_IM and #PURPLE_CMD_FLAG_CHAT set in |
|
Evan@653
|
84 |
* order to be even slighly useful. |
|
Evan@653
|
85 |
* |
|
Evan@653
|
86 |
* @see purple_cmd_register |
|
Evan@653
|
87 |
*/ |
|
Evan@653
|
88 |
typedef enum _PurpleCmdFlag { |
|
Evan@653
|
89 |
/** Command is usable in IMs. */ |
|
Evan@653
|
90 |
PURPLE_CMD_FLAG_IM = 0x01, |
|
Evan@653
|
91 |
/** Command is usable in multi-user chats. */ |
|
Evan@653
|
92 |
PURPLE_CMD_FLAG_CHAT = 0x02, |
|
Evan@653
|
93 |
/** Command is usable only for a particular prpl. */ |
|
Evan@653
|
94 |
PURPLE_CMD_FLAG_PRPL_ONLY = 0x04, |
|
Evan@653
|
95 |
/** Incorrect arguments to this command should be accepted anyway. */ |
|
Evan@653
|
96 |
PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS = 0x08 |
|
Evan@653
|
97 |
} PurpleCmdFlag; |
|
Evan@653
|
98 |
|
|
Evan@653
|
99 |
|
|
Evan@653
|
100 |
/*@}*/ |
|
Evan@653
|
101 |
|
|
Evan@653
|
102 |
#ifdef __cplusplus |
|
Evan@653
|
103 |
extern "C" { |
|
Evan@653
|
104 |
#endif |
|
Evan@653
|
105 |
|
|
Evan@653
|
106 |
/**************************************************************************/ |
|
Evan@653
|
107 |
/** @name Commands API */ |
|
Evan@653
|
108 |
/**************************************************************************/ |
|
Evan@653
|
109 |
/*@{*/ |
|
Evan@653
|
110 |
|
|
Evan@653
|
111 |
/** |
|
Evan@653
|
112 |
* Register a new command with the core. |
|
Evan@653
|
113 |
* |
|
Evan@653
|
114 |
* The command will only happen if commands are enabled, |
|
Evan@653
|
115 |
* which is a UI pref. UIs don't have to support commands at all. |
|
Evan@653
|
116 |
* |
|
Evan@653
|
117 |
* @param cmd The command. This should be a UTF-8 (or ASCII) string, with no spaces |
|
Evan@653
|
118 |
* or other white space. |
|
Evan@653
|
119 |
* @param args A string of characters describing to libpurple how to parse this |
|
Evan@653
|
120 |
* command's arguments. If what the user types doesn't match this |
|
Evan@653
|
121 |
* pattern, libpurple will keep looking for another command, unless |
|
Evan@653
|
122 |
* the flag #PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS is passed in @a f. |
|
Evan@653
|
123 |
* This string should contain no whitespace, and use a single |
|
Evan@653
|
124 |
* character for each argument. The recognized characters are: |
|
Evan@653
|
125 |
* <ul> |
|
Evan@653
|
126 |
* <li><tt>'w'</tt>: Matches a single word.</li> |
|
Evan@653
|
127 |
* <li><tt>'W'</tt>: Matches a single word, with formatting.</li> |
|
Evan@653
|
128 |
* <li><tt>'s'</tt>: Matches the rest of the arguments after this |
|
Evan@653
|
129 |
* point, as a single string.</li> |
|
Evan@653
|
130 |
* <li><tt>'S'</tt>: Same as <tt>'s'</tt> but with formatting.</li> |
|
Evan@653
|
131 |
* </ul> |
|
Evan@653
|
132 |
* If args is the empty string, then the command accepts no arguments. |
|
Evan@653
|
133 |
* The args passed to the callback @a func will be a @c NULL |
|
Evan@653
|
134 |
* terminated array of @c NULL terminated strings, and will always |
|
Evan@653
|
135 |
* match the number of arguments asked for, unless |
|
Evan@653
|
136 |
* #PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS is passed. |
|
Evan@653
|
137 |
* @param p This is the priority. Higher priority commands will be run first, |
|
Evan@653
|
138 |
* and usually the first command will stop any others from being |
|
Evan@653
|
139 |
* called. |
|
Evan@653
|
140 |
* @param f Flags specifying various options about this command, combined with |
|
Evan@653
|
141 |
* <tt>|</tt> (bitwise OR). You need to at least pass one of |
|
Evan@653
|
142 |
* #PURPLE_CMD_FLAG_IM or #PURPLE_CMD_FLAG_CHAT (you may pass both) in |
|
Evan@653
|
143 |
* order for the command to ever actually be called. |
|
Evan@653
|
144 |
* @param prpl_id If the #PURPLE_CMD_FLAG_PRPL_ONLY flag is set, this is the id |
|
Evan@653
|
145 |
* of the prpl to which the command applies (such as |
|
Evan@653
|
146 |
* <tt>"prpl-msn"</tt>). If the flag is not set, this parameter |
|
Evan@653
|
147 |
* is ignored; pass @c NULL (or a humourous string of your |
|
Evan@653
|
148 |
* choice!). |
|
Evan@653
|
149 |
* @param func This is the function to call when someone enters this command. |
|
Evan@653
|
150 |
* @param helpstr a whitespace sensitive, UTF-8, HTML string describing how to |
|
Evan@653
|
151 |
* use the command. The preferred format of this string is the |
|
Evan@653
|
152 |
* command's name, followed by a space and any arguments it |
|
Evan@653
|
153 |
* accepts (if it takes any arguments, otherwise no space), |
|
Evan@653
|
154 |
* followed by a colon, two spaces, and a description of the |
|
Evan@653
|
155 |
* command in sentence form. Do not include a slash before the |
|
Evan@653
|
156 |
* command name. |
|
Evan@653
|
157 |
* @param data User defined data to pass to the #PurpleCmdFunc @a f. |
|
Evan@653
|
158 |
* @return A #PurpleCmdId, which is only used for calling |
|
Evan@653
|
159 |
* #purple_cmd_unregister, or @a 0 on failure. |
|
Evan@653
|
160 |
*/ |
|
Evan@653
|
161 |
PurpleCmdId purple_cmd_register(const gchar *cmd, const gchar *args, PurpleCmdPriority p, PurpleCmdFlag f, |
|
Evan@653
|
162 |
const gchar *prpl_id, PurpleCmdFunc func, const gchar *helpstr, void *data); |
|
Evan@653
|
163 |
|
|
Evan@653
|
164 |
/** |
|
Evan@653
|
165 |
* Unregister a command with the core. |
|
Evan@653
|
166 |
* |
|
Evan@653
|
167 |
* All registered commands must be unregistered, if they're registered by a plugin |
|
Evan@653
|
168 |
* or something else that might go away. Normally this is called when the plugin |
|
Evan@653
|
169 |
* unloads itself. |
|
Evan@653
|
170 |
* |
|
Evan@653
|
171 |
* @param id The #PurpleCmdId to unregister, as returned by #purple_cmd_register. |
|
Evan@653
|
172 |
*/ |
|
Evan@653
|
173 |
void purple_cmd_unregister(PurpleCmdId id); |
|
Evan@653
|
174 |
|
|
Evan@653
|
175 |
/** |
|
Evan@653
|
176 |
* Do a command. |
|
Evan@653
|
177 |
* |
|
Evan@653
|
178 |
* Normally the UI calls this to perform a command. This might also be useful |
|
Evan@653
|
179 |
* if aliases are ever implemented. |
|
Evan@653
|
180 |
* |
|
Evan@653
|
181 |
* @param conv The conversation the command was typed in. |
|
Evan@653
|
182 |
* @param cmdline The command the user typed (including all arguments) as a single string. |
|
Evan@653
|
183 |
* The caller doesn't have to do any parsing, except removing the command |
|
Evan@653
|
184 |
* prefix, which the core has no knowledge of. cmd should not contain any |
|
Evan@653
|
185 |
* formatting, and should be in plain text (no html entities). |
|
Evan@653
|
186 |
* @param markup This is the same as cmd, but is the formatted version. It should be in |
|
Evan@653
|
187 |
* HTML, with < > and &, at least, escaped to html entities, and should |
|
Evan@653
|
188 |
* include both the default formatting and any extra manual formatting. |
|
Evan@653
|
189 |
* @param errormsg If the command failed errormsg is filled in with the appropriate error |
|
Evan@653
|
190 |
* message. It must be freed by the caller with g_free(). |
|
Evan@653
|
191 |
* @return A #PurpleCmdStatus indicating if the command succeeded or failed. |
|
Evan@653
|
192 |
*/ |
|
Evan@653
|
193 |
PurpleCmdStatus purple_cmd_do_command(PurpleConversation *conv, const gchar *cmdline, |
|
Evan@653
|
194 |
const gchar *markup, gchar **errormsg); |
|
Evan@653
|
195 |
|
|
Evan@653
|
196 |
/** |
|
Evan@653
|
197 |
* List registered commands. |
|
Evan@653
|
198 |
* |
|
Evan@653
|
199 |
* Returns a <tt>GList</tt> (which must be freed by the caller) of all commands |
|
Evan@653
|
200 |
* that are valid in the context of @a conv, or all commands, if @a conv is @c |
|
Evan@653
|
201 |
* NULL. Don't keep this list around past the main loop, or anything else that |
|
Evan@653
|
202 |
* might unregister a command, as the <tt>const char *</tt>'s used get freed |
|
Evan@653
|
203 |
* then. |
|
Evan@653
|
204 |
* |
|
Evan@653
|
205 |
* @param conv The conversation, or @c NULL. |
|
Evan@653
|
206 |
* @return A @c GList of <tt>const char *</tt>, which must be freed with |
|
Evan@653
|
207 |
* <tt>g_list_free()</tt>. |
|
Evan@653
|
208 |
*/ |
|
Evan@653
|
209 |
GList *purple_cmd_list(PurpleConversation *conv); |
|
Evan@653
|
210 |
|
|
Evan@653
|
211 |
/** |
|
Evan@653
|
212 |
* Get the help string for a command. |
|
Evan@653
|
213 |
* |
|
Evan@653
|
214 |
* Returns the help strings for a given command in the form of a GList, |
|
Evan@653
|
215 |
* one node for each matching command. |
|
Evan@653
|
216 |
* |
|
Evan@653
|
217 |
* @param conv The conversation, or @c NULL for no context. |
|
Evan@653
|
218 |
* @param cmd The command. No wildcards accepted, but returns help for all |
|
Evan@653
|
219 |
* commands if @c NULL. |
|
Evan@653
|
220 |
* @return A <tt>GList</tt> of <tt>const char *</tt>s, which is the help string |
|
Evan@653
|
221 |
* for that command. |
|
Evan@653
|
222 |
*/ |
|
Evan@653
|
223 |
GList *purple_cmd_help(PurpleConversation *conv, const gchar *cmd); |
|
Evan@653
|
224 |
|
|
Evan@653
|
225 |
/** |
|
Evan@653
|
226 |
* Get the handle for the commands API |
|
Evan@653
|
227 |
* @return The handle |
|
Evan@653
|
228 |
* @since 2.5.0 |
|
Evan@653
|
229 |
*/ |
|
Evan@653
|
230 |
gpointer purple_cmds_get_handle(void); |
|
Evan@653
|
231 |
|
|
Evan@653
|
232 |
/** |
|
Evan@653
|
233 |
* Initialize the commands subsystem. |
|
Evan@653
|
234 |
* @since 2.5.0 |
|
Evan@653
|
235 |
*/ |
|
Evan@653
|
236 |
void purple_cmds_init(void); |
|
Evan@653
|
237 |
|
|
Evan@653
|
238 |
/** |
|
Evan@653
|
239 |
* Uninitialize the commands subsystem. |
|
Evan@653
|
240 |
* @since 2.5.0 |
|
Evan@653
|
241 |
*/ |
|
Evan@653
|
242 |
void purple_cmds_uninit(void); |
|
Evan@653
|
243 |
|
|
Evan@653
|
244 |
/*@}*/ |
|
Evan@653
|
245 |
|
|
Evan@653
|
246 |
#ifdef __cplusplus |
|
Evan@653
|
247 |
} |
|
Evan@653
|
248 |
#endif |
|
Evan@653
|
249 |
|
|
Evan@653
|
250 |
#endif /* _PURPLE_CMDS_H_ */ |