/* * Asterisk -- A telephony toolkit for Linux. * * JabberPop application -- Does a screen pop over Jabber. * * Copyright (C) 2005 Digium, Inc. * * Matt O'Gorman * * This program is free software, distributed under the terms of * the GNU General Public License * */ #include #include #include #include #include #include #include #include #include #include #include #include #include #define JABBERPOP_CONFIG "jabberpop.conf" static char *tdesc = "The Beginning of intergrating Jabber into Asterisk"; static char *app_jabberpop = "JabberPop"; static char *jabberpop_synopsis = "JabberPop(ScreenName,Message)"; static char *jabberpop_descrip = "JabberPop(ScreenName,Message)\n" " ScreenName - User Name to message.\n" " Message - Message to be sent to the user\n"; STANDARD_LOCAL_USER; LOCAL_USER_DECL; struct jabber_user{ char *host; char *username; char *password; char *senderid; char *prefix; char *suffix; iksid *my_jid; iksparser *p; ikstack *stack; int port; }; struct jabber_user jabuser; static int jabberpop_exec(struct ast_channel *chan, void *data) { /*Send A message over the Jabber protocal*/ if(!jabuser.host){ ast_log(LOG_WARNING, "Host not configured in file %s\n", JABBERPOP_CONFIG); return -1; } char *s=NULL,*recipiant=NULL,*message=NULL,*output=NULL; if (data) { s = ast_strdupa((char *)data); if (s) { recipiant = strsep(&s, "|"); if (recipiant && (recipiant[0] != '\0')) { message = s; } else { ast_log(LOG_ERROR, "Bad arguments\n"); return -1; } } }else{ ast_log(LOG_ERROR, "Out of memory\n"); return -1; } output = (char *)malloc((strlen(jabuser.prefix)+strlen(jabuser.suffix)+strlen(message)+1)*sizeof(char)); sprintf(output,"%s%s%s",jabuser.prefix,message,jabuser.suffix); iks_send(jabuser.p, iks_make_msg(IKS_TYPE_NONE,recipiant,output)); return 0; } static void jabberpop_connect(void) { /* Log onto Jabber */ iks *auth_block; jabuser.stack = iks_stack_new(8192,8192); jabuser.my_jid = iks_id_new(jabuser.stack,jabuser.username); jabuser.p = iks_stream_new ("jabber:client", NULL, 0); iks_set_log_hook(jabuser.p, NULL); iks_connect_tcp(jabuser.p, jabuser.host, jabuser.port); auth_block = iks_make_auth(jabuser.my_jid, jabuser.password, NULL); iks_send(jabuser.p, auth_block); iks_send(jabuser.p, iks_make_pres(IKS_SHOW_AVAILABLE,"Online")); } static void jabberpop_disconnect(void) { /* Logout of Jabber */ iks_disconnect(jabuser.p); iks_parser_delete(jabuser.p); } static int jabberpop_load_config(void) { char *temp; /*Read Jabber Config */ struct ast_config *cfg=NULL; cfg = ast_config_load(JABBERPOP_CONFIG); if (!cfg){ ast_log(LOG_WARNING, "No such configuration file %s\n", JABBERPOP_CONFIG); return -1; } if (!(jabuser.host = ast_variable_retrieve(cfg, "general", "host"))) { ast_log(LOG_WARNING, "Host not configured in file %s\n", JABBERPOP_CONFIG); return -1; } if (!(temp = ast_variable_retrieve(cfg, "general", "port"))) { jabuser.port = 5222; ast_log(LOG_WARNING, "Port not configured in file %s, using 5222\n", JABBERPOP_CONFIG); } else { jabuser.port = atoi(temp); } if (!(jabuser.username = ast_variable_retrieve(cfg, "general", "username"))) { ast_log(LOG_WARNING, "Username not configured in file %s, using asterisk\n", JABBERPOP_CONFIG); } if (!(jabuser.password = ast_variable_retrieve(cfg, "general", "password"))) { ast_log(LOG_WARNING, "Password not configured in file %s, using asterisk\n", JABBERPOP_CONFIG); } if (!(jabuser.prefix = ast_variable_retrieve(cfg, "general", "prefix"))){ jabuser.prefix = ""; } if (!(jabuser.suffix = ast_variable_retrieve(cfg, "general", "suffix"))){ jabuser.suffix = ""; } return 0; } int unload_module(void) { STANDARD_HANGUP_LOCALUSERS; if(!jabuser.host){ ast_log(LOG_WARNING, "Host not configured in file %s\n", JABBERPOP_CONFIG); } else jabberpop_disconnect(); return ast_unregister_application(app_jabberpop); } int load_module(void) { jabberpop_load_config(); if(!jabuser.host){ ast_log(LOG_WARNING, "Host not configured in file %s\n", JABBERPOP_CONFIG); } else jabberpop_connect(); return ast_register_application(app_jabberpop, jabberpop_exec, jabberpop_synopsis, jabberpop_descrip); } char *description(void) { return tdesc; } int usecount(void) { int res; STANDARD_USECOUNT(res); return res; } char *key() { return ASTERISK_GPL_KEY; }