comparison mcabber/src/commands.c @ 1430:12847b0ea8c9

Add an option "-q" (quiet) to /say_to New prototype: /SAY_TO [-q] jid message Useful for non-interactive commands (FIFO, external sourced files...)
author Mikael Berthe <mikael@lilotux.net>
date Wed, 20 Feb 2008 21:26:54 +0100
parents 99d95d4ea806
children 46e5eb9917bc
comparison
equal deleted inserted replaced
1429:99d95d4ea806 1430:12847b0ea8c9
1072 do_group_return: 1072 do_group_return:
1073 free_arg_lst(paramlst); 1073 free_arg_lst(paramlst);
1074 } 1074 }
1075 1075
1076 static int send_message_to(const char *fjid, const char *msg, const char *subj, 1076 static int send_message_to(const char *fjid, const char *msg, const char *subj,
1077 const char *type_overwrite) 1077 const char *type_overwrite, bool quiet)
1078 { 1078 {
1079 char *bare_jid, *rp; 1079 char *bare_jid, *rp;
1080 char *hmsg; 1080 char *hmsg;
1081 gint crypted; 1081 gint crypted;
1082 gint retval = 0; 1082 gint retval = 0;
1100 return 1; 1100 return 1;
1101 } 1101 }
1102 1102
1103 // We must use the bare jid in hk_message_out() 1103 // We must use the bare jid in hk_message_out()
1104 rp = strchr(fjid, JID_RESOURCE_SEPARATOR); 1104 rp = strchr(fjid, JID_RESOURCE_SEPARATOR);
1105 if (rp) bare_jid = g_strndup(fjid, rp - fjid); 1105 if (rp)
1106 else bare_jid = (char*)fjid; 1106 bare_jid = g_strndup(fjid, rp - fjid);
1107 1107 else
1108 // Jump to window, create one if needed 1108 bare_jid = (char*)fjid;
1109 scr_RosterJumpJid(bare_jid); 1109
1110 if (!quiet) {
1111 // Jump to window, create one if needed
1112 scr_RosterJumpJid(bare_jid);
1113 }
1110 1114
1111 // Check if we're sending a message to a conference room 1115 // Check if we're sending a message to a conference room
1112 // If not, we must make sure rp is NULL, for hk_message_out() 1116 // If not, we must make sure rp is NULL, for hk_message_out()
1113 isroom = !!roster_find(bare_jid, jidsearch, ROSTER_TYPE_ROOM); 1117 isroom = !!roster_find(bare_jid, jidsearch, ROSTER_TYPE_ROOM);
1114 if (rp) { 1118 if (rp) {
1161 if (!bjid) { 1165 if (!bjid) {
1162 scr_LogPrint(LPRINT_NORMAL, "No buddy is currently selected."); 1166 scr_LogPrint(LPRINT_NORMAL, "No buddy is currently selected.");
1163 return; 1167 return;
1164 } 1168 }
1165 1169
1166 send_message_to(bjid, msg, subj, type_overwrite); 1170 send_message_to(bjid, msg, subj, type_overwrite, FALSE);
1167 } 1171 }
1168 1172
1169 static const char *scan_mtype(char **arg) 1173 static const char *scan_mtype(char **arg)
1170 { 1174 {
1171 //Try splitting it 1175 //Try splitting it
1299 // Let's send to the specified JID. We leave now if there 1303 // Let's send to the specified JID. We leave now if there
1300 // has been an error (so we don't leave multi-line mode). 1304 // has been an error (so we don't leave multi-line mode).
1301 arg = to_utf8(arg); 1305 arg = to_utf8(arg);
1302 msg_utf8 = to_utf8(scr_get_multiline()); 1306 msg_utf8 = to_utf8(scr_get_multiline());
1303 if (msg_utf8) { 1307 if (msg_utf8) {
1304 err = send_message_to(arg, msg_utf8, scr_get_multimode_subj(), msg_type); 1308 err = send_message_to(arg, msg_utf8, scr_get_multimode_subj(), msg_type,
1309 FALSE);
1305 g_free(msg_utf8); 1310 g_free(msg_utf8);
1306 } 1311 }
1307 g_free(arg); 1312 g_free(arg);
1308 if (err) 1313 if (err)
1309 goto do_msay_return; 1314 goto do_msay_return;
1339 static void do_say_to(char *arg) 1344 static void do_say_to(char *arg)
1340 { 1345 {
1341 char **paramlst; 1346 char **paramlst;
1342 char *fjid, *msg; 1347 char *fjid, *msg;
1343 const char *msg_type = NULL; 1348 const char *msg_type = NULL;
1349 bool quiet = FALSE;
1344 1350
1345 if (!jb_getonline()) { 1351 if (!jb_getonline()) {
1346 scr_LogPrint(LPRINT_NORMAL, "You are not connected."); 1352 scr_LogPrint(LPRINT_NORMAL, "You are not connected.");
1347 return; 1353 return;
1348 } 1354 }
1349 1355
1350 msg_type = scan_mtype(&arg); 1356 msg_type = scan_mtype(&arg);
1351 paramlst = split_arg(arg, 2, 1); // jid, message 1357 paramlst = split_arg(arg, 2, 1); // jid, message (or option, jid, message)
1358
1359 // Check for an option parameter
1360 if (*paramlst && !strcmp(*paramlst, "-q")) {
1361 char **oldparamlst = paramlst;
1362 paramlst = split_arg(*(oldparamlst+1), 2, 1); // jid, message
1363 free_arg_lst(oldparamlst);
1364 quiet = TRUE;
1365 }
1366
1352 fjid = *paramlst; 1367 fjid = *paramlst;
1353 msg = *(paramlst+1); 1368 msg = *(paramlst+1);
1354 1369
1355 if (!fjid || !strcmp(fjid, ".")) { 1370 if (!fjid || !strcmp(fjid, ".")) {
1356 scr_LogPrint(LPRINT_NORMAL, "Please specify a Jabber ID."); 1371 scr_LogPrint(LPRINT_NORMAL, "Please specify a Jabber ID.");
1359 } 1374 }
1360 1375
1361 fjid = to_utf8(fjid); 1376 fjid = to_utf8(fjid);
1362 msg = to_utf8(msg); 1377 msg = to_utf8(msg);
1363 1378
1364 send_message_to(fjid, msg, NULL, msg_type); 1379 send_message_to(fjid, msg, NULL, msg_type, quiet);
1365 1380
1366 g_free(fjid); 1381 g_free(fjid);
1367 g_free(msg); 1382 g_free(msg);
1368 free_arg_lst(paramlst); 1383 free_arg_lst(paramlst);
1369 } 1384 }
2385 } 2400 }
2386 2401
2387 fjid = g_strdup_printf("%s/%s", buddy_getjid(bud), nick); 2402 fjid = g_strdup_printf("%s/%s", buddy_getjid(bud), nick);
2388 fjid_utf8 = to_utf8(fjid); 2403 fjid_utf8 = to_utf8(fjid);
2389 msg = to_utf8(arg); 2404 msg = to_utf8(arg);
2390 send_message_to(fjid_utf8, msg, NULL, NULL); 2405 send_message_to(fjid_utf8, msg, NULL, NULL, FALSE);
2391 g_free(fjid); 2406 g_free(fjid);
2392 g_free(fjid_utf8); 2407 g_free(fjid_utf8);
2393 g_free(msg); 2408 g_free(msg);
2394 free_arg_lst(paramlst); 2409 free_arg_lst(paramlst);
2395 } 2410 }