|
|
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/socket.h>
#include <string.h>
#include <libjwgc.h>
Go to the source code of this file.
Defines | |
#define | SLEEP_CNT 10 |
#define | SLEEP_TIME 1 |
#define | SLEEP_CALL sleep |
Functions | |
void | jctl_do_sendrecv (jwgconn j, xode x) |
void | usage () |
void | jctl_on_event_handler (jwgconn conn, jwgpacket packet) |
int | main (int argc, argv) |
Variables | |
char * | whoami |
char * | storedjid |
char * | storedmode |
jwgconn | jwga |
jwgconn | jwgb |
|
|
|
|
|
|
|
Definition at line 143 of file jctl.c. References jctl_on_event_handler(), jwg_event_handler(), jwg_getfd(), jwg_new(), jwg_poll(), jwg_send(), jwg_start(), jwg_stop(), jwgconn, and xode. Referenced by jctl_on_event_handler(), and main(). 00146 { 00147 j = jwg_new(); 00148 if (!j) { 00149 fprintf(stderr, "jctl: failed to initialize jwgc connection\n"); 00150 exit(1); 00151 } 00152 jwg_event_handler(j, jctl_on_event_handler); 00153 jwg_start(j); 00154 if (jwg_getfd(j) < 0) { 00155 fprintf(stderr, "jctl: failed to create jwgc connection\n"); 00156 exit(1); 00157 } 00158 jwg_send(j, x); 00159 jwg_poll(j, -1); 00160 jwg_stop(j); 00161 }
|
|
Definition at line 67 of file jctl.c. References dExecution, dprintf(), jctl_do_sendrecv(), JDisplayForm(), JFormHandler(), jwgb, jwgconn, jwgpacket, storedjid, storedmode, jwgpacket_struct::x, xode, xode_free(), xode_get_attrib(), xode_get_data(), xode_get_name(), xode_get_tag(), xode_insert_node(), xode_new(), xode_put_attrib(), and xode_to_prettystr(). Referenced by jctl_do_sendrecv(). 00070 { 00071 xode x; 00072 char *cdata; 00073 00074 x = packet->x; 00075 cdata = xode_get_data(x); 00076 00077 if (!strcmp(xode_get_name(x), "iq")) { 00078 xode query, form, error, xtag; 00079 char *type; 00080 00081 00082 error = xode_get_tag(x, "error"); 00083 if (error) { 00084 char *errormsg = xode_get_data(error); 00085 if (errormsg) { 00086 printf("ERROR: %s\n", errormsg); 00087 } 00088 return; 00089 } 00090 00091 query = xode_get_tag(x, "query"); 00092 if (query) { 00093 xtag = xode_get_tag(query, "x"); 00094 if (xtag) { 00095 type = xode_get_attrib(xtag, "type"); 00096 if (type) { 00097 if (!strcmp(type, "result")) { 00098 JDisplayForm(query); 00099 return; 00100 } 00101 } 00102 } 00103 00104 form = JFormHandler(query); 00105 if (form) { 00106 xode ret; 00107 00108 dprintf(dExecution, "Returned form is:\n%s\n", 00109 xode_to_prettystr(form)); 00110 00111 ret = xode_new(storedmode); 00112 xode_put_attrib(ret, "jid", storedjid); 00113 xode_insert_node(ret, form); 00114 00115 jctl_do_sendrecv(jwgb, ret); 00116 xode_free(ret); 00117 } 00118 else { 00119 printf("Form cancelled.\n"); 00120 } 00121 return; 00122 } 00123 else { 00124 printf("Unknown response from server.\n"); 00125 return; 00126 } 00127 } 00128 else if (!strcmp(xode_get_name(x), "success")) { 00129 printf("%s\n", cdata); 00130 return; 00131 } 00132 else if (!strcmp(xode_get_name(x), "error")) { 00133 printf("ERROR: %s\n", cdata); 00134 return; 00135 } 00136 else { 00137 printf("Unknown response from server.\n"); 00138 return; 00139 } 00140 }
|
|
Definition at line 164 of file jctl.c. References dinit(), dparseflags(), dprinttypes(), jctl_do_sendrecv(), jwga, storedjid, storedmode, usage(), whoami, xode, xode_free(), xode_insert_cdata(), xode_insert_tag(), xode_new(), and xode_put_attrib(). 00167 { 00168 int arg; 00169 char *setting; 00170 xode x, y; 00171 00172 whoami = argv[0]; 00173 dinit(); 00174 00175 arg = 1; 00176 00177 if (argc < 2) { 00178 usage(); 00179 } 00180 00181 for (; arg < argc; arg++) { 00182 if (*argv[arg] != '-') { 00183 if (!strcmp(argv[arg], "help")) { 00184 usage(); 00185 } 00186 else if (!strcmp(argv[arg], "shutdown")) { 00187 x = xode_new("shutdown"); 00188 continue; 00189 } 00190 else if (!strcmp(argv[arg], "reread")) { 00191 x = xode_new("reread"); 00192 continue; 00193 } 00194 else if (!strcmp(argv[arg], "nickname")) { 00195 if ((arg + 3) > argc) { 00196 usage(); 00197 } 00198 x = xode_new("nickname"); 00199 xode_put_attrib(x, "jid", argv[++arg]); 00200 if ((arg + 2) <= argc) { 00201 xode_put_attrib(x, "nick", argv[++arg]); 00202 } 00203 else { 00204 xode_put_attrib(x, "nick", ""); 00205 } 00206 continue; 00207 } 00208 else if (!strcmp(argv[arg], "group")) { 00209 if ((arg + 3) > argc) { 00210 usage(); 00211 } 00212 x = xode_new("group"); 00213 xode_put_attrib(x, "jid", argv[++arg]); 00214 if ((arg + 2) <= argc) { 00215 xode_put_attrib(x, "group", argv[++arg]); 00216 } 00217 else { 00218 xode_put_attrib(x, "group", ""); 00219 } 00220 continue; 00221 } 00222 else if (!strcmp(argv[arg], "subscribe")) { 00223 if ((arg + 2) > argc) { 00224 usage(); 00225 } 00226 x = xode_new("subscribe"); 00227 xode_put_attrib(x, "jid", argv[++arg]); 00228 continue; 00229 } 00230 else if (!strcmp(argv[arg], "unsubscribe")) { 00231 if ((arg + 2) > argc) { 00232 usage(); 00233 } 00234 x = xode_new("unsubscribe"); 00235 xode_put_attrib(x, "jid", argv[++arg]); 00236 continue; 00237 } 00238 else if (!strcmp(argv[arg], "set")) { 00239 if ((arg + 3) > argc) { 00240 usage(); 00241 } 00242 x = xode_new("setvar"); 00243 xode_put_attrib(x, "var", argv[++arg]); 00244 setting = argv[++arg]; 00245 xode_insert_cdata(x, setting, strlen(setting)); 00246 continue; 00247 } 00248 else if (!strcmp(argv[arg], "show")) { 00249 if ((arg + 2) > argc) { 00250 usage(); 00251 } 00252 x = xode_new("showvar"); 00253 xode_put_attrib(x, "var", argv[++arg]); 00254 continue; 00255 } 00256 else if (!strcmp(argv[arg], "register")) { 00257 if ((arg + 2) > argc) { 00258 usage(); 00259 } 00260 x = xode_new("register"); 00261 xode_put_attrib(x, "jid", argv[++arg]); 00262 storedjid = argv[arg]; 00263 storedmode = "register"; 00264 continue; 00265 } 00266 else if (!strcmp(argv[arg], "search")) { 00267 if ((arg + 2) > argc) { 00268 usage(); 00269 } 00270 x = xode_new("search"); 00271 xode_put_attrib(x, "jid", argv[++arg]); 00272 storedjid = argv[arg]; 00273 storedmode = "search"; 00274 continue; 00275 } 00276 else if (!strcmp(argv[arg], "join")) { 00277 if ((arg + 2) > argc) { 00278 usage(); 00279 } 00280 x = xode_new("join"); 00281 xode_put_attrib(x, "room", argv[++arg]); 00282 continue; 00283 } 00284 else if (!strcmp(argv[arg], "leave")) { 00285 if ((arg + 2) > argc) { 00286 usage(); 00287 } 00288 x = xode_new("leave"); 00289 xode_put_attrib(x, "room", argv[++arg]); 00290 continue; 00291 } 00292 #ifndef NODEBUG 00293 else if (!strcmp(argv[arg], "debug")) { 00294 if ((arg + 2) > argc) { 00295 usage(); 00296 } 00297 x = xode_new("debug"); 00298 y = xode_insert_tag(x, "debugflags"); 00299 setting = argv[++arg]; 00300 xode_insert_cdata(y, setting, strlen(setting)); 00301 continue; 00302 } 00303 #endif /* NODEBUG */ 00304 else { 00305 fprintf(stderr, "Unknown command: %s\n", 00306 argv[arg]); 00307 usage(); 00308 } 00309 } 00310 switch (argv[arg][1]) { 00311 case 'd': 00312 arg++; 00313 if (arg >= argc) { 00314 dprinttypes(); 00315 } 00316 dparseflags(argv[arg]); 00317 break; 00318 case 'h': 00319 usage(); 00320 break; 00321 default: 00322 fprintf(stderr, "Unknown option: %s\n", 00323 argv[arg]); 00324 usage(); 00325 } 00326 } 00327 00328 jctl_do_sendrecv(jwga, x); 00329 xode_free(x); 00330 00331 exit(0); 00332 }
|
|
Definition at line 28 of file jctl.c. Referenced by display_init(), init_standard_ports(), and main(). 00029 { 00030 fprintf(stderr, "Usage: %s %s[-h] command <args...>\n%s\ 00031 -h Display help\n\ 00032 \n\ 00033 Commands:\n\ 00034 help Display help\n\ 00035 reread Reread description file (.jwgc.desc)\n\ 00036 subscribe <jid> Subscribe to <jid>'s presence\n\ 00037 unsubscribe <jid> Unsubscribe from <jid>'s presence\n\ 00038 nickname <jid> <nick> Sets a nickname <nick> on <jid>\n\ 00039 group <jid> <group> Sets a group <group> on <jid>\n\ 00040 set <var> <setting> Set variable <var> to <setting>\n\ 00041 show <var> Show variable setting of <var>\n\ 00042 shutdown Log off of jabber server and shut down jwgc\n\ 00043 join <chatroom jid> Join a jabber groupchat room\n\ 00044 leave <chatroom jid> Leave a jabber groupchat room\n\ 00045 register <jid> Register with agent <jid>\n\ 00046 search <jid> Search with agent <jid>\n%s\ 00047 \n\ 00048 <nick> in nickname and <group> in group can be left blank to unset a\n\ 00049 nickname or group, respectively.\n\ 00050 ", 00051 whoami, 00052 #ifdef NODEBUG 00053 "", 00054 "", 00055 "" 00056 #else 00057 "[-d <flags>] ", 00058 " -d Enable/Disable debugging (leave <flags> blank for usage)\n", 00059 " debug <debug flags> Modify current debugging flags\n" 00060 #endif /* NODEBUG */ 00061 ); 00062 00063 exit(1); 00064 }
|
|
Definition at line 12 of file jctl.c. Referenced by main(). |
|
Definition at line 13 of file jctl.c. Referenced by jctl_on_event_handler(). |
|
Definition at line 10 of file jctl.c. Referenced by jctl_on_event_handler(), and main(). |
|
Definition at line 11 of file jctl.c. Referenced by jctl_on_event_handler(), and main(). |
|
|
Last updated at Tue Dec 18 21:07:42 PST 2007. | This site and project hosted by... |