comparison libpurple/protocols/myspace/message.c @ 18897:d0be4366e876

Change msim_msg_new() and msim_msg_new_v() to accept the first key name as the first argument, instead of a boolean value indicating that variadic arguments follow. So now, you don't need to pass TRUE as the first argument all the time. NULL can still be passed in the first argument (well, instead of FALSE) to create a new empty message.
author Jeffrey Connelly <jaconnel@calpoly.edu>
date Sat, 11 Aug 2007 17:57:19 +0000
parents f732d072b118
children 3f95e691bad2
comparison
equal deleted inserted replaced
18896:945a77c7079c 18897:d0be4366e876
25 static gchar *msim_unescape_or_escape(const gchar *msg, gboolean escape); 25 static gchar *msim_unescape_or_escape(const gchar *msg, gboolean escape);
26 static void msim_msg_free_element(gpointer data, gpointer user_data); 26 static void msim_msg_free_element(gpointer data, gpointer user_data);
27 static void msim_msg_debug_string_element(gpointer data, gpointer user_data); 27 static void msim_msg_debug_string_element(gpointer data, gpointer user_data);
28 static gchar *msim_msg_pack_using(MsimMessage *msg, GFunc gf, const gchar *sep, const gchar *begin, const gchar *end); 28 static gchar *msim_msg_pack_using(MsimMessage *msg, GFunc gf, const gchar *sep, const gchar *begin, const gchar *end);
29 static GList *msim_msg_get_node(MsimMessage *msg, const gchar *name); 29 static GList *msim_msg_get_node(MsimMessage *msg, const gchar *name);
30 static MsimMessage *msim_msg_new_v(va_list argp); 30 static MsimMessage *msim_msg_new_v(gchar *first_key, va_list argp);
31 31
32 /* Escape codes and associated replacement text, used for protocol message 32 /* Escape codes and associated replacement text, used for protocol message
33 * escaping and unescaping. */ 33 * escaping and unescaping. */
34 static struct MSIM_ESCAPE_REPLACEMENT { 34 static struct MSIM_ESCAPE_REPLACEMENT {
35 gchar *code; 35 gchar *code;
99 return msim_unescape_or_escape(msg, FALSE); 99 return msim_unescape_or_escape(msg, FALSE);
100 } 100 }
101 101
102 /** Create a new MsimMessage. 102 /** Create a new MsimMessage.
103 * 103 *
104 * @param not_empty FALSE if message is empty, TRUE if variadic arguments follow. 104 * @param first_key The first key in the sequence, or NULL for an empty message.
105 * @param ... A sequence of gchar* key/type/value triplets, terminated with NULL. 105 * @param ... A sequence of gchar* key/type/value triplets, terminated with NULL.
106 * 106 *
107 * See msim_msg_append() documentation for details on types. 107 * See msim_msg_append() documentation for details on types.
108 */ 108 */
109 MsimMessage * 109 MsimMessage *
110 msim_msg_new(gboolean not_empty, ...) 110 msim_msg_new(gchar *first_key, ...)
111 { 111 {
112 va_list argp; 112 va_list argp;
113 113
114 va_start(argp, not_empty); 114 if (first_key) {
115 115 va_start(argp, first_key);
116 if (not_empty) { 116 return msim_msg_new_v(first_key, argp);
117 return msim_msg_new_v(argp);
118 } else { 117 } else {
119 return NULL; 118 return NULL;
120 } 119 }
121 } 120 }
122 121
123 /** Create a new message from va_list and its first argument. 122 /** Create a new message from va_list and its first argument.
124 * 123 *
124 * @param first_key The first argument (a key), or NULL to take all arguments
125 * from argp.
125 * @param argp A va_list of variadic arguments, already started with va_start(). Will be va_end()'d. 126 * @param argp A va_list of variadic arguments, already started with va_start(). Will be va_end()'d.
126 * @return New MsimMessage *, must be freed with msim_msg_free(). 127 * @return New MsimMessage *, must be freed with msim_msg_free().
127 * 128 *
128 * For internal use - users probably want msim_msg_new() or msim_send(). 129 * For internal use - users probably want msim_msg_new() or msim_send().
129 */ 130 */
130 static MsimMessage * 131 static MsimMessage *
131 msim_msg_new_v(va_list argp) 132 msim_msg_new_v(gchar *first_key, va_list argp)
132 { 133 {
133 gchar *key, *value; 134 gchar *key, *value;
134 MsimMessageType type; 135 MsimMessageType type;
135 MsimMessage *msg; 136 MsimMessage *msg;
137 gboolean first;
136 138
137 GString *gs; 139 GString *gs;
138 GList *gl; 140 GList *gl;
139 MsimMessage *dict; 141 MsimMessage *dict;
140 142
141
142 /* Begin with an empty message. */ 143 /* Begin with an empty message. */
143 msg = NULL; 144 msg = NULL;
145
146 /* First parameter can be given explicitly. */
147 first = first_key != NULL;
144 148
145 /* Read key, type, value triplets until NULL. */ 149 /* Read key, type, value triplets until NULL. */
146 do { 150 do {
147 key = va_arg(argp, gchar *); 151 if (first)
148 if (!key) { 152 {
149 break; 153 key = first_key;
150 } 154 first = FALSE;
155 } else {
156 key = va_arg(argp, gchar *);
157 if (!key) {
158 break;
159 }
160 }
151 161
152 type = va_arg(argp, int); 162 type = va_arg(argp, int);
153 163
154 /* Interpret variadic arguments. */ 164 /* Interpret variadic arguments. */
155 switch (type) { 165 switch (type) {
438 gboolean success; 448 gboolean success;
439 MsimMessage *msg; 449 MsimMessage *msg;
440 va_list argp; 450 va_list argp;
441 451
442 va_start(argp, session); 452 va_start(argp, session);
443 msg = msim_msg_new_v(argp); 453 msg = msim_msg_new_v(NULL, argp);
444 454
445 /* Actually send the message. */ 455 /* Actually send the message. */
446 success = msim_msg_send(session, msg); 456 success = msim_msg_send(session, msg);
447 457
448 /* Cleanup. */ 458 /* Cleanup. */