comparison libpurple/protocols/myspace/myspace.c @ 17368:3720176bdac6

Pass postprocessing parameters inside MsimMessage * instead of in a new struct. (UNTESTED)
author Jeffrey Connelly <jaconnel@calpoly.edu>
date Wed, 06 Jun 2007 02:49:35 +0000
parents 05723949f75d
children 962edb051146
comparison
equal deleted inserted replaced
17367:05723949f75d 17368:3720176bdac6
1118 purple_notify_error(NULL, NULL, _("Failed to add buddy"), _("persist command failed")); 1118 purple_notify_error(NULL, NULL, _("Failed to add buddy"), _("persist command failed"));
1119 return; 1119 return;
1120 } 1120 }
1121 } 1121 }
1122 1122
1123 typedef struct _POSTPROCESS_INFO
1124 {
1125 MsimMessage *msg;
1126 gchar *username;
1127 gchar *uid_field_name;
1128 gchar *uid_before;
1129 } POSTPROCESS_INFO;
1130
1131 /* Callback for msim_postprocess_outgoing() to add a uid field, after resolving username/email. */ 1123 /* Callback for msim_postprocess_outgoing() to add a uid field, after resolving username/email. */
1132 void msim_postprocess_outgoing_cb(MsimSession *session, MsimMessage *userinfo, gpointer data) 1124 void msim_postprocess_outgoing_cb(MsimSession *session, MsimMessage *userinfo, gpointer data)
1133 { 1125 {
1134 gchar *body_str; 1126 gchar *body_str;
1135 GHashTable *body; 1127 GHashTable *body;
1136 gchar *uid; 1128 gchar *uid, *uid_field_name, *uid_before;
1137 POSTPROCESS_INFO *pi; 1129 MsimMessage *msg;
1138 1130
1139 pi = (POSTPROCESS_INFO *)data; 1131 msg = (MsimMessage *)data;
1132
1133 msim_msg_dump("msim_postprocess_outgoing_cb() got msg=%s\n", msg);
1140 1134
1141 /* Obtain userid from userinfo message. */ 1135 /* Obtain userid from userinfo message. */
1142 body_str = msim_msg_get_string(userinfo, "body"); 1136 body_str = msim_msg_get_string(userinfo, "body");
1143 g_return_if_fail(body_str != NULL); 1137 g_return_if_fail(body_str != NULL);
1144 body = msim_parse_body(body_str); 1138 body = msim_parse_body(body_str);
1146 1140
1147 uid = g_strdup(g_hash_table_lookup(body, "UserID")); 1141 uid = g_strdup(g_hash_table_lookup(body, "UserID"));
1148 g_hash_table_destroy(body); 1142 g_hash_table_destroy(body);
1149 1143
1150 /* Insert into outgoing message. */ 1144 /* Insert into outgoing message. */
1151 pi->msg = msim_msg_insert_before(pi->msg, pi->uid_before, 1145 uid_field_name = msim_msg_get_string(msg, "_uid_field_name");
1152 pi->uid_field_name, MSIM_TYPE_STRING, uid); 1146 uid_before = msim_msg_get_string(msg, "_uid_before");
1147
1148 msg = msim_msg_insert_before(msg, uid_field_name, uid_before, MSIM_TYPE_STRING, uid);
1149
1150 g_free(uid_field_name);
1151 g_free(uid_before);
1153 1152
1154 /* Send */ 1153 /* Send */
1155 g_return_if_fail(msim_msg_send(session, pi->msg)); 1154 g_return_if_fail(msim_msg_send(session, msg));
1156
1157 g_free(pi);
1158 } 1155 }
1159 1156
1160 /** Postprocess and send a message. 1157 /** Postprocess and send a message.
1161 * 1158 *
1162 * @param session 1159 * @param session
1163 * @param msg Message to postprocess. 1160 * @param msg Message to postprocess.
1164 * @param username Username to resolve. 1161 * @param username Username to resolve. Assumed to be a static string (will not be freed or copied).
1165 * @param uid_field_name Name of new field to add, containing uid of username. 1162 * @param uid_field_name Name of new field to add, containing uid of username. Static string.
1166 * @param uid_before Name of existing field to insert username field before. 1163 * @param uid_before Name of existing field to insert username field before. Static string.
1167 * 1164 *
1168 * @return Postprocessed message. 1165 * @return Postprocessed message.
1169 */ 1166 */
1170 gboolean msim_postprocess_outgoing(MsimSession *session, MsimMessage *msg, gchar *username, 1167 gboolean msim_postprocess_outgoing(MsimSession *session, MsimMessage *msg, gchar *username,
1171 gchar *uid_field_name, gchar *uid_before) 1168 gchar *uid_field_name, gchar *uid_before)
1172 { 1169 {
1173 PurpleBuddy *buddy; 1170 PurpleBuddy *buddy;
1174 guint uid; 1171 guint uid;
1175 POSTPROCESS_INFO* pi; 1172
1176 1173 /* Store information for msim_postprocess_outgoing_cb(). */
1177 pi = g_new0(POSTPROCESS_INFO, 1); 1174 purple_debug_info("msim", "msim_postprocess_outgoing(u=%s,ufn=%s,ub=%s)\n",
1178 1175 username, uid_field_name, uid_before);
1179 pi->msg = msim_msg_clone(msg); 1176 msg = msim_msg_append(msg, "_username", MSIM_TYPE_STRING, g_strdup(username));
1180 pi->uid_before = uid_before; 1177 msg = msim_msg_append(msg, "_uid_field_name", MSIM_TYPE_STRING, g_strdup(uid_field_name));
1181 pi->uid_field_name = uid_field_name; 1178 msg = msim_msg_append(msg, "_uid_before", MSIM_TYPE_STRING, g_strdup(uid_before));
1182 pi->username = username;
1183 1179
1184 /* First, try the most obvious. If numeric userid is given, use that directly. */ 1180 /* First, try the most obvious. If numeric userid is given, use that directly. */
1185 if (msim_is_userid(username)) 1181 if (msim_is_userid(username))
1186 { 1182 {
1187 uid = atol(username); 1183 uid = atol(username);
1197 1193
1198 if (!buddy || !uid) 1194 if (!buddy || !uid)
1199 { 1195 {
1200 purple_debug_info("msim", ">>> msim_postprocess_outgoing: couldn't find username %s in blist\n", 1196 purple_debug_info("msim", ">>> msim_postprocess_outgoing: couldn't find username %s in blist\n",
1201 username); 1197 username);
1202 msim_lookup_user(session, username, msim_postprocess_outgoing_cb, pi); 1198 msim_lookup_user(session, username, msim_postprocess_outgoing_cb, msim_msg_clone(msg));
1203 return TRUE; /* not sure of status yet - haven't sent! */ 1199 return TRUE; /* not sure of status yet - haven't sent! */
1204 } 1200 }
1205 } 1201 }
1206 1202
1207 /* Already have uid, insert it and send msg. */ 1203 /* Already have uid, insert it and send msg. */