|
|
#include "mux.h"
#include "file.h"
#include "parser.h"
#include "port.h"
#include "main.h"
Go to the source code of this file.
Defines | |
#define | ALARMTIMEOUT 60 |
Functions | |
void | usage () |
void | fake_startup_packet () |
int | read_in_description_file () |
void | check_live_jwgc_on_event_handler (jwgconn conn, jwgpacket packet) |
void | check_live_jwgc () |
void | jwgc_init () |
void | jabber_init () |
void | jabber_finalize () |
void | run_initprogs () |
int | main (int argc, char **argv) |
Variables | |
jabconn | jab_c = NULL |
jwgconn | jwg_c = NULL |
time_t | jab_connect_time = 0 |
int | jwgc_register = 0 |
int | jab_reauth = 0 |
char * | whoami = NULL |
char * | progname = NULL |
char * | description_filename_override = NULL |
_Node * | program = NULL |
char * | current_presence = "available" |
char * | barebones_desc |
|
Definition at line 7 of file main.c. Referenced by jabber_init(), and main(). |
|
Definition at line 119 of file main.c. References check_live_jwgc_on_event_handler(), dExecution, dprintf(), jwg_event_handler(), jwg_getfd(), jwg_new(), jwg_poll(), jwg_send(), jwg_start(), jwg_stop(), jwgconn, xode, xode_free(), and xode_new(). Referenced by main(). 00120 { 00121 jwgconn checkjwg; 00122 xode x; 00123 00124 checkjwg = jwg_new(); 00125 if (!checkjwg) { 00126 dprintf(dExecution, "check_live_jwgc: failed to initialize jwgc connection\n"); 00127 return; 00128 } 00129 00130 jwg_event_handler(checkjwg, check_live_jwgc_on_event_handler); 00131 jwg_start(checkjwg); 00132 if (jwg_getfd(checkjwg) < 0) { 00133 dprintf(dExecution, "check_live_jwgc: failed to create jwgc connection\n"); 00134 return; 00135 } 00136 00137 x = xode_new("check"); 00138 jwg_send(checkjwg, x); 00139 xode_free(x); 00140 00141 jwg_poll(checkjwg, -1); 00142 jwg_stop(checkjwg); 00143 }
|
|
Definition at line 112 of file main.c. References jwgconn, and jwgpacket. Referenced by check_live_jwgc(). 00113 {
00114 fprintf(stderr, "There is already an active jwgc running! Exiting...\n");
00115 exit(0);
00116 }
|
|
Definition at line 68 of file main.c. References jab_c, jab_send(), jabutil_msgnew(), jVarJID, jVars_get(), NULL, xode, and xode_free(). Referenced by read_in_description_file(). 00069 { 00070 xode fake; 00071 00072 fake = jabutil_msgnew("internal", 00073 (char *)jVars_get(jVarJID), 00074 "startup", 00075 "Jabber Windowgram Client Started...", 00076 NULL); 00077 jab_send(jab_c, fake); 00078 xode_free(fake); 00079 }
|
|
Definition at line 199 of file main.c. References jab_c, jab_stop(), JCleanupSocket(), jwg_c, and jwg_stop(). Referenced by main(). 00200 { 00201 jab_stop(jab_c); 00202 jwg_stop(jwg_c); 00203 JCleanupSocket(); 00204 }
|
|
Definition at line 163 of file main.c. References ALARMTIMEOUT, dExecution, dprintf(), jab_auth(), jab_c, jab_connect_time, jab_getfd(), jab_new(), jab_on_packet_handler(), jab_on_state_handler(), jab_packet_handler(), jab_reauth, jab_recv(), jab_reg(), jab_start(), jab_startup(), jab_state_handler(), jVarJID, jVarPassword, jVarPort, jVars_get(), jwgc_register, mux_add_input_source(), jabconn_struct::port, and jabconn_struct::state. Referenced by main(). 00164 { 00165 jab_reauth = 0; 00166 jab_c = jab_new((char *)jVars_get(jVarJID), (char *)jVars_get(jVarPassword)); 00167 if (!jab_c) { 00168 fprintf(stderr, "jwgc: unable to create jabber connection.\n"); 00169 exit(1); 00170 } 00171 jab_c->port = *(int *)jVars_get(jVarPort); 00172 jab_packet_handler(jab_c, jab_on_packet_handler); 00173 jab_state_handler(jab_c, jab_on_state_handler); 00174 jab_start(jab_c, 00175 #ifdef USE_SSL 00176 *(int *) jVars_get(jVarUseSSL) 00177 #else /* USE_SSL */ 00178 0 00179 #endif /* USE_SSL */ 00180 ); 00181 if (jwgc_register) { 00182 dprintf(dExecution, "Registering user...\n"); 00183 jab_reg(jab_c); 00184 jwgc_register = 0; 00185 } 00186 jab_auth(jab_c); 00187 if (jab_c->state == JABCONN_STATE_OFF) { 00188 fprintf(stderr, "Unable to connect to jabber server. Retrying in %d seconds.\n", ALARMTIMEOUT); 00189 jab_reauth = 1; 00190 return; 00191 } 00192 mux_add_input_source(jab_getfd(jab_c), jab_recv, jab_c); 00193 00194 jab_startup(jab_c); 00195 jab_connect_time = time(0); 00196 }
|
|
Definition at line 146 of file main.c. References jwg_c, jwg_event_handler(), jwg_getfd(), jwg_on_event_handler(), jwg_server(), jwg_servrecv(), jwg_servstart(), and mux_add_input_source(). Referenced by main(). 00147 { 00148 jwg_c = jwg_server(); 00149 if (!jwg_c) { 00150 fprintf(stderr, "jwgc: unable to initialize jwgc connection.\n"); 00151 exit(1); 00152 } 00153 jwg_event_handler(jwg_c, jwg_on_event_handler); 00154 jwg_servstart(jwg_c); 00155 if (jwg_getfd(jwg_c) < 0) { 00156 fprintf(stderr, "jwgc: unable to create jwgc connection.\n"); 00157 exit(1); 00158 } 00159 mux_add_input_source(jwg_getfd(jwg_c), jwg_servrecv, jwg_c); 00160 }
|
|
Definition at line 412 of file main.c. References ALARMTIMEOUT, check_live_jwgc(), DEFSSLPORT, description_filename_override, dExecution, dinit(), dparseflags(), dprintf(), dprinttypes(), init_ports(), init_standard_ports(), jabber_finalize(), jabber_init(), jVarJID, jVarPassword, jVarPort, jVarPriority, jVarResource, jVars_get(), jVars_init(), jVars_set(), jVars_set_defaults_handler(), jVarServer, jVarUsername, jwg_set_defaults_handler(), jwgc_init(), jwgc_register, mux_init(), mux_loop(), progname, read_in_description_file(), run_initprogs(), snprintf, string_Eq, usage(), var_clear_all_variables(), and whoami. 00415 { 00416 extern char *optarg; 00417 extern int optind; 00418 char prompt[256]; 00419 char **new; 00420 register char **current; 00421 int dofork = 1; 00422 int portset = 0; 00423 00424 whoami = argv[0]; 00425 progname = argv[0]; 00426 #ifndef NODEBUG 00427 dinit(); 00428 for (new = current = argv + 1; *current; current++) { 00429 if (string_Eq(*current, "-debug")) { 00430 argc -= 2; 00431 current++; 00432 if (!*current) 00433 dprinttypes(); 00434 dparseflags(*current); 00435 } 00436 } 00437 #endif /* NODEBUG */ 00438 jVars_set_defaults_handler(jwg_set_defaults_handler); 00439 jVars_init(); 00440 00441 for (new = current = argv + 1; *current; current++) { 00442 if (string_Eq(*current, "-h") || 00443 string_Eq(*current, "-help")) { 00444 usage(); 00445 } 00446 #ifndef NODEBUG 00447 else if (string_Eq(*current, "-debug")) { 00448 argc -= 2; 00449 current++; 00450 /* we already checked this above */ 00451 } 00452 #endif /* NODEBUG */ 00453 else if (string_Eq(*current, "-f") || 00454 string_Eq(*current, "-descfile")) { 00455 argc -= 2; 00456 current++; 00457 if (!*current) 00458 usage(); 00459 description_filename_override = *current; 00460 } 00461 else if (string_Eq(*current, "-j") || 00462 string_Eq(*current, "-jid")) { 00463 argc -= 2; 00464 current++; 00465 if (!*current) 00466 usage(); 00467 jVars_set(jVarJID, *current); 00468 } 00469 else if (string_Eq(*current, "-port")) { 00470 argc -= 2; 00471 current++; 00472 if (!*current) 00473 usage(); 00474 jVars_set(jVarPort, *current); 00475 portset = 1; 00476 } 00477 else if (string_Eq(*current, "-priority")) { 00478 argc -= 2; 00479 current++; 00480 if (!*current) 00481 usage(); 00482 jVars_set(jVarPriority, *current); 00483 } 00484 else if (string_Eq(*current, "-nofork")) { 00485 argc--; 00486 dofork = 0; 00487 } 00488 else if (string_Eq(*current, "-register")) { 00489 argc--; 00490 jwgc_register = 1; 00491 } 00492 #ifdef USE_SSL 00493 else if (string_Eq(*current, "-ssl")) { 00494 argc--; 00495 jVars_set(jVarUseSSL, "1"); 00496 } 00497 else if (string_Eq(*current, "-nossl")) { 00498 argc--; 00499 jVars_set(jVarUseSSL, "0"); 00500 } 00501 #endif /* USE_SSL */ 00502 #ifdef USE_GPGME 00503 else if (string_Eq(*current, "-gpg")) { 00504 argc--; 00505 jVars_set(jVarUseGPG, "1"); 00506 } 00507 else if (string_Eq(*current, "-nogpg")) { 00508 argc--; 00509 jVars_set(jVarUseGPG, "0"); 00510 } 00511 else if (string_Eq(*current, "-gpgpass")) { 00512 argc -= 2; 00513 current++; 00514 if (!*current) 00515 usage(); 00516 jVars_set(jVarGPGPass, *current); 00517 } 00518 #endif /* USE_GPGME */ 00519 else if (string_Eq(*current, "-u") || 00520 string_Eq(*current, "-username")) { 00521 argc -= 2; 00522 current++; 00523 if (!*current) 00524 usage(); 00525 jVars_set(jVarUsername, *current); 00526 } 00527 else if (string_Eq(*current, "-s") || 00528 string_Eq(*current, "-server")) { 00529 argc -= 2; 00530 current++; 00531 if (!*current) 00532 usage(); 00533 jVars_set(jVarServer, *current); 00534 } 00535 else if (string_Eq(*current, "-r") || 00536 string_Eq(*current, "-resource")) { 00537 argc -= 2; 00538 current++; 00539 if (!*current) 00540 usage(); 00541 jVars_set(jVarResource, *current); 00542 } 00543 else if (string_Eq(*current, "-p") || 00544 string_Eq(*current, "-password")) { 00545 argc -= 2; 00546 current++; 00547 if (!*current) 00548 usage(); 00549 jVars_set(jVarPassword, *current); 00550 } 00551 else 00552 *(new)++ = *current; 00553 } 00554 *new = *current; 00555 00556 #ifdef USE_SSL 00557 if (!portset && *(int *)jVars_get(jVarUseSSL)) { 00558 jVars_set(jVarPort, DEFSSLPORT); 00559 } 00560 #endif /* USE_SSL */ 00561 00562 if (jVars_get(jVarUsername) == NULL) { 00563 if (!jVars_set(jVarUsername, getlogin())) { 00564 printf("No username specified.\n"); 00565 exit(0); 00566 } 00567 } 00568 00569 if (jVars_get(jVarPassword) == NULL) { 00570 snprintf(prompt, 255, "Password for %s@%s:", 00571 (char *)jVars_get(jVarUsername), 00572 (char *)jVars_get(jVarServer)); 00573 #ifdef HAVE_GETPASSPHRASE 00574 if (!jVars_set(jVarPassword, getpassphrase(prompt))) { 00575 #else 00576 if (!jVars_set(jVarPassword, getpass(prompt))) { 00577 #endif 00578 printf("No password specified.\n"); 00579 exit(0); 00580 } 00581 } 00582 00583 mux_init(); 00584 var_clear_all_variables(); 00585 init_ports(); 00586 dprintf(dExecution, "Initializing standard ports...\n"); 00587 init_standard_ports(&argc, argv); 00588 if (argc > 1) 00589 usage(); 00590 check_live_jwgc(); 00591 setup_signals(dofork); 00592 00593 if (!jVars_get(jVarJID)) { 00594 char *jwgcjid; 00595 dprintf(dExecution, "Creating JID...\n"); 00596 jwgcjid = (char *) malloc(sizeof(char) * 00597 (strlen((char *)jVars_get(jVarUsername)) 00598 + strlen((char *)jVars_get(jVarServer)) 00599 + strlen((char *)jVars_get(jVarResource)) + 3)); 00600 sprintf(jwgcjid, "%s@%s/%s", 00601 (char *)jVars_get(jVarUsername), 00602 (char *)jVars_get(jVarServer), 00603 (char *)jVars_get(jVarResource)); 00604 dprintf(dExecution, "JID = %s\n", jwgcjid ? jwgcjid : "n/a"); 00605 jVars_set(jVarJID, jwgcjid); 00606 free(jwgcjid); 00607 } 00608 else { 00609 dprintf(dExecution, "JID already set to %s.\n", 00610 (char *)jVars_get(jVarJID)); 00611 } 00612 jwgc_init(); 00613 jabber_init(); 00614 00615 if (dofork) 00616 detach(); 00617 00618 run_initprogs(); 00619 00620 read_in_description_file(); 00621 00622 alarm(ALARMTIMEOUT); 00623 00624 mux_loop(); 00625 00626 jabber_finalize(); 00627 00628 exit(0); 00629 }
|
|
Definition at line 82 of file main.c. References barebones_desc, DEFDESC, description_filename_override, fake_startup_packet(), locate_file(), parse_buffer(), parse_file(), program, and USRDESC. Referenced by jwg_on_event_handler(), and main(). 00083 { 00084 FILE *input_file; 00085 char *defdesc; 00086 00087 defdesc = (char *)malloc(sizeof(char) * (strlen(DATADIR) + 1 + 00088 strlen(DEFDESC) + 1)); 00089 00090 sprintf(defdesc, "%s/%s", DATADIR, DEFDESC); 00091 input_file = (FILE *) locate_file(description_filename_override, 00092 USRDESC, defdesc); 00093 free(defdesc); 00094 if (input_file) 00095 program = (struct _Node *) parse_file(input_file); 00096 else 00097 program = NULL; 00098 00099 if (program == NULL) 00100 program = (struct _Node *) parse_buffer(barebones_desc); 00101 00102 if (program != NULL) { 00103 fake_startup_packet(); 00104 return 1; 00105 } 00106 else { 00107 return 0; 00108 } 00109 }
|
|
Definition at line 207 of file main.c. References dExecution, dprintf(), jVarInitProgs, jVars_get(), and progname. Referenced by main(). 00208 { 00209 int status; 00210 char *progname = (char *)jVars_get(jVarInitProgs); 00211 00212 if (!progname) 00213 return; 00214 00215 dprintf(dExecution, "Running init program... %s\n", progname); 00216 00217 status = system(progname); 00218 if (status == 127) { 00219 perror("jwgc initprog exec"); 00220 fprintf(stderr, "jwgc initprog of <%s> failed: no shell.\n", 00221 progname); 00222 } 00223 else if (status != -1 && status >> 8) { 00224 perror("jwgc initprog exec"); 00225 fprintf(stderr, "jwgc initprog of <%s> failed with status [%d].\n", 00226 progname, status >> 8); 00227 } 00228 }
|
|
Definition at line 38 of file main.c. References whoami. 00039 { 00040 fprintf(stderr, "\ 00041 Usage: %s [-h] [-f <filename>]\n\ 00042 [-u <username>] [-p <password>]\n\ 00043 [-r <resource>] [-s <server>] [-j <jid>]\n\ 00044 [-port <port>] [-priority <priority>]\n\ 00045 [-ttymode] [-nofork] [-register]\n\ 00046 [-default <driver>] {-disable <driver>}*\n\ 00047 [output driver options]\n\ 00048 ", whoami); 00049 #ifdef USE_GPGME 00050 fprintf(stderr, "\ 00051 [-gpg] [-nogpg] [-gpgpass <password>]\n\ 00052 "); 00053 #endif /* USE_GPGME */ 00054 #ifdef USE_SSL 00055 fprintf(stderr, "\ 00056 [-ssl] [-nossl]\n\ 00057 "); 00058 #endif /* USE_SSL */ 00059 #ifndef NODEBUG 00060 fprintf(stderr, "\ 00061 [-debug <flags>]\n\ 00062 "); 00063 #endif /* NODEBUG */ 00064 exit(1); 00065 }
|
|
Initial value: "\ fields body\n\ print \"@b(Description file is broken! This is a barebones config.)\\n\"\n\ print \"Date: \"+$date+\"\\n\"\n\ print \"Time: \"+$time+\"\\n\"\n\ print \"From: \"+$from+\"\\n\"\n\ print \"Status: \"+$status+\"\\n\"\n\ print \"Show: \"+$show+\"\\n\"\n\ print \"Type: \"+$type+\"\\n\"\n\ print \"Subtype: \"+$subtype+\"\\n\"\n\ print \"Body:\\n\"+$body+\"\\n\"\n\ put\n\ exit\n\ " Definition at line 22 of file main.c. Referenced by read_in_description_file(). |
|
|
|
Definition at line 17 of file main.c. Referenced by main(), and read_in_description_file(). |
|
Definition at line 9 of file main.c. Referenced by fake_startup_packet(), jab_on_state_handler(), jabber_finalize(), jabber_init(), jwg_on_event_handler(), jwgc_change_presence_event_handler(), and show_status(). |
|
Definition at line 11 of file main.c. Referenced by jabber_init(), process_presence(), and show_status(). |
|
Definition at line 13 of file main.c. Referenced by jab_on_state_handler(), and jabber_init(). |
|
Definition at line 10 of file main.c. Referenced by jabber_finalize(), jwg_on_event_handler(), jwgc_init(), and show_status(). |
|
Definition at line 12 of file main.c. Referenced by jabber_init(), and main(). |
|
Definition at line 16 of file main.c. Referenced by init_standard_ports(), main(), and run_initprogs(). |
|
Definition at line 18 of file main.c. Referenced by exec_process_packet(), jab_on_packet_handler(), process_presence(), and read_in_description_file(). |
|
|
Last updated at Tue Dec 18 21:07:42 PST 2007. | This site and project hosted by... |