comparison mcabber/src/commands.c @ 1066:6de60e142372

Add command /pgp
author Mikael Berthe <mikael@lilotux.net>
date Sat, 02 Dec 2006 12:45:17 +0100
parents 230dca34dbea
children 9eaacc0ad3a2
comparison
equal deleted inserted replaced
1065:230dca34dbea 1066:6de60e142372
67 static void do_authorization(char *arg); 67 static void do_authorization(char *arg);
68 static void do_version(char *arg); 68 static void do_version(char *arg);
69 static void do_request(char *arg); 69 static void do_request(char *arg);
70 static void do_event(char *arg); 70 static void do_event(char *arg);
71 static void do_help(char *arg); 71 static void do_help(char *arg);
72 static void do_pgp(char *arg);
72 73
73 // Global variable for the commands list 74 // Global variable for the commands list
74 static GSList *Commands; 75 static GSList *Commands;
75 76
76 77
111 cmd_add("info", "Show basic info on current buddy", 0, 0, &do_info); 112 cmd_add("info", "Show basic info on current buddy", 0, 0, &do_info);
112 cmd_add("move", "Move the current buddy to another group", COMPL_GROUPNAME, 113 cmd_add("move", "Move the current buddy to another group", COMPL_GROUPNAME,
113 0, &do_move); 114 0, &do_move);
114 cmd_add("msay", "Send a multi-lines message to the selected buddy", 115 cmd_add("msay", "Send a multi-lines message to the selected buddy",
115 COMPL_MULTILINE, 0, &do_msay); 116 COMPL_MULTILINE, 0, &do_msay);
117 cmd_add("pgp", "Manage PGP settings", COMPL_PGP, COMPL_JID, &do_pgp);
116 cmd_add("quit", "Exit the software", 0, 0, NULL); 118 cmd_add("quit", "Exit the software", 0, 0, NULL);
117 cmd_add("rawxml", "Send a raw XML string", 0, 0, &do_rawxml); 119 cmd_add("rawxml", "Send a raw XML string", 0, 0, &do_rawxml);
118 cmd_add("rename", "Rename the current buddy", 0, 0, &do_rename); 120 cmd_add("rename", "Rename the current buddy", 0, 0, &do_rename);
119 cmd_add("request", "Send a Jabber IQ request", COMPL_REQUEST, COMPL_JID, 121 cmd_add("request", "Send a Jabber IQ request", COMPL_REQUEST, COMPL_JID,
120 &do_request); 122 &do_request);
220 222
221 // Events category 223 // Events category
222 compl_add_category_word(COMPL_EVENTS, "accept"); 224 compl_add_category_word(COMPL_EVENTS, "accept");
223 compl_add_category_word(COMPL_EVENTS, "ignore"); 225 compl_add_category_word(COMPL_EVENTS, "ignore");
224 compl_add_category_word(COMPL_EVENTS, "reject"); 226 compl_add_category_word(COMPL_EVENTS, "reject");
227
228 // PGP category
229 compl_add_category_word(COMPL_PGP, "disable");
230 compl_add_category_word(COMPL_PGP, "enable");
231 compl_add_category_word(COMPL_PGP, "info");
232 compl_add_category_word(COMPL_PGP, "setkey");
225 } 233 }
226 234
227 // expandalias(line) 235 // expandalias(line)
228 // If there is one, expand the alias in line and returns a new allocated line 236 // If there is one, expand the alias in line and returns a new allocated line
229 // If no alias is found, returns line 237 // If no alias is found, returns line
1351 scr_WriteIncomingMessage(bjid, buffer, 0, HBB_PREFIX_NONE); 1359 scr_WriteIncomingMessage(bjid, buffer, 0, HBB_PREFIX_NONE);
1352 } 1360 }
1353 } 1361 }
1354 #endif 1362 #endif
1355 } 1363 }
1356 #ifdef HAVE_GPGME
1357 if (settings_pgp_getdisabled(bjid))
1358 scr_WriteIncomingMessage(bjid, "PGP is disabled", 0, HBB_PREFIX_NONE);
1359 #endif
1360 } else { 1364 } else {
1361 if (name) scr_LogPrint(LPRINT_NORMAL, "Name: %s", name); 1365 if (name) scr_LogPrint(LPRINT_NORMAL, "Name: %s", name);
1362 scr_LogPrint(LPRINT_NORMAL, "Type: %s", 1366 scr_LogPrint(LPRINT_NORMAL, "Type: %s",
1363 type == ROSTER_TYPE_GROUP ? "group" : 1367 type == ROSTER_TYPE_GROUP ? "group" :
1364 (type == ROSTER_TYPE_SPECIAL ? "special" : "unknown")); 1368 (type == ROSTER_TYPE_SPECIAL ? "special" : "unknown"));
2528 } 2532 }
2529 2533
2530 free_arg_lst(paramlst); 2534 free_arg_lst(paramlst);
2531 } 2535 }
2532 2536
2537 static void do_pgp(char *arg)
2538 {
2539 char **paramlst;
2540 char *fjid, *subcmd, *keyid;
2541 enum {
2542 pgp_none,
2543 pgp_enable,
2544 pgp_disable,
2545 pgp_setkey,
2546 pgp_info
2547 } op = 0;
2548
2549 paramlst = split_arg(arg, 3, 0); // subcmd, jid, [key]
2550 subcmd = *paramlst;
2551 fjid = *(paramlst+1);
2552 keyid = *(paramlst+2);
2553
2554 if (!subcmd)
2555 fjid = NULL;
2556 if (!fjid)
2557 keyid = NULL;
2558
2559 if (subcmd) {
2560 if (!strcasecmp(subcmd, "enable"))
2561 op = pgp_enable;
2562 else if (!strcasecmp(subcmd, "disable"))
2563 op = pgp_disable;
2564 else if (!strcasecmp(subcmd, "setkey"))
2565 op = pgp_setkey;
2566 else if (!strcasecmp(subcmd, "info"))
2567 op = pgp_info;
2568 }
2569
2570 if (!op) {
2571 scr_LogPrint(LPRINT_NORMAL, "Unrecognized or missing parameter!");
2572 free_arg_lst(paramlst);
2573 return;
2574 }
2575
2576 // Allow special jid "" or "." (current buddy)
2577 if (fjid && (!*fjid || !strcmp(fjid, ".")))
2578 fjid = NULL;
2579
2580 if (fjid) {
2581 // The JID has been specified. Quick check...
2582 if (check_jid_syntax(fjid) || !strchr(fjid, '@')) {
2583 scr_LogPrint(LPRINT_NORMAL|LPRINT_NOTUTF8,
2584 "<%s> is not a valid Jabber ID.", fjid);
2585 fjid = NULL;
2586 } else {
2587 // Convert jid to lowercase and strip resource
2588 char *p;
2589 for (p = fjid; *p && *p != JID_RESOURCE_SEPARATOR; p++)
2590 *p = tolower(*p);
2591 if (*p == JID_RESOURCE_SEPARATOR)
2592 *p = '\0';
2593 }
2594 } else {
2595 gpointer bud = NULL;
2596 if (current_buddy)
2597 bud = BUDDATA(current_buddy);
2598 if (bud) {
2599 guint type = buddy_gettype(bud);
2600 if (type & ROSTER_TYPE_USER) // Is it a user?
2601 fjid = (char*)buddy_getjid(bud);
2602 else
2603 scr_LogPrint(LPRINT_NORMAL, "The selected item should be a user.");
2604 }
2605 }
2606
2607 if (fjid) { // fjid is actually a bare jid...
2608 GString *sbuf;
2609 switch (op) {
2610 case pgp_enable:
2611 case pgp_disable:
2612 settings_pgp_setdisabled(fjid, (op == pgp_disable ? TRUE : FALSE));
2613 break;
2614 case pgp_setkey:
2615 settings_pgp_setkeyid(fjid, keyid);
2616 break;
2617 case pgp_info:
2618 sbuf = g_string_new("");
2619 if (settings_pgp_getkeyid(fjid)) {
2620 g_string_printf(sbuf, "PGP Encryption key id: %s",
2621 settings_pgp_getkeyid(fjid));
2622 scr_WriteIncomingMessage(fjid, sbuf->str, 0, HBB_PREFIX_INFO);
2623 }
2624 g_string_printf(sbuf, "PGP encryption is %s",
2625 (settings_pgp_getdisabled(fjid) ? "disabled" :
2626 "enabled"));
2627 scr_WriteIncomingMessage(fjid, sbuf->str, 0, HBB_PREFIX_INFO);
2628 g_string_free(sbuf, TRUE);
2629 break;
2630 default:
2631 break;
2632 }
2633 } else {
2634 scr_LogPrint(LPRINT_NORMAL, "Please specify a valid Jabber ID.");
2635 }
2636
2637 free_arg_lst(paramlst);
2638 }
2639
2533 static void do_connect(char *arg) 2640 static void do_connect(char *arg)
2534 { 2641 {
2535 mcabber_connect(); 2642 mcabber_connect();
2536 } 2643 }
2537 2644