comparison mcabber/src/commands.c @ 693:e98abd3ce28c

Add /request command Usage: /request version|time [jid]
author Mikael Berthe <mikael@lilotux.net>
date Sat, 11 Feb 2006 15:18:45 +0100
parents 8dc602a246a4
children 6d6fdaf846ed
comparison
equal deleted inserted replaced
692:d3511f846d47 693:e98abd3ce28c
53 static void do_disconnect(char *arg); 53 static void do_disconnect(char *arg);
54 static void do_rawxml(char *arg); 54 static void do_rawxml(char *arg);
55 static void do_room(char *arg); 55 static void do_room(char *arg);
56 static void do_authorization(char *arg); 56 static void do_authorization(char *arg);
57 static void do_version(char *arg); 57 static void do_version(char *arg);
58 static void do_request(char *arg);
58 59
59 // Global variable for the commands list 60 // Global variable for the commands list
60 static GSList *Commands; 61 static GSList *Commands;
61 62
62 63
97 cmd_add("move", "Move the current buddy to another group", COMPL_GROUPNAME, 98 cmd_add("move", "Move the current buddy to another group", COMPL_GROUPNAME,
98 0, &do_move); 99 0, &do_move);
99 cmd_add("msay", "Send a multi-lines message to the selected buddy", 100 cmd_add("msay", "Send a multi-lines message to the selected buddy",
100 COMPL_MULTILINE, 0, &do_msay); 101 COMPL_MULTILINE, 0, &do_msay);
101 cmd_add("room", "MUC actions command", COMPL_ROOM, 0, &do_room); 102 cmd_add("room", "MUC actions command", COMPL_ROOM, 0, &do_room);
103 cmd_add("request", "Send a Jabber IQ request", COMPL_REQUEST, COMPL_JID,
104 &do_request);
102 cmd_add("quit", "Exit the software", 0, 0, NULL); 105 cmd_add("quit", "Exit the software", 0, 0, NULL);
103 cmd_add("rawxml", "Send a raw XML string", 0, 0, &do_rawxml); 106 cmd_add("rawxml", "Send a raw XML string", 0, 0, &do_rawxml);
104 cmd_add("rename", "Rename the current buddy", 0, 0, &do_rename); 107 cmd_add("rename", "Rename the current buddy", 0, 0, &do_rename);
105 cmd_add("roster", "Manipulate the roster/buddylist", COMPL_ROSTER, 0, 108 cmd_add("roster", "Manipulate the roster/buddylist", COMPL_ROSTER, 0,
106 &do_roster); 109 &do_roster);
178 181
179 // Authorization category 182 // Authorization category
180 compl_add_category_word(COMPL_AUTH, "allow"); 183 compl_add_category_word(COMPL_AUTH, "allow");
181 compl_add_category_word(COMPL_AUTH, "cancel"); 184 compl_add_category_word(COMPL_AUTH, "cancel");
182 compl_add_category_word(COMPL_AUTH, "request"); 185 compl_add_category_word(COMPL_AUTH, "request");
186
187 // Request (query) category
188 compl_add_category_word(COMPL_REQUEST, "time");
189 compl_add_category_word(COMPL_REQUEST, "version");
183 } 190 }
184 191
185 // expandalias(line) 192 // expandalias(line)
186 // If there is one, expand the alias in line and returns a new allocated line 193 // If there is one, expand the alias in line and returns a new allocated line
187 // If no alias is found, returns line 194 // If no alias is found, returns line
1855 static void do_version(char *arg) 1862 static void do_version(char *arg)
1856 { 1863 {
1857 scr_LogPrint(LPRINT_NORMAL, "This is mcabber version %s.", PACKAGE_VERSION); 1864 scr_LogPrint(LPRINT_NORMAL, "This is mcabber version %s.", PACKAGE_VERSION);
1858 } 1865 }
1859 1866
1867 static void do_request(char *arg)
1868 {
1869 char **paramlst;
1870 char *jid, *type;
1871 enum iqreq_type numtype;
1872
1873 paramlst = split_arg(arg, 2, 0); // type, jid
1874 type = *paramlst;
1875 jid = *(paramlst+1);
1876
1877 if (type) {
1878 // Quick check...
1879 if (!strcasecmp(type, "version"))
1880 numtype = iqreq_version;
1881 else if (!strcasecmp(type, "time"))
1882 numtype = iqreq_time;
1883 }
1884
1885 if (!type || !numtype) {
1886 scr_LogPrint(LPRINT_NORMAL,
1887 "Please specify a query type (version, time).");
1888 free_arg_lst(paramlst);
1889 return;
1890 }
1891
1892 // Allow special jid "" or "." (current buddy)
1893 if (jid && (!*jid || !strcmp(jid, ".")))
1894 jid = NULL;
1895
1896 if (jid) {
1897 // The JID has been specified. Quick check...
1898 if (check_jid_syntax(jid)) {
1899 scr_LogPrint(LPRINT_NORMAL, "<%s> is not a valid Jabber ID.", jid);
1900 jid = NULL;
1901 } else {
1902 // Convert jid to lowercase
1903 char *p = jid;
1904 for ( ; *p && *p != '/'; p++)
1905 *p = tolower(*p);
1906 }
1907 } else {
1908 // Add the current buddy
1909 if (current_buddy)
1910 jid = (char*)buddy_getjid(BUDDATA(current_buddy));
1911 if (!jid)
1912 scr_LogPrint(LPRINT_NORMAL, "Please specify a Jabber ID.");
1913 }
1914
1915 if (jid) {
1916 switch (numtype) {
1917 case iqreq_version:
1918 case iqreq_time:
1919 jb_request(jid, numtype);
1920 break;
1921 default:
1922 break;
1923 }
1924 }
1925 free_arg_lst(paramlst);
1926 }
1927
1860 static void do_connect(char *arg) 1928 static void do_connect(char *arg)
1861 { 1929 {
1862 mcabber_connect(); 1930 mcabber_connect();
1863 } 1931 }
1864 1932