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