123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- /*
- ============================================================================
- Name : generate_paging_conf.sh
- Author : ssc
- Version : v1.0
- Copyright : ZYCOO copyright
- Description : Generate paging info from mysql to paging conf file
- ============================================================================
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <errno.h>
- #include <assert.h>
- #include <time.h>
- #include <ctype.h>
- // #include <mysql/mysql.h>
- // MYSQL *g_conn; // mysql 连接
- // MYSQL_RES *g_res; // mysql group记录集
- // MYSQL_ROW g_row; // 字符串数组,mysql 记录行
- // MYSQL_RES *d_res; // mysql device记录集
- // MYSQL_ROW d_row; // 字符串数组,mysql 记录行
- #define MAX_TRUNK_SIZE 256
- #define MAX_SIZE 5120
- #define MIDLE_SIZE 512
- #define MINI_SIZE 64
- #define KEYVALLEN 100
- #define VERSION "V1.0.1"
- // char g_host_name[MINI_SIZE];
- // char g_user_name[MINI_SIZE];
- // char g_password[MINI_SIZE];
- // char g_db_name[MINI_SIZE];
- // const unsigned int g_db_port = 3306;
- // char sql_tmp[MIDLE_SIZE];
- // char * mytime(){
- // time_t my_time;
- // time(&my_time);
- // char *time_string = ctime(&my_time);
- // if (time_string[strlen(time_string) - 1] == '\n')
- // {
- // time_string[strlen(time_string) - 1] = '\0';
- // }
- // return time_string;
- // }
- // void print_mysql_error(const char *msg) { // 打印最后一次错误
- // if (msg)
- // printf("%s: %s\n", msg, mysql_error(g_conn));
- // else
- // puts(mysql_error(g_conn));
- // }
- // int executesql(const char * sql) {
- // /*query the database according the sql*/
- // if (mysql_real_query(g_conn, sql, strlen(sql))) // 如果失败
- // return -1; // 表示失败
- // return 0; // 成功执行
- // }
- // int init_mysql() { // 初始化连接
- // // init the database connection
- // g_conn = mysql_init(NULL);
- // /* connect the database */
- // if(!mysql_real_connect(g_conn, g_host_name, g_user_name, g_password, g_db_name, g_db_port, NULL, 0)) // 如果失败
- // return -1;
- // // 是否连接已经可用
- // if (executesql("set names utf8")) // 如果失败
- // return -1;
- // return 0; // 返回成功
- // }
- int main(int argc, char **argv) {
- char confno[36], callfile[64], cmd[128];
- char *exten;
- // memset(g_host_name, 0, sizeof(g_host_name));
- // memset(g_user_name, 0, sizeof(g_user_name));
- // memset(g_password, 0, sizeof(g_password));
- // memset(g_db_name, 0, sizeof(g_db_name));
- // strcpy(g_host_name,getenv("MYSQL"));
- // strcpy(g_user_name,getenv("MYSQL_USER"));
- // strcpy(g_password,getenv("MYSQL_PASSWORD"));
- // strcpy(g_db_name,getenv("MYSQL_DATABASE"));
- // if (init_mysql()){
- // print_mysql_error(NULL);
- // exit(1);
- // }
- strcpy(confno, argv[1]);
- exten = strtok(argv[3], "|");
- while (exten != NULL)
- {
- // sprintf(sql_tmp, "SELECT user_id FROM t_paging_devices WHERE exten='%s'", exten);
- // if (executesql(sql_tmp)){
- // print_mysql_error(NULL);
- // exit(1);
- // }
- // g_res = mysql_store_result(g_conn); // 从服务器传送结果集至本地,mysql_use_result直接使用服务器上的记录集
- // g_row=mysql_fetch_row(g_res);
- // if (g_row && g_row[0] != NULL){
- // strcpy(mark, "yes");
- // }
- // else
- // {
- // strcpy(mark, "no");
- // }
- memset(callfile, 0, sizeof(callfile));
- sprintf(callfile, "/tmp/meetme-%s-%s.call", confno, exten);
- FILE *callfile_fp = fopen(callfile, "w+");
- fprintf(callfile_fp, "\
- Channel: Local/%s@phones-group-%s\n\
- Context: join-dynamic-meetme\n\
- Extension: s\n\
- Priority: 1\n\
- Callerid: %s\n\
- MaxRetries: 30\n\
- RetryTime: 10\n\
- Setvar: CONFNO=%s\n\
- Setvar: DEST=%s\n\
- Setvar: alarmCall=no\n\
- WaitTime: 600\n\
- \n", \
- exten,\
- confno,\
- exten,\
- confno,\
- exten\
- );
- fclose(callfile_fp);
- sprintf(cmd, "mv %s /var/spool/asterisk/outgoing/", callfile);
- system(cmd);
- exten = strtok(NULL, "|");
- }
- // mysql_free_result(g_res); // 释放结果集
- // mysql_close(g_conn); // 关闭链接
- return 0;
- }
|