joinmeetme.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. ============================================================================
  3. Name : generate_paging_conf.sh
  4. Author : ssc
  5. Version : v1.0
  6. Copyright : ZYCOO copyright
  7. Description : Generate paging info from mysql to paging conf file
  8. ============================================================================
  9. */
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include <errno.h>
  14. #include <assert.h>
  15. #include <time.h>
  16. #include <ctype.h>
  17. // #include <mysql/mysql.h>
  18. // MYSQL *g_conn; // mysql 连接
  19. // MYSQL_RES *g_res; // mysql group记录集
  20. // MYSQL_ROW g_row; // 字符串数组,mysql 记录行
  21. // MYSQL_RES *d_res; // mysql device记录集
  22. // MYSQL_ROW d_row; // 字符串数组,mysql 记录行
  23. #define MAX_TRUNK_SIZE 256
  24. #define MAX_SIZE 5120
  25. #define MIDLE_SIZE 512
  26. #define MINI_SIZE 64
  27. #define KEYVALLEN 100
  28. #define VERSION "V1.0.1"
  29. // char g_host_name[MINI_SIZE];
  30. // char g_user_name[MINI_SIZE];
  31. // char g_password[MINI_SIZE];
  32. // char g_db_name[MINI_SIZE];
  33. // const unsigned int g_db_port = 3306;
  34. // char sql_tmp[MIDLE_SIZE];
  35. // char * mytime(){
  36. // time_t my_time;
  37. // time(&my_time);
  38. // char *time_string = ctime(&my_time);
  39. // if (time_string[strlen(time_string) - 1] == '\n')
  40. // {
  41. // time_string[strlen(time_string) - 1] = '\0';
  42. // }
  43. // return time_string;
  44. // }
  45. // void print_mysql_error(const char *msg) { // 打印最后一次错误
  46. // if (msg)
  47. // printf("%s: %s\n", msg, mysql_error(g_conn));
  48. // else
  49. // puts(mysql_error(g_conn));
  50. // }
  51. // int executesql(const char * sql) {
  52. // /*query the database according the sql*/
  53. // if (mysql_real_query(g_conn, sql, strlen(sql))) // 如果失败
  54. // return -1; // 表示失败
  55. // return 0; // 成功执行
  56. // }
  57. // int init_mysql() { // 初始化连接
  58. // // init the database connection
  59. // g_conn = mysql_init(NULL);
  60. // /* connect the database */
  61. // if(!mysql_real_connect(g_conn, g_host_name, g_user_name, g_password, g_db_name, g_db_port, NULL, 0)) // 如果失败
  62. // return -1;
  63. // // 是否连接已经可用
  64. // if (executesql("set names utf8")) // 如果失败
  65. // return -1;
  66. // return 0; // 返回成功
  67. // }
  68. int main(int argc, char **argv) {
  69. char confno[36], callfile[64], cmd[128];
  70. char *exten;
  71. // memset(g_host_name, 0, sizeof(g_host_name));
  72. // memset(g_user_name, 0, sizeof(g_user_name));
  73. // memset(g_password, 0, sizeof(g_password));
  74. // memset(g_db_name, 0, sizeof(g_db_name));
  75. // strcpy(g_host_name,getenv("MYSQL"));
  76. // strcpy(g_user_name,getenv("MYSQL_USER"));
  77. // strcpy(g_password,getenv("MYSQL_PASSWORD"));
  78. // strcpy(g_db_name,getenv("MYSQL_DATABASE"));
  79. // if (init_mysql()){
  80. // print_mysql_error(NULL);
  81. // exit(1);
  82. // }
  83. strcpy(confno, argv[1]);
  84. exten = strtok(argv[3], "|");
  85. while (exten != NULL)
  86. {
  87. // sprintf(sql_tmp, "SELECT user_id FROM t_paging_devices WHERE exten='%s'", exten);
  88. // if (executesql(sql_tmp)){
  89. // print_mysql_error(NULL);
  90. // exit(1);
  91. // }
  92. // g_res = mysql_store_result(g_conn); // 从服务器传送结果集至本地,mysql_use_result直接使用服务器上的记录集
  93. // g_row=mysql_fetch_row(g_res);
  94. // if (g_row && g_row[0] != NULL){
  95. // strcpy(mark, "yes");
  96. // }
  97. // else
  98. // {
  99. // strcpy(mark, "no");
  100. // }
  101. memset(callfile, 0, sizeof(callfile));
  102. sprintf(callfile, "/tmp/meetme-%s-%s.call", confno, exten);
  103. FILE *callfile_fp = fopen(callfile, "w+");
  104. fprintf(callfile_fp, "\
  105. Channel: Local/%s@phones-group-%s\n\
  106. Context: join-dynamic-meetme\n\
  107. Extension: s\n\
  108. Priority: 1\n\
  109. Callerid: %s\n\
  110. MaxRetries: 30\n\
  111. RetryTime: 10\n\
  112. Setvar: CONFNO=%s\n\
  113. Setvar: DEST=%s\n\
  114. Setvar: alarmCall=no\n\
  115. WaitTime: 600\n\
  116. \n", \
  117. exten,\
  118. confno,\
  119. exten,\
  120. confno,\
  121. exten\
  122. );
  123. fclose(callfile_fp);
  124. sprintf(cmd, "mv %s /var/spool/asterisk/outgoing/", callfile);
  125. system(cmd);
  126. exten = strtok(NULL, "|");
  127. }
  128. // mysql_free_result(g_res); // 释放结果集
  129. // mysql_close(g_conn); // 关闭链接
  130. return 0;
  131. }