⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 siproxd.c

📁 sip proxy
💻 C
📖 第 1 页 / 共 2 页
字号:
/*    Copyright (C) 2002-2007  Thomas Ries <tries@gmx.net>    This file is part of Siproxd.        Siproxd is free software; you can redistribute it and/or modify    it under the terms of the GNU General Public License as published by    the Free Software Foundation; either version 2 of the License, or    (at your option) any later version.        Siproxd is distributed in the hope that it will be useful,    but WITHOUT ANY WARRANTY; without even the implied warranty of    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    GNU General Public License for more details.        You should have received a copy of the GNU General Public License    along with Siproxd; if not, write to the Free Software    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */#include "config.h"#include <stdio.h>#include <errno.h>#include <string.h>#include <stdlib.h>#include <unistd.h>#include <signal.h>#include <netinet/in.h>#include <arpa/inet.h>#ifdef  HAVE_GETOPT_H#include <getopt.h>#endif#include <osipparser2/osip_parser.h>#include "siproxd.h"#include "plugins.h"#include "log.h"static char const ident[]="$Id: siproxd.c,v 1.71 2007/06/08 19:42:10 hb9xar Exp $";/* configuration storage */struct siproxd_config configuration;/* Global File instance on pw file */FILE *siproxd_passwordfile;/* -h help option text */static const char str_helpmsg[] =PACKAGE "-" VERSION "-" BUILDSTR " (c) 2002-2005 Thomas Ries\n""\nUsage: siproxd [options]\n\n""options:\n"#ifdef  HAVE_GETOPT_LONG"       -h, --help                 help\n""       -d, --debug <pattern>      set debug-pattern\n""       -c, --config <cfgfile>     use the specified config file\n""       -p, --pid-file <pidfile>   create pid file <pidfile>\n"#else"       -h              help\n""       -d <pattern>    set debug-pattern\n""       -c <cfgfile>    use the specified config file\n""       -p <pidfile>    create pid file <pidfile>\n"#endif"";/* * module local data */static  int dmalloc_dump=0;static  int exit_program=0;/* * local prototypes */static void sighandler(int sig);int main (int argc, char *argv[]) {   int sts;   int i;   size_t buflen;   int access;   char buff [BUFFER_SIZE];   sip_ticket_t ticket;   extern char *optarg;         /* Defined in libc getopt and unistd.h */   int ch1;      char configfile[64]="siproxd";       /* basename of configfile */   int  config_search=1;                /* search the config file */   int  cmdline_debuglevel=0;   char *pidfilename=NULL;   struct sigaction act;   log_init();   log_set_stderr(1);/* * setup signal handlers */   act.sa_handler=sighandler;   sigemptyset(&act.sa_mask);   act.sa_flags=SA_RESTART;   if (sigaction(SIGTERM, &act, NULL)) {      ERROR("Failed to install SIGTERM handler");   }   if (sigaction(SIGINT, &act, NULL)) {      ERROR("Failed to install SIGINT handler");   }   if (sigaction(SIGUSR2, &act, NULL)) {      ERROR("Failed to install SIGUSR2 handler");   }   if (sigaction(SIGPIPE, &act, NULL)) {      ERROR("Failed to install SIGPIPE handler");   }/* * prepare default configuration */   make_default_config();   log_set_pattern(configuration.debuglevel);/* * parse command line */{#ifdef  HAVE_GETOPT_LONG   int option_index = 0;   static struct option long_options[] = {      {"help", no_argument, NULL, 'h'},      {"config", required_argument, NULL, 'c'},      {"debug", required_argument, NULL, 'd'},      {"pid-file", required_argument, NULL,'p'},      {0,0,0,0}   };    while ((ch1 = getopt_long(argc, argv, "hc:d:p:",                  long_options, &option_index)) != -1) {#else   /* ! HAVE_GETOPT_LONG */    while ((ch1 = getopt(argc, argv, "hc:d:p:")) != -1) {#endif      switch (ch1) {      case 'h': /* help */         DEBUGC(DBCLASS_CONFIG,"option: help");         fprintf(stderr,str_helpmsg);         exit(0);         break;      case 'c': /* load config file */         DEBUGC(DBCLASS_CONFIG,"option: config file=%s",optarg);         i=sizeof(configfile)-1;         strncpy(configfile,optarg,i);         configfile[i]='\0';         config_search=0;         break;       case 'd': /* set debug level */         DEBUGC(DBCLASS_CONFIG,"option: set debug level: %s",optarg);         cmdline_debuglevel=atoi(optarg);         log_set_pattern(cmdline_debuglevel);         break;      case 'p':         pidfilename = optarg;         break;      default:         DEBUGC(DBCLASS_CONFIG,"no command line options");         break;       }   }}/* * Init stuff */   INFO(PACKAGE"-"VERSION"-"BUILDSTR" "UNAME" starting up");   /* read the config file */   if (read_config(configfile, config_search) == STS_FAILURE) exit(1);   /* if a debug level > 0 has been given on the commandline use its      value and not what is in the config file */   if (cmdline_debuglevel != 0) {      configuration.debuglevel=cmdline_debuglevel;   }/* * open a the pwfile instance, so we still have access after * we possibly have chroot()ed to somewhere. */   if (configuration.proxy_auth_pwfile) {      siproxd_passwordfile = fopen(configuration.proxy_auth_pwfile, "r");   } else {      siproxd_passwordfile = NULL;   }   /* set debug level as desired */   log_set_pattern(configuration.debuglevel);   log_set_listen_port(configuration.debugport);   /* daemonize if requested to */   if (configuration.daemonize) {      DEBUGC(DBCLASS_CONFIG,"daemonizing");      if (fork()!=0) exit(0);      setsid();      if (fork()!=0) exit(0);      log_set_stderr(0);      INFO("daemonized, pid=%i", getpid());   }   /* prepare for creating PID file */   if (pidfilename == NULL) pidfilename = configuration.pid_file;   /* If going to dive into a chroot jail, create a PID file outside    * the jail, too. However, it will be owned by root and not deleted    * on process termination... */   if (configuration.chrootjail && ((getuid()==0) || (geteuid()==0))) {      if (pidfilename) createpidfile(pidfilename);   }   /* change user and group IDs */   secure_enviroment();   /* write PID file of main thread as changed siproxd user and    * possibly into the chroot jail file tree  */   if (pidfilename) createpidfile(pidfilename);   /* initialize the RTP proxy */   sts=rtpproxy_init();   if (sts != STS_SUCCESS) {      ERROR("unable to initialize RTP proxy - aborting");       exit(1);   }   /* init the oSIP parser */   parser_init();   /* listen for incoming messages */   sts=sipsock_listen();   if (sts == STS_FAILURE) {      /* failure to allocate SIP socket... */      ERROR("unable to bind to SIP listening socket - aborting");       exit(1);   }   /* initialize the registration facility */   register_init();/* * silence the log - if so required... */   log_set_silence(configuration.silence_log);   INFO(PACKAGE"-"VERSION"-"BUILDSTR" "UNAME" started");/***************************** * Main loop *****************************/   while (!exit_program) {      DEBUGC(DBCLASS_BABBLE,"going into sipsock_wait\n");      while (sipsock_wait()<=0) {         /* got no input, here by timeout. do aging */         register_agemap();         /* TCP log: check for a connection */         log_tcp_connect();         /* dump memory stats if requested to do so */         if (dmalloc_dump) {            dmalloc_dump=0;#ifdef DMALLOC            INFO("SIGUSR2 - DMALLOC statistics is dumped");            dmalloc_log_stats();            dmalloc_log_unfreed();#else            INFO("SIGUSR2 - DMALLOC support is not compiled in");#endif         }         if (exit_program) goto exit_prg;      }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -