Explorar o código

- removed implementation of fifo and unixsocket servers from core
(it will be implemented in modules instead)

Jan Janak %!s(int64=20) %!d(string=hai) anos
pai
achega
539283cdd7
Modificáronse 9 ficheiros con 7 adicións e 2391 borrados
  1. 0 18
      cfg.lex
  2. 1 30
      cfg.y
  3. 0 13
      config.h
  4. 0 950
      fifo_server.c
  5. 0 92
      fifo_server.h
  6. 0 11
      globals.h
  7. 6 102
      main.c
  8. 0 1032
      unixsock_server.c
  9. 0 143
      unixsock_server.h

+ 0 - 18
cfg.lex

@@ -227,15 +227,6 @@ CHECK_VIA	check_via
 SYN_BRANCH syn_branch
 SYN_BRANCH syn_branch
 MEMLOG		"memlog"|"mem_log"
 MEMLOG		"memlog"|"mem_log"
 SIP_WARNING sip_warning
 SIP_WARNING sip_warning
-FIFO fifo
-FIFO_DIR  fifo_dir
-SOCK_MODE "fifo_mode"|"sock_mode"|"file_mode"
-SOCK_USER "fifo_user"|"sock_user"
-SOCK_GROUP "fifo_group"|"sock_group"
-FIFO_DB_URL fifo_db_url
-UNIX_SOCK unix_sock
-UNIX_SOCK_CHILDREN unix_sock_children
-UNIX_TX_TIMEOUT unix_tx_timeout
 SERVER_SIGNATURE server_signature
 SERVER_SIGNATURE server_signature
 REPLY_TO_VIA reply_to_via
 REPLY_TO_VIA reply_to_via
 USER		"user"|"uid"
 USER		"user"|"uid"
@@ -460,15 +451,6 @@ EAT_ABLE	[\ \t\b\r]
 										return TLS_HANDSHAKE_TIMEOUT; }
 										return TLS_HANDSHAKE_TIMEOUT; }
 <INITIAL>{TLS_SEND_TIMEOUT}	{ count(); yylval.strval=yytext;
 <INITIAL>{TLS_SEND_TIMEOUT}	{ count(); yylval.strval=yytext;
 										return TLS_SEND_TIMEOUT; }
 										return TLS_SEND_TIMEOUT; }
-<INITIAL>{FIFO}	{ count(); yylval.strval=yytext; return FIFO; }
-<INITIAL>{FIFO_DIR}	{ count(); yylval.strval=yytext; return FIFO_DIR; }
-<INITIAL>{FIFO_DB_URL}	{ count(); yylval.strval=yytext; return FIFO_DB_URL; }
-<INITIAL>{SOCK_MODE}	{ count(); yylval.strval=yytext; return SOCK_MODE; }
-<INITIAL>{SOCK_USER}	{ count(); yylval.strval=yytext; return SOCK_USER; }
-<INITIAL>{SOCK_GROUP}	{ count(); yylval.strval=yytext; return SOCK_GROUP; }
-<INITIAL>{UNIX_SOCK} { count(); yylval.strval=yytext; return UNIX_SOCK; }
-<INITIAL>{UNIX_SOCK_CHILDREN} { count(); yylval.strval=yytext; return UNIX_SOCK_CHILDREN; }
-<INITIAL>{UNIX_TX_TIMEOUT} { count(); yylval.strval=yytext; return UNIX_TX_TIMEOUT; }
 <INITIAL>{SERVER_SIGNATURE}	{ count(); yylval.strval=yytext; return SERVER_SIGNATURE; }
 <INITIAL>{SERVER_SIGNATURE}	{ count(); yylval.strval=yytext; return SERVER_SIGNATURE; }
 <INITIAL>{REPLY_TO_VIA}	{ count(); yylval.strval=yytext; return REPLY_TO_VIA; }
 <INITIAL>{REPLY_TO_VIA}	{ count(); yylval.strval=yytext; return REPLY_TO_VIA; }
 <INITIAL>{ADVERTISED_ADDRESS}	{	count(); yylval.strval=yytext;
 <INITIAL>{ADVERTISED_ADDRESS}	{	count(); yylval.strval=yytext;

+ 1 - 30
cfg.y

@@ -234,15 +234,6 @@ static struct socket_id* mk_listen_id(char*, int, int);
 %token SYN_BRANCH
 %token SYN_BRANCH
 %token MEMLOG
 %token MEMLOG
 %token SIP_WARNING
 %token SIP_WARNING
-%token FIFO
-%token FIFO_DIR
-%token SOCK_MODE
-%token SOCK_USER
-%token SOCK_GROUP
-%token FIFO_DB_URL
-%token UNIX_SOCK
-%token UNIX_SOCK_CHILDREN
-%token UNIX_TX_TIMEOUT
 %token SERVER_SIGNATURE
 %token SERVER_SIGNATURE
 %token REPLY_TO_VIA
 %token REPLY_TO_VIA
 %token LOADMODULE
 %token LOADMODULE
@@ -476,26 +467,6 @@ assign_stm:	DEBUG_V EQUAL NUMBER { debug=$3; }
 		| MEMLOG EQUAL error { yyerror("int value expected"); }
 		| MEMLOG EQUAL error { yyerror("int value expected"); }
 		| SIP_WARNING EQUAL NUMBER { sip_warning=$3; }
 		| SIP_WARNING EQUAL NUMBER { sip_warning=$3; }
 		| SIP_WARNING EQUAL error { yyerror("boolean value expected"); }
 		| SIP_WARNING EQUAL error { yyerror("boolean value expected"); }
-		| FIFO EQUAL STRING { fifo=$3; }
-		| FIFO EQUAL error { yyerror("string value expected"); }
-		| FIFO_DIR EQUAL STRING { fifo_dir=$3; }
-		| FIFO_DIR EQUAL error { yyerror("string value expected"); }
-		| SOCK_MODE EQUAL NUMBER { sock_mode=$3; }
-		| SOCK_MODE EQUAL error { yyerror("int value expected"); }
-		| SOCK_USER EQUAL STRING { sock_user=$3; }
-		| SOCK_USER EQUAL ID     { sock_user=$3; }
-		| SOCK_USER EQUAL error { yyerror("string value expected"); }
-		| SOCK_GROUP EQUAL STRING { sock_group=$3; }
-		| SOCK_GROUP EQUAL ID     { sock_group=$3; }
-		| SOCK_GROUP EQUAL error { yyerror("string value expected"); }
-		| FIFO_DB_URL EQUAL STRING { fifo_db_url=$3; }
-		| FIFO_DB_URL EQUAL error  { yyerror("string value expected"); }
-		| UNIX_SOCK EQUAL STRING { unixsock_name=$3; }
-		| UNIX_SOCK EQUAL error { yyerror("string value expected"); }
-		| UNIX_SOCK_CHILDREN EQUAL NUMBER { unixsock_children=$3; }
-		| UNIX_SOCK_CHILDREN EQUAL error { yyerror("int value expected\n"); }
-		| UNIX_TX_TIMEOUT EQUAL NUMBER { unixsock_tx_timeout=$3; }
-		| UNIX_TX_TIMEOUT EQUAL error { yyerror("int value expected\n"); }
 		| USER EQUAL STRING     { user=$3; }
 		| USER EQUAL STRING     { user=$3; }
 		| USER EQUAL ID         { user=$3; }
 		| USER EQUAL ID         { user=$3; }
 		| USER EQUAL error      { yyerror("string value expected"); }
 		| USER EQUAL error      { yyerror("string value expected"); }
@@ -1354,7 +1325,6 @@ select_params : select_params DOT select_param
 ;
 ;
 
 
 select_id : SELECT_MARK { sel.n = 0; sel.f = 0; } select_params {
 select_id : SELECT_MARK { sel.n = 0; sel.f = 0; } select_params {
-//	if (resolve_select(&sel) < 0) yyerror("Unable to resolve select");
 	sel_ptr = (select_t*)pkg_malloc(sizeof(select_t));
 	sel_ptr = (select_t*)pkg_malloc(sizeof(select_t));
 	if (!sel_ptr) {
 	if (!sel_ptr) {
 		yyerror("No memory left to allocate select structure\n");
 		yyerror("No memory left to allocate select structure\n");
@@ -1364,6 +1334,7 @@ select_id : SELECT_MARK { sel.n = 0; sel.f = 0; } select_params {
 }
 }
 ;
 ;
 
 
+
 attr_id : ATTR_MARK ID { s_attr = (struct avp_spec*)pkg_malloc(sizeof(struct avp_spec));
 attr_id : ATTR_MARK ID { s_attr = (struct avp_spec*)pkg_malloc(sizeof(struct avp_spec));
                          if (!s_attr) { yyerror("No memory left"); }
                          if (!s_attr) { yyerror("No memory left"); }
                          s_attr->type = AVP_NAME_STR;                   
                          s_attr->type = AVP_NAME_STR;                   

+ 0 - 13
config.h

@@ -150,13 +150,6 @@
 /* maximum number of branches per transaction */
 /* maximum number of branches per transaction */
 #define MAX_BRANCHES    12
 #define MAX_BRANCHES    12
 
 
-/* maximum length of a FIFO server command */
-#define MAX_FIFO_COMMAND 512
-
-/* buffer dimensions for FIFO server */
-#define MAX_CONSUME_BUFFER 1024
-/* where reply pipes may be opened */
-#define DEFAULT_FIFO_DIR "/tmp/"
 /* max length of the text of fifo 'print' command */
 /* max length of the text of fifo 'print' command */
 #define MAX_PRINT_TEXT 256
 #define MAX_PRINT_TEXT 256
 
 
@@ -169,12 +162,6 @@
 */
 */
 #define CLEANUP_EOL "      \n"
 #define CLEANUP_EOL "      \n"
 
 
-/* how patient is ser with FIFO clients not awaiting a reply? 
-	4 x 80ms = 0.32 sec
-*/
-#define FIFO_REPLY_RETRIES	4
-#define FIFO_REPLY_WAIT		80000
-
 /* magic cookie for transaction matching as defined in RFC3261 */
 /* magic cookie for transaction matching as defined in RFC3261 */
 #define MCOOKIE "z9hG4bK"
 #define MCOOKIE "z9hG4bK"
 #define MCOOKIE_LEN (sizeof(MCOOKIE)-1)
 #define MCOOKIE_LEN (sizeof(MCOOKIE)-1)

+ 0 - 950
fifo_server.c

@@ -1,950 +0,0 @@
-/*
- * $Id$
- *
- *
- * Copyright (C) 2001-2003 FhG Fokus
- *
- * This file is part of ser, a free SIP server.
- *
- * ser 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
- *
- * For a license to use the ser software under conditions
- * other than those described here, or to purchase support for this
- * software, please contact iptel.org by e-mail at the following addresses:
- *    [email protected]
- *
- * ser 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 this program; if not, write to the Free Software 
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- * Fifo server is a very powerful tool used to access easily
- * ser's internals via textual interface, similarly to
- * how internals of many operating systems are accessible
- * via the proc file system. This might be used for
- * making ser do things for you (such as initiating new
- * transaction from webpages) or inspect server's health.
- * 
- * FIFO server allows new functionality to be registered
- * with it -- thats what register_fifo_cmd is good for.
- * Remember, the initialization must take place before
- * forking; best in init_module functions. When a function
- * is registered, it can be always evoked by sending its
- * name prefixed by colon to the FIFO.
- *
- * There are few commands already implemented in core.
- * These are 'uptime' for looking at how long the server
- * is alive and 'print' for debugging purposes.
- *
- * Every command sent to FIFO must be sent atomically to
- * avoid intermixing with other commands and MUST be
- * terminated by empty line so that the server is to able
- * to find its end if it does not understand the command.
- *
- * File test/transaction.fifo illustrates example of use
- * of t_uac command (part of TM module).
- *
- * History:
- * --------
- *  2003-03-29  destroy pkg mem introduced (jiri)
- *  2003-03-19  replaced all mallocs/frees w/ pkg_malloc/pkg_free (andrei)
- *  2003-01-29  new built-in fifo commands: arg and pwd (jiri)
- *  2003-10-07  fifo security fixes: permissions, always delete old fifo,
- *               reply fifo checks -- added fifo_check (andrei)
- *  2003-10-13  added fifo_dir for reply fifos (andrei)
- *  2003-10-30  DB interface exported via FIFO (bogdan)
- *  2004-03-09  open_fifo_server split into init_ and start_ (andrei)
- *  2004-04-29  added chown(sock_user, sock_group)  (andrei)
- *  2004-06-06  updated to the new DB interface  & init_db_fifo (andrei)
- *  2004-09-19  fifo is deleted on exit (destroy_fifo)  (andrei)
- *  2005-03-02  meminfo fifo cmd added (andrei)
- */
-
-
-#include <limits.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <errno.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <string.h>
-#include <time.h>
-#include <stdarg.h>
-#ifdef USE_TCP
-#include <sys/socket.h>
-#endif
-
-#include "dprint.h"
-#include "ut.h"
-#include "error.h"
-#include "config.h"
-#include "globals.h"
-#include "fifo_server.h"
-#include "mem/mem.h"
-#include "mem/shm_mem.h" /* shm_info() */
-#include "sr_module.h"
-#include "pt.h"
-#include "db/db_fifo.h"
-
-/* FIFO server vars */
-char *fifo=0; /* FIFO name */
-char* fifo_dir=DEFAULT_FIFO_DIR; /* dir where reply fifos are allowed */
-char *fifo_db_url = 0;
-pid_t fifo_pid;
-
-
-/* file descriptors */
-static int fifo_read=0;
-static int fifo_write=0;
-static FILE *fifo_stream=0;
-
-/* list of fifo command */
-static struct fifo_command *cmd_list=0;
-
-/* up time */
-static time_t up_since;
-static char up_since_ctime[MAX_CTIME_LEN];
-
-static struct fifo_command *lookup_fifo_cmd( char *name )
-{
-	struct fifo_command *c;
-	for(c=cmd_list; c; c=c->next) {
-		if (strcasecmp(c->name, name)==0) return c;
-	}
-	return 0;
-}
-
-int register_fifo_cmd(fifo_cmd f, char *cmd_name, void *param)
-{
-	struct fifo_command *new_cmd;
-
-	if (lookup_fifo_cmd(cmd_name)) {
-		LOG(L_ERR, "ERROR: register_fifo_cmd: attempt to register synonyms\n");
-		return E_BUG;
-	}
-	new_cmd=pkg_malloc(sizeof(struct fifo_command));
-	if (new_cmd==0) {
-		LOG(L_ERR, "ERROR: register_fifo_cmd: out of mem\n");
-		return E_OUT_OF_MEM;
-	}
-	new_cmd->f=f;
-	new_cmd->name=cmd_name;
-	new_cmd->param=param;
-
-	new_cmd->next=cmd_list;
-	cmd_list=new_cmd;
-	
-	DBG("DEBUG: register_fifo_cmd: new command (%s) registered\n", cmd_name );
-
-	return 1;
-}
-
-void destroy_fifo()
-{
-	struct fifo_command *c, *foo;
-
-	c=cmd_list;
-
-	while(c) {
-		foo=c->next;
-		pkg_free(c);
-		c=foo;
-	}
-	if (fifo_stream){
-			fclose(fifo_stream);
-			fifo_stream=0;
-		/* if  FIFO was created, delete it */
-		if (fifo && strlen(fifo)){
-			if (unlink(fifo)<0){
-				LOG(L_ERR, "WARNING: destroy_fifo: cannot delete fifo (%s):"
-							" %s\n", fifo, strerror(errno));
-			}
-		}
-	}
-}
-
-
-int read_line( char *b, int max, FILE *stream, int *read )
-{
-	int len;
-	int retry_cnt;
-
-	retry_cnt=0;
-
-retry:
-	if (fgets(b, max, stream)==NULL) {
-		LOG(L_ERR, "ERROR: fifo_server fgets failed: %s\n",
-			strerror(errno));
-		/* on Linux, fgets sometimes returns ESPIPE -- give
-		   it few more chances
-		*/
-		if (errno==ESPIPE) {
-			retry_cnt++;
-			if (retry_cnt<4) goto retry;
-		}
-		/* interrupted by signal or ... */
-		if ((errno==EINTR)||(errno==EAGAIN)) goto retry;
-		kill(0, SIGTERM);
-	}
-	/* if we did not read whole line, our buffer is too small
-	   and we cannot process the request; consume the remainder of 
-	   request
-	*/
-	len=strlen(b);
-	if (len && !(b[len-1]=='\n' || b[len-1]=='\r')) {
-		LOG(L_ERR, "ERROR: read_line: request  line too long\n");
-		return 0;
-	}
-	/* trim from right */
-	while(len) {
-		if(b[len-1]=='\n' || b[len-1]=='\r'
-				|| b[len-1]==' ' || b[len-1]=='\t' ) {
-			len--;
-			b[len]=0;
-		} else break;
-	}
-	*read=len;
-	return 1;
-}
-
-static void consume_request( FILE *stream )
-{
-	int len;
-	char buffer[MAX_CONSUME_BUFFER];
-
-	while(!read_line(buffer, MAX_CONSUME_BUFFER, stream, &len));
-
-}
-
-int read_eol( FILE *stream )
-{
-	int len;
-	char buffer[MAX_CONSUME_BUFFER];
-	if (!read_line(buffer, MAX_CONSUME_BUFFER, stream, &len) || len!=0) {
-		LOG(L_ERR, "ERROR: read_eol: EOL expected: %.10s...\n",
-			buffer );
-		return 0;
-	}
-	return 1;
-}
-
-/* read from input until empty line is encountered */	
-int read_line_set(char *buf, int max_len, FILE *fifo, int *len)
-{
-	int set_len;
-	char *c;
-	int line_len;
-
-	c=buf;set_len=0;
-	while(1) {
-		if (!read_line(c,max_len,fifo,&line_len)) {
-			LOG(L_ERR, "ERROR: fifo_server: line expected\n");
-			return 0;
-		}
-		/* end encountered ... return */
-		if (line_len==0 || (line_len==1 && c[0]=='.' )) {
-			*len=set_len;
-			return 1;
-		}
-		max_len-=line_len; c+=line_len; set_len+=line_len;
-		if (max_len<CRLF_LEN) {
-			LOG(L_ERR, "ERROR: fifo_server: no place for CRLF\n");
-			return 0;
-		}
-		memcpy(c, CRLF, CRLF_LEN);
-		max_len-=CRLF_LEN; c+=CRLF_LEN; set_len+=CRLF_LEN;
-	}
-}
-
-
-/* read from input until line with only dot in it is encountered */
-int read_body(char *buf, int max_len, FILE *fifo, int *len)
-{
-	int set_len;
-	char *c;
-	int line_len;
-
-	c=buf;set_len=0;
-	while(1) {
-		if (!read_line(c,max_len,fifo,&line_len)) {
-			LOG(L_ERR, "ERROR: fifo_server: line expected\n");
-			return 0;
-		}
-		/* end encountered ... return */
-		if (line_len==1 && *c=='.') {
-			*len=set_len;
-			return 1;
-		}
-		max_len-=line_len; c+=line_len; set_len+=line_len;
-		if (max_len<CRLF_LEN) {
-			LOG(L_ERR, "ERROR: fifo_server: no place for CRLF\n");
-			return 0;
-		}
-		memcpy(c, CRLF, CRLF_LEN);
-		max_len-=CRLF_LEN; c+=CRLF_LEN; set_len+=CRLF_LEN;
-	}
-}
-
-static char *trim_filename( char * file )
-{
-	int prefix_len, fn_len;
-	char *new_fn;
-
-	/* we only allow files in "/tmp" -- any directory
-	   changes are not welcome
-	*/
-	if (strchr(file,'.') || strchr(file,'/')
-				|| strchr(file, '\\')) {
-		LOG(L_ERR, "ERROR: trim_filename: forbidden filename: %s\n"
-			, file);
-		return 0;
-	}
-	prefix_len=strlen(fifo_dir); fn_len=strlen(file);
-	new_fn=pkg_malloc(prefix_len+fn_len+1);
-	if (new_fn==0) {
-		LOG(L_ERR, "ERROR: trim_filename: no mem\n");
-		return 0;
-	}
-
-	memcpy(new_fn, fifo_dir, prefix_len);
-	memcpy(new_fn+prefix_len, file, fn_len );
-	new_fn[prefix_len+fn_len]=0;
-
-	return new_fn;
-}
-
-
-
-/* reply fifo security checks:
- * checks if fd is a fifo, is not hardlinked and it's not a softlink
- * opened file descriptor + file name (for soft link check)
- * returns 0 if ok, <0 if not */
-static int fifo_check(int fd, char* fname)
-{
-	struct stat fst;
-	struct stat lst;
-	
-	if (fstat(fd, &fst)<0){
-		LOG(L_ERR, "ERROR: fifo_check: fstat failed: %s\n",
-				strerror(errno));
-		return -1;
-	}
-	/* check if fifo */
-	if (!S_ISFIFO(fst.st_mode)){
-		LOG(L_ERR, "ERROR: fifo_check: %s is not a fifo\n", fname);
-		return -1;
-	}
-	/* check if hard-linked */
-	if (fst.st_nlink>1){
-		LOG(L_ERR, "ERROR: security: fifo_check: %s is hard-linked %d times\n",
-				fname, (unsigned)fst.st_nlink);
-		return -1;
-	}
-	
-	/* lstat to check for soft links */
-	if (lstat(fname, &lst)<0){
-		LOG(L_ERR, "ERROR: fifo_check: lstat failed: %s\n",
-				strerror(errno));
-		return -1;
-	}
-	if (S_ISLNK(lst.st_mode)){
-		LOG(L_ERR, "ERROR: security: fifo_check: %s is a soft link\n",
-				fname);
-		return -1;
-	}
-	/* if this is not a symbolic link, check to see if the inode didn't
-	 * change to avoid possible sym.link, rm sym.link & replace w/ fifo race
-	 */
-	if ((lst.st_dev!=fst.st_dev)||(lst.st_ino!=fst.st_ino)){
-		LOG(L_ERR, "ERROR: security: fifo_check: inode/dev number differ"
-				": %d %d (%s)\n",
-				 (int)fst.st_ino, (int)lst.st_ino, fname);
-		return -1;
-	}
-	/* success */
-	return 0;
-}
-
-
-
-/* tell FIFO client what happened via reply pipe */
-void fifo_reply( char *reply_fifo, char *reply_fmt, ... )
-{
-	FILE *file_handle;
-	int r;
-	va_list ap;
-
-	file_handle=open_reply_pipe(reply_fifo);
-	if (file_handle==0) {
-		LOG(L_ERR, "ERROR: fifo_reply: no reply pipe %s\n",
-			reply_fifo);
-		return;
-	}
-retry:
-	va_start(ap, reply_fmt);
-	r=vfprintf(file_handle, reply_fmt, ap);
-	va_end(ap);
-	if (r<=0) {
-		LOG(L_ERR, "ERROR: fifo_error: write error (%s): %s\n",
-			fifo, strerror(errno));
-		if ((errno==EINTR)||(errno==EAGAIN)||(errno==EWOULDBLOCK)) {
-			goto retry;
-		}
-	}
-	fclose(file_handle);
-}
-
-FILE *open_reply_pipe( char *pipe_name )
-{
-
-	int fifofd;
-	FILE *file_handle;
-	int flags;
-
-	int retries=FIFO_REPLY_RETRIES;
-
-	if (!pipe_name || *pipe_name==0) {
-		DBG("DEBUG: open_reply_pipe: no file to write to about missing cmd\n");
-		return 0;
-	}
-
-tryagain:
-	/* open non-blocking to make sure that a broken client will not 
-	 * block the FIFO server forever */
-	fifofd=open( pipe_name, O_WRONLY | O_NONBLOCK );
-	if (fifofd==-1) {
-		/* retry several times if client is not yet ready for getting
-		   feedback via a reply pipe
-		*/
-		if (errno==ENXIO) {
-			/* give up on the client - we can't afford server blocking */
-			if (retries==0) {
-				LOG(L_ERR, "ERROR: open_reply_pipe: no client at %s\n",
-					pipe_name );
-				return 0;
-			}
-			/* don't be noisy on the very first try */
-			if (retries!=FIFO_REPLY_RETRIES)
-				DBG("DEBUG: open_reply_pipe: retry countdown: %d\n", retries );
-			sleep_us( FIFO_REPLY_WAIT );
-			retries--;
-			goto tryagain;
-		}
-		/* some other opening error */
-		LOG(L_ERR, "ERROR: open_reply_pipe: open error (%s): %s\n",
-			pipe_name, strerror(errno));
-		return 0;
-	}
-	/* security checks: is this really a fifo?, is 
-	 * it hardlinked? is it a soft link? */
-	if (fifo_check(fifofd, pipe_name)<0) goto error;
-	
-	/* we want server blocking for big writes */
-	if ( (flags=fcntl(fifofd, F_GETFL, 0))<0) {
-		LOG(L_ERR, "ERROR: open_reply_pipe (%s): getfl failed: %s\n",
-			pipe_name, strerror(errno));
-		goto error;
-	}
-	flags&=~O_NONBLOCK;
-	if (fcntl(fifofd, F_SETFL, flags)<0) {
-		LOG(L_ERR, "ERROR: open_reply_pipe (%s): setfl cntl failed: %s\n",
-			pipe_name, strerror(errno));
-		goto error;
-	}
-
-	/* create an I/O stream */	
-	file_handle=fdopen( fifofd, "w");
-	if (file_handle==NULL) {
-		LOG(L_ERR, "ERROR: open_reply_pipe: open error (%s): %s\n",
-			pipe_name, strerror(errno));
-		goto error;
-	}
-	return file_handle;
-error:
-	close(fifofd);
-	return 0;
-}
-
-static void fifo_server(FILE *fifo_stream)
-{
-	char buf[MAX_FIFO_COMMAND];
-	int line_len;
-	char *file_sep, *command, *file;
-	struct fifo_command *f;
-
-	file_sep=command=file=0;
-
-	/* register a diagnostic FIFO command */
-	register_core_fifo();
-
-	while(1) {
-
-		/* commands must look this way ':<command>:[filename]' */
-		if (!read_line(buf, MAX_FIFO_COMMAND, fifo_stream, &line_len)) {
-			/* line breaking must have failed -- consume the rest
-			   and proceed to a new request
-			*/
-			LOG(L_ERR, "ERROR: fifo_server: command expected\n");
-			goto consume;
-		}
-		if (line_len==0) {
-			LOG(L_DBG, "INFO: fifo_server: command empty\n");
-			continue;
-		}
-		if (line_len<3) {
-			LOG(L_ERR, "ERROR: fifo_server: command must have at least 3 chars\n");
-			goto consume;
-		}
-		if (*buf!=CMD_SEPARATOR) {
-			LOG(L_ERR, "ERROR: fifo_server: command must begin with %c: %.*s\n", 
-				CMD_SEPARATOR, line_len, buf );
-			goto consume;
-		}
-		command=buf+1;
-		file_sep=strchr(command, CMD_SEPARATOR );
-		if (file_sep==NULL) {
-			LOG(L_ERR, "ERROR: fifo_server: file separator missing\n");
-			goto consume;
-		}
-		if (file_sep==command) {
-			LOG(L_ERR, "ERROR: fifo_server: empty command\n");
-			goto consume;
-		}
-		if (*(file_sep+1)==0) file=NULL; 
-		else {
-			file=file_sep+1;
-			file=trim_filename(file);
-			if (file==0) {
-				LOG(L_ERR, "ERROR: fifo_server: trimming filename\n");
-				goto consume;
-			}
-		}
-		/* make command zero-terminated */
-		*file_sep=0;
-
-		f=lookup_fifo_cmd( command );
-		if (f==0) {
-			LOG(L_ERR, "ERROR: fifo_server: command %s is not available\n",
-				command);
-			fifo_reply(file, "500 command '%s' not available\n", command);
-			goto consume;
-		}
-		if (f->f(fifo_stream, file)<0) {
-			LOG(L_ERR, "ERROR: fifo_server: command (%s) "
-				"processing failed\n", command );
-			goto consume;
-		}
-
-consume:
-		if (file) { pkg_free(file); file=0;}
-		consume_request(fifo_stream);
-		DBG("**** done consume\n");
-	}
-}
-
-int init_fifo_server()
-{
-	char *t;
-	struct stat filestat;
-	int n;
-	long opt;
-
-	if (fifo==NULL) {
-		DBG("DBG: open_fifo_server: no fifo will be opened\n");
-		/* everything is ok, we just do not want to start */
-		return 1;
-	}
-	if (strlen(fifo)==0) {
-		DBG("DBG: open_fifo_server: fifo disabled\n");
-		return 1;
-	}
-	DBG("DBG: open_uac_fifo: opening fifo...\n");
-	n=stat(fifo, &filestat);
-	if (n==0){
-		/* FIFO exist, delete it (safer) */
-		if (unlink(fifo)<0){
-			LOG(L_ERR, "ERROR: open_fifo_server: cannot delete old fifo (%s):"
-					" %s\n", fifo, strerror(errno));
-			return -1;
-		}
-	}else if (n<0 && errno!=ENOENT){
-		LOG(L_DBG, "DEBUG: open_fifo_server: FIFO stat failed: %s\n",
-			strerror(errno));
-	}
-		/* create FIFO ... */
-		if ((mkfifo(fifo, sock_mode)<0)) {
-			LOG(L_ERR, "ERROR: open_fifo_server; can't create FIFO: "
-					"%s (mode=%d)\n",
-					strerror(errno), sock_mode);
-			return -1;
-		} 
-		DBG("DEBUG: FIFO created @ %s\n", fifo );
-		if ((chmod(fifo, sock_mode)<0)) {
-			LOG(L_ERR, "ERROR: open_fifo_server; can't chmod FIFO: "
-					"%s (mode=%d)\n",
-					strerror(errno), sock_mode);
-			return -1;
-		}
-		if ((sock_uid!=-1) || (sock_gid!=-1)){
-			if (chown(fifo, sock_uid, sock_gid)<0){
-			LOG(L_ERR, "ERROR: open_fifo_server: failed to change the"
-					" owner/group for %s  to %d.%d; %s[%d]\n",
-					fifo, sock_uid, sock_gid, strerror(errno), errno);
-			return -1;
-		}
-	}
-
-		
-	DBG("DEBUG: fifo %s opened, mode=%d\n", fifo, sock_mode );
-	time(&up_since);
-	t=ctime(&up_since);
-	if (strlen(t)+1>=MAX_CTIME_LEN) {
-		LOG(L_ERR, "ERROR: open_fifo_server: "
-			"too long date %d\n", (int)strlen(t));
-		return -1;
-	}
-	memcpy(up_since_ctime,t,strlen(t)+1);
-	/* open it non-blocking or else wait here until someone
-	 * opens it for writing */
-	fifo_read=open(fifo, O_RDONLY|O_NONBLOCK, 0);
-	if (fifo_read<0) {
-		LOG(L_ERR, "ERROR: init_fifo_server: fifo_read did not open: %s\n",
-			strerror(errno));
-		return -1;
-	}
-	fifo_stream=fdopen(fifo_read, "r");
-	if (fifo_stream==NULL) {
-		LOG(L_ERR, "ERROR: init_fifo_server: fdopen failed: %s\n",
-			strerror(errno));
-		return -1;
-	}
-	/* make sure the read fifo will not close */
-	fifo_write=open(fifo, O_WRONLY|O_NONBLOCK, 0);
-	if (fifo_write<0) {
-		LOG(L_ERR, "ERROR: init_fifo_server: fifo_write did not open: %s\n",
-			strerror(errno));
-		return -1;
-	}
-	/* set read fifo blocking mode */
-	if ((opt=fcntl(fifo_read, F_GETFL))==-1){
-		LOG(L_ERR, "ERROR: init_fifo_server: fcntl(F_GETFL) failed: %s [%d]\n",
-				strerror(errno), errno);
-		return -1;
-	}
-	if (fcntl(fifo_read, F_SETFL, opt & (~O_NONBLOCK))==-1){
-		LOG(L_ERR, "ERROR: init_fifo_server: fcntl(F_SETFL) failed: %s [%d]\n",
-				strerror(errno), errno);
-		return -1;
-	}
-	return 0;
-}
-
-
-
-int start_fifo_server()
-{
-#ifdef USE_TCP
-	int sockfd[2];
-#endif
-	if (fifo_stream==0) return 1; /* no error, we just don't start it */
-#ifdef USE_TCP
-	if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockfd)<0){
-			LOG(L_ERR, "ERROR: open_fifo_server: socketpair failed: %s\n",
-				strerror(errno));
-			return -1;
-	}
-#endif
-	process_no++;
-	fifo_pid=fork();
-	if (fifo_pid<0) {
-		LOG(L_ERR, "ERROR: open_fifo_server: failure to fork: %s\n",
-			strerror(errno));
-		return -1;
-	}
-	if (fifo_pid==0) { /* child == FIFO server */
-		/* record pid twice to avoid the child using it, before
-		 * parent gets a chance to set it*/
-		pt[process_no].pid=getpid();
-		LOG(L_INFO, "INFO: fifo process starting: %d\n", getpid());
-		/* call per-child module initialization too -- some
-		   FIFO commands may need it
-		*/
-#ifdef USE_TCP
-		close(sockfd[0]);
-		unix_tcp_sock=sockfd[1];
-#endif
-		if (init_child(PROC_FIFO) < 0 ) {
-			LOG(L_ERR, "ERROR: open_uac_fifo: init_child failed\n");
-			return -1;
-		}
-		/* a real server doesn't die if writing to reply fifo fails */
-		signal(SIGPIPE, SIG_IGN);
-		LOG(L_INFO, "SER: open_uac_fifo: fifo server up at %s...\n",
-			fifo);
-		fifo_server( fifo_stream ); /* never returns */
-	}
-	/* dad process */
-	pt[process_no].pid=fifo_pid;
-	strncpy(pt[process_no].desc, "fifo server", MAX_PT_DESC );
-#ifdef USE_TCP
-	close(sockfd[1]);
-	pt[process_no].unix_sock=sockfd[0];
-	pt[process_no].idx=-1; /* this is not "tcp" process*/
-#endif
-	return 1;
-}
-
-static int print_version_cmd( FILE *stream, char *response_file )
-{
-	if (response_file) {
-		fifo_reply(response_file, "200 ok\n" SERVER_HDR CRLF );
-	} else {
-		LOG(L_ERR, "ERROR: no file for %s\n", "print_version_cmd" );
-	}
-	return 1;
-}
-
-static int pwd_cmd( FILE *stream, char *response_file )
-{
-	char *cwd_buf;
-	int max_len;
-
-	if (!response_file) {
-		LOG(L_ERR, "ERROR: no file for %s\n", "pwd_cmd" );
-		return 1;
-	}
-
-	max_len=pathmax();
-	cwd_buf=pkg_malloc(max_len);
-	if (!cwd_buf) {
-		LOG(L_ERR, "ERROR: pwd_cmd: no cwd pkg mem\n");
-		fifo_reply(response_file, "500 no memory\n");
-		return 1;
-	}
-
-	if (getcwd(cwd_buf, max_len)) {
-		fifo_reply(response_file, "200 ok\n%s\n", cwd_buf );
-	} else {
-		fifo_reply(response_file, "500 getcwd failed\n" );
-	}
-
-	pkg_free(cwd_buf);
-	return 1;
-}
-
-static int arg_cmd( FILE *stream, char *response_file )
-{
-	FILE *reply_pipe;
-	int p;
-
-	if (response_file==0 || *response_file==0 ) {
-		 LOG(L_ERR, "ERROR: ps_fifo_cmd: null file\n");
-		return -1;
-	}
-	reply_pipe=open_reply_pipe(response_file);
-	if (reply_pipe==NULL) {
-		LOG(L_ERR, "ERROR: ps_fifo_cmd: opening reply pipe (%s) failed\n",
-			response_file );
-		return -1;
-	}
-
-	fputs( "200 ok\n", reply_pipe);
-	for (p=0; p<my_argc;p++) 
-			fprintf( reply_pipe, "%s\n", my_argv[p] );
-			
-	fclose(reply_pipe);
-	return 1;
-}
-
-	
-
-/* diagnostic and hello-world FIFO command */
-static int print_fifo_cmd( FILE *stream, char *response_file )
-{
-	char text[MAX_PRINT_TEXT];
-	int text_len;
-	
-	/* expect one line which will be printed out */
-	if (response_file==0 || *response_file==0 ) { 
-		LOG(L_ERR, "ERROR: print_fifo_cmd: null file\n");
-		return -1;
-	}
-	if (!read_line(text, MAX_PRINT_TEXT, stream, &text_len)) {
-		fifo_reply(response_file, 
-			"500 print_fifo_cmd: too big text");
-		return -1;
-	}
-	/* now the work begins */
-	if (response_file) {
-		fifo_reply(response_file, "200 ok\n%s\n", text );
-	} else {
-		LOG(L_INFO, "INFO: print_fifo_cmd: %.*s\n", 
-			text_len, text );
-	}
-	return 1;
-}
-
-static int uptime_fifo_cmd( FILE *stream, char *response_file )
-{
-	time_t now;
-
-	if (response_file==0 || *response_file==0 ) { 
-		LOG(L_ERR, "ERROR: uptime_fifo_cmd: null file\n");
-		return -1;
-	}
-
-	time(&now);
-	fifo_reply( response_file, "200 ok\n"
-		"Now: %sUp Since: %sUp time: %.0f [sec]\n",
-		ctime(&now), up_since_ctime, difftime(now, up_since) );
-
-	return 1;
-}
-
-static int kill_fifo_cmd( FILE *stream, char *response_file )
-{
-	if (response_file==0 || *response_file==0 ) { 
-		LOG(L_ERR, "ERROR: uptime_fifo_cmd: null file\n");
-		return -1;
-	}
-	fifo_reply(response_file, "200 killing now..." );
-	kill(0, SIGTERM);
-	return 1;
-}
-
-static int which_fifo_cmd(FILE *stream, char *response_file )
-{
-	FILE *reply_pipe;
-	struct fifo_command *c;
-
-	if (response_file==0 || *response_file==0 ) {
-		 LOG(L_ERR, "ERROR: which_fifo_cmd: null file\n");
-		return -1;
-	}
-
-	reply_pipe=open_reply_pipe(response_file);
-	if (reply_pipe==NULL) {
-		LOG(L_ERR, "ERROR: which_fifo_cmd: opening reply pipe (%s) failed\n",
-			response_file );
-		return -1;
-	}
-	fputs( "200 ok\n", reply_pipe);
-	for(c=cmd_list; c; c=c->next) {
-		fprintf( reply_pipe, "%s\n", c->name );
-	}
-
-	fclose(reply_pipe);
-	return 1;
-}
-
-static int ps_fifo_cmd(FILE *stream, char *response_file )
-{
-	FILE *reply_pipe;
-	int p;
-
-	if (response_file==0 || *response_file==0 ) {
-		 LOG(L_ERR, "ERROR: ps_fifo_cmd: null file\n");
-		return -1;
-	}
-	reply_pipe=open_reply_pipe(response_file);
-	if (reply_pipe==NULL) {
-		LOG(L_ERR, "ERROR: ps_fifo_cmd: opening reply pipe (%s) failed\n",
-			response_file );
-		return -1;
-	}
-
-	fputs( "200 ok\n", reply_pipe);
-	for (p=0; p<process_count;p++) 
-		fprintf( reply_pipe, "%d\t%d\t%s\n",
-			p, pt[p].pid, pt[p].desc );
-
-	fclose(reply_pipe);
-	return 1;
-}
-
-
-
-static int meminfo_fifo_cmd( FILE *stream, char *response_file )
-{
-	struct mem_info mi;
-	
-	if (response_file==0 || *response_file==0 ) { 
-		LOG(L_ERR, "ERROR: meminfo_fifo_cmd: null file\n");
-		return -1;
-	}
-	
-#ifdef SHM_MEM
-	shm_info(&mi);
-	fifo_reply( response_file, "200 ok\n"
-					"total:%ld\n"
-					"free:%ld\n"
-					"used:%ld\n"
-					"max used:%ld\n"
-					"fragments:%ld\n",
-					mi.total_size, mi.free, mi.real_used,
-					mi.max_used, mi.total_frags);
-#else
-	fifo_reply( response_file, "400 No shared memory support\n");
-#endif
-
-	return 1;
-}
-
-
-
-int register_core_fifo()
-{
-	if (register_fifo_cmd(print_fifo_cmd, FIFO_PRINT, 0)<0) {
-		LOG(L_ERR, "ERROR: unable to register '%s' FIFO cmd\n", FIFO_PRINT);
-		return -1;
-	}
-	if (register_fifo_cmd(uptime_fifo_cmd, FIFO_UPTIME, 0)<0) {
-		LOG(L_ERR, "ERROR: unable to register '%s' FIFO cmd\n", FIFO_UPTIME);
-		return -1;
-	}
-	if (register_fifo_cmd(print_version_cmd, FIFO_VERSION, 0)<0) {
-		LOG(L_ERR, "ERROR: unable to register '%s' FIFO cmd\n",FIFO_VERSION);
-		return -1;
-	}
-	if (register_fifo_cmd(pwd_cmd, FIFO_PWD, 0)<0) {
-		LOG(L_ERR, "ERROR: unable to register '%s' FIFO cmd\n", FIFO_PWD);
-		return -1;
-	}
-	if (register_fifo_cmd(arg_cmd, FIFO_ARG, 0)<0) {
-		LOG(L_ERR, "ERROR: unable to register '%s' FIFO cmd\n", FIFO_ARG);
-		return -1;
-	}
-	if (register_fifo_cmd(which_fifo_cmd, FIFO_WHICH, 0)<0) {
-		LOG(L_ERR, "ERROR: unable to register '%s' FIFO cmd\n", FIFO_WHICH);
-		return -1;
-	}
-	if (register_fifo_cmd(ps_fifo_cmd, FIFO_PS, 0)<0) {
-		LOG(L_ERR, "ERROR: unable to register '%s' FIFO cmd\n", FIFO_PS);
-		return -1;
-	}
-	if (register_fifo_cmd(kill_fifo_cmd, FIFO_KILL, 0)<0) {
-		LOG(L_CRIT, "ERROR: unable to register '%s' FIFO cmd\n", FIFO_KILL);
-		return -1;
-	}
-	if (register_fifo_cmd(meminfo_fifo_cmd, FIFO_MEMINFO, 0)<0) {
-		LOG(L_CRIT, "ERROR: unable to register '%s' FIFO cmd\n", FIFO_MEMINFO);
-		return -1;
-	}
-	if (fifo_db_url==0) {
-		LOG(L_WARN,"WARNING: no fifo_db_url given - "
-			"fifo DB commands disabled!\n");
-	} else if (init_db_fifo(fifo_db_url)<0){
-		return -1;
-	}
-	return 1;
-}

+ 0 - 92
fifo_server.h

@@ -1,92 +0,0 @@
-/*
- * $Id$
- *
- *
- * Copyright (C) 2001-2003 FhG Fokus
- *
- * This file is part of ser, a free SIP server.
- *
- * ser 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
- *
- * For a license to use the ser software under conditions
- * other than those described here, or to purchase support for this
- * software, please contact iptel.org by e-mail at the following addresses:
- *    [email protected]
- *
- * ser 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 this program; if not, write to the Free Software 
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-
-#ifndef _FIFO_SERVER_H
-#define _FIFO_SERVER_H
-
-#include <stdio.h>
-
-#define CMD_SEPARATOR ':'
-
-/* core FIFO command set */
-/* echo input */
-#define FIFO_PRINT "print"
-/* print server's uptime */
-#define FIFO_UPTIME "uptime"
-/* print server's version */
-#define FIFO_VERSION "version"
-/* print available FIFO commands */
-#define FIFO_WHICH "which"
-/* print server's process table */
-#define FIFO_PS "ps"
-/* print server's command line arguments */
-#define FIFO_ARG "arg"
-/* print server's working directory */
-#define FIFO_PWD "pwd"
-/* kill the server */
-#define FIFO_KILL "kill"
-#define FIFO_MEMINFO "meminfo"
-
-#define MAX_CTIME_LEN 128
-
-typedef int (fifo_cmd)( FILE *fifo_stream, char *response_file );
-
-struct fifo_command{
-	fifo_cmd *f;
-	struct fifo_command *next;
-	void *param;
-	char *name;
-};
-
-int register_fifo_cmd(fifo_cmd f, char *cmd_name, void *param);
-
-/* read a single EoL-terminated line from fifo */
-int read_line( char *b, int max, FILE *stream, int *read );
-/* consume EoL from fifo */
-int read_eol( FILE *stream );
-/* consume a set of EoL-terminated lines terminated by an additional EoL */
-int read_line_set(char *buf, int max_len, FILE *fifo, int *len);
-/* consume a set of EoL-terminated lines terminated by a single dot line */
-int read_body(char *buf, int max_len, FILE *fifo, int *len);
-
-int init_fifo_server();
-int start_fifo_server();
-
-/* register core FIFO command set */
-int register_core_fifo();
-
-FILE *open_reply_pipe( char *pipe_name );
-
-/* tell FIFO client an error occurred via reply pipe */
-void fifo_reply( char *reply_fifo, char *reply_fmt, ... );
-
-/* memory deallocation */
-void destroy_fifo();
-
-#endif

+ 0 - 11
globals.h

@@ -124,17 +124,6 @@ extern unsigned int msg_no;
 
 
 extern unsigned long shm_mem_size;
 extern unsigned long shm_mem_size;
 
 
-/* FIFO server config */
-extern char *fifo; /* FIFO name */
-extern int fifo_mode;
-extern char *fifo_dir; /* dir. where  reply fifos are allowed */
-extern char *fifo_db_url;  /* db url used by db_fifo interface */
-
-/* UNIX domain socket configuration */
-extern char *unixsock_name;   /* The name of the socket */
-extern int unixsock_children; /* The number of listening children */
-extern int unixsock_tx_timeout; /* Timeout (in ms) used when sending data */
-
 /* AVP configuration */
 /* AVP configuration */
 extern char *avp_db_url;  /* db url used by user preferences (AVPs) */
 extern char *avp_db_url;  /* db url used by user preferences (AVPs) */
 
 

+ 6 - 102
main.c

@@ -112,8 +112,6 @@
 #include "resolve.h"
 #include "resolve.h"
 #include "parser/parse_hname2.h"
 #include "parser/parse_hname2.h"
 #include "parser/digest/digest_parser.h"
 #include "parser/digest/digest_parser.h"
-#include "fifo_server.h"
-#include "unixsock_server.h"
 #include "name_alias.h"
 #include "name_alias.h"
 #include "hash_func.h"
 #include "hash_func.h"
 #include "pt.h"
 #include "pt.h"
@@ -128,7 +126,7 @@
 #endif
 #endif
 #endif
 #endif
 #include "usr_avp.h"
 #include "usr_avp.h"
-
+#include "core_cmd.h"
 
 
 #include "stats.h"
 #include "stats.h"
 
 
@@ -179,9 +177,7 @@ Options:\n\
     -u uid       Change uid \n\
     -u uid       Change uid \n\
     -g gid       Change gid \n\
     -g gid       Change gid \n\
     -P file      Create a pid file\n\
     -P file      Create a pid file\n\
-    -G file      Create a pgid file\n\
-    -i fifo_path Create a fifo (useful for monitoring " NAME ") \n\
-    -x socket    Create a unix domain socket \n"
+    -G file      Create a pgid file\n"
 #ifdef STATS
 #ifdef STATS
 "    -s file     File to which statistics is dumped (disabled otherwise)\n"
 "    -s file     File to which statistics is dumped (disabled otherwise)\n"
 #endif
 #endif
@@ -388,8 +384,6 @@ void cleanup(show_status)
 	destroy_tls();
 	destroy_tls();
 #endif
 #endif
 	destroy_timer();
 	destroy_timer();
-	close_unixsock_server();
-	destroy_fifo();
 	destroy_script_cb();
 	destroy_script_cb();
 #ifdef PKG_MALLOC
 #ifdef PKG_MALLOC
 	if (show_status){
 	if (show_status){
@@ -804,18 +798,6 @@ int main_loop()
 			LOG(L_WARN, "WARNING: using only the first listen address"
 			LOG(L_WARN, "WARNING: using only the first listen address"
 						" (no fork)\n");
 						" (no fork)\n");
 		}
 		}
-		/* initialize fifo server -- we need to open the fifo before
-		 * do_suid() and start the fifo server after all the socket 
-		 * are initialized, to inherit them*/
-		if (init_fifo_server()<0) {
-			LOG(L_ERR, "initializing fifo server failed\n");
-			goto error;
-		}
-		 /* Initialize Unix domain socket server */
-		if (init_unixsock_socket()<0) {
-			LOG(L_ERR, "Error while creating unix domain sockets\n");
-			goto error;
-		}
 		if (do_suid()==-1) goto error; /* try to drop privileges */
 		if (do_suid()==-1) goto error; /* try to drop privileges */
 		/* process_no now initialized to zero -- increase from now on
 		/* process_no now initialized to zero -- increase from now on
 		   as new processes are forked (while skipping 0 reserved for main 
 		   as new processes are forked (while skipping 0 reserved for main 
@@ -872,19 +854,6 @@ int main_loop()
 						strncpy(pt[process_no].desc, "timer", MAX_PT_DESC );
 						strncpy(pt[process_no].desc, "timer", MAX_PT_DESC );
 				}
 				}
 
 
-		/* if configured, start a server for accepting FIFO commands,
-		 * we need to do it after all the sockets are initialized, to 
-		 * inherit them*/
-		if (start_fifo_server()<0) {
-			LOG(L_ERR, "starting fifo server failed\n");
-			goto error;
-		}
-
-		if (init_unixsock_children()<0) {
-			LOG(L_ERR, "Error while initializing Unix domain socket server\n");
-			goto error;
-		}
-
 		/* main process, receive loop */
 		/* main process, receive loop */
 		process_no=0; /*main process number*/
 		process_no=0; /*main process number*/
 		pt[process_no].pid=getpid();
 		pt[process_no].pid=getpid();
@@ -958,39 +927,10 @@ int main_loop()
 #endif /* USE_TLS */
 #endif /* USE_TLS */
 #endif /* USE_TCP */
 #endif /* USE_TCP */
 
 
-		/* initialize fifo server -- we need to open the fifo before
-		 * do_suid() and start the fifo server after all the socket 
-		 * are initialized, to inherit them*/
-		if (init_fifo_server()<0) {
-			LOG(L_ERR, "initializing fifo server failed\n");
-			goto error;
-		}
-		 /* Initialize Unix domain socket server */
-		     /* Create the unix domain sockets */
-		if (init_unixsock_socket()<0) {
-			LOG(L_ERR, "ERROR: Could not create unix domain sockets\n");
-			goto error;
-		}
-
 			/* all processes should have access to all the sockets (for sending)
 			/* all processes should have access to all the sockets (for sending)
 			 * so we open all first*/
 			 * so we open all first*/
 		if (do_suid()==-1) goto error; /* try to drop privileges */
 		if (do_suid()==-1) goto error; /* try to drop privileges */
 
 
-		/* if configured, start a server for accepting FIFO commands,
-		 * we need to do it after all the sockets are initialized, to 
-		 * inherit them*/
-		if (start_fifo_server()<0) {
-			LOG(L_ERR, "starting fifo server failed\n");
-			goto error;
-		}
-		     /* Spawn children listening on unix domain socket if and only if
-		      * the unix domain socket server has not been disabled (i == 0)
-		      */
-		if (init_unixsock_children()<0) {
-			LOG(L_ERR, "ERROR: Could not initialize unix domain socket server\n");
-			goto error;
-		}
-
 		/* udp processes */
 		/* udp processes */
 		for(si=udp_listen; si; si=si->next){
 		for(si=udp_listen; si; si=si->next){
 			for(i=0;i<children_no;i++){
 			for(i=0;i<children_no;i++){
@@ -1219,7 +1159,6 @@ int main_loop()
 
 
 }
 }
 
 
-
 /*
 /*
  * Calculate number of processes, this does not
  * Calculate number of processes, this does not
  * include processes created by modules
  * include processes created by modules
@@ -1239,17 +1178,12 @@ static int calc_proc_no(void)
 #ifdef USE_SLOW_TIMER
 #ifdef USE_SLOW_TIMER
 		+ 1 /* slow timer process */
 		+ 1 /* slow timer process */
 #endif
 #endif
-		/* fifo server */
-		+((fifo==NULL || strlen(fifo)==0) ? 0 : 1 )
-		/* unixsock server*/
-		+(unixsock_name?unixsock_children:0)
 #ifdef USE_TCP
 #ifdef USE_TCP
 		+((!tcp_disable)?( 1/* tcp main */ + tcp_children_no ):0) 
 		+((!tcp_disable)?( 1/* tcp main */ + tcp_children_no ):0) 
 #endif
 #endif
 		;
 		;
 }
 }
 
 
-
 int main(int argc, char** argv)
 int main(int argc, char** argv)
 {
 {
 
 
@@ -1285,7 +1219,7 @@ int main(int argc, char** argv)
 #ifdef STATS
 #ifdef STATS
 	"s:"
 	"s:"
 #endif
 #endif
-	"f:cm:b:l:n:N:rRvdDETVhw:t:u:g:P:G:i:x:W:";
+	"f:cm:b:l:n:N:rRvdDETVhw:t:u:g:P:G:W:";
 	
 	
 	while((c=getopt(argc,argv,options))!=-1){
 	while((c=getopt(argc,argv,options))!=-1){
 		switch(c){
 		switch(c){
@@ -1423,12 +1357,6 @@ int main(int argc, char** argv)
 		        case 'G':
 		        case 'G':
 				        pgid_file=optarg;
 				        pgid_file=optarg;
 				        break;
 				        break;
-			case 'i':
-					fifo=optarg;
-					break;
-			case 'x':
-					unixsock_name=optarg;
-					break;
 			case '?':
 			case '?':
 					if (isprint(optopt))
 					if (isprint(optopt))
 						fprintf(stderr, "Unknown option `-%c´.\n", optopt);
 						fprintf(stderr, "Unknown option `-%c´.\n", optopt);
@@ -1478,14 +1406,6 @@ try_again:
 	srand(seed);
 	srand(seed);
 	DBG("test random number %u\n", rand());
 	DBG("test random number %u\n", rand());
 	
 	
-	
-	
-	/* register a diagnostic FIFO command  - moved to fifo server - bogdan
-	if (register_core_fifo()<0) {
-		LOG(L_CRIT, "unable to register core FIFO commands\n");
-		goto error;
-	}*/
-
 	/*register builtin  modules*/
 	/*register builtin  modules*/
 	register_builtin_modules();
 	register_builtin_modules();
 
 
@@ -1494,9 +1414,7 @@ try_again:
 		fprintf(stderr, "ERROR: bad config file (%d errors)\n", cfg_errors);
 		fprintf(stderr, "ERROR: bad config file (%d errors)\n", cfg_errors);
 		goto error;
 		goto error;
 	}
 	}
-	
-	
-	
+		
 	print_rl();
 	print_rl();
 	
 	
 	/* init the resolver, before fixing the config */
 	/* init the resolver, before fixing the config */
@@ -1530,19 +1448,6 @@ try_again:
 			goto error;
 			goto error;
 		}
 		}
 	}
 	}
-	/* fix sock/fifo uid/gid */
-	if (sock_user){
-		if (user2uid(&sock_uid, 0, sock_user)<0){
-			fprintf(stderr, "bad socket user name/uid number %s\n", user);
-			goto error;
-		}
-	}
-	if (sock_group){
-		if (group2gid(&sock_gid, sock_group)<0){
-			fprintf(stderr, "bad group name/gid number: -u %s\n", group);
-			goto error;
-		}
-	}
 	if (fix_all_socket_lists()!=0){
 	if (fix_all_socket_lists()!=0){
 		fprintf(stderr,  "failed to initialize list addresses\n");
 		fprintf(stderr,  "failed to initialize list addresses\n");
 		goto error;
 		goto error;
@@ -1586,6 +1491,7 @@ try_again:
 	}
 	}
 	
 	
 	if (init_avps()<0) goto error;
 	if (init_avps()<0) goto error;
+	if (rpc_init_time() < 0) goto error;
 
 
 #ifdef USE_TCP
 #ifdef USE_TCP
 	if (!tcp_disable){
 	if (!tcp_disable){
@@ -1622,8 +1528,6 @@ try_again:
 			goto error;
 			goto error;
 		}
 		}
 	}
 	}
-
-
 	     /* Calculate initial process count, mod_init functions called 
 	     /* Calculate initial process count, mod_init functions called 
 	      * below can add to it
 	      * below can add to it
 	      */
 	      */
@@ -1632,6 +1536,7 @@ try_again:
 		fprintf(stderr, "ERROR: error while initializing modules\n");
 		fprintf(stderr, "ERROR: error while initializing modules\n");
 		goto error;
 		goto error;
 	}
 	}
+
 	     /* The total number of processes is know now, note that no 
 	     /* The total number of processes is know now, note that no 
 	      * function being called before this point may rely on the 
 	      * function being called before this point may rely on the 
 	      * number of processes !
 	      * number of processes !
@@ -1676,4 +1581,3 @@ error:
 	return -1;
 	return -1;
 
 
 }
 }
-

+ 0 - 1032
unixsock_server.c

@@ -1,1032 +0,0 @@
-/*
- * $Id$
- *
- * UNIX Domain Socket Server
- *
- * Copyright (C) 2001-2004 FhG Fokus
- *
- * This file is part of ser, a free SIP server.
- *
- * ser 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
- *
- * For a license to use the ser software under conditions
- * other than those described here, or to purchase support for this
- * software, please contact iptel.org by e-mail at the following addresses:
- *    [email protected]
- *
- * ser 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 this program; if not, write to the Free Software 
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-/* History:
- *              created by janakj
- *  2004-03-03  added tcp init code (andrei)
- *  2004-04-29  added chmod(sock_perm) & chown(sock_user,sock_group)  (andrei)
- */
-
-#include <unistd.h>
-#include <errno.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/stat.h>
-#include <signal.h>
-#include <stdarg.h>
-#include <time.h>
-#include <fcntl.h>
-#include "config.h"
-#include "ut.h"
-#include "globals.h"
-#include "trim.h"
-#include "pt.h"
-#include "sr_module.h"
-#include "mem/mem.h"
-#include "fifo_server.h" /* CMD_SEPARATOR */
-#include "unixsock_server.h"
-#include "tsend.h"
-
-
-/* AF_LOCAL is not defined on solaris */
-#if !defined(AF_LOCAL)
-#define AF_LOCAL AF_UNIX
-#endif
-#if !defined(PF_LOCAL)
-#define PF_LOCAL PF_UNIX
-#endif
-
-
-/* solaris doesn't have SUN_LEN */
-#ifndef SUN_LEN
-#define SUN_LEN(sa)	 ( strlen((sa)->sun_path) + \
-					 (size_t)(((struct sockaddr_un*)0)->sun_path) )
-#endif
-
-
-#define UNIXSOCK_BUF_SIZE BUF_SIZE
-
-char* unixsock_name = 0;
-int unixsock_children = 1;
-int unixsock_tx_timeout = 2000; /* Timeout for sending replies in milliseconds */
-
-
-static int rx_sock, tx_sock;
-static struct unixsock_cmd* cmd_list = 0;
-static char reply_buf[UNIXSOCK_BUF_SIZE];
-static str reply_pos;
-static struct sockaddr_un reply_addr;
-static unsigned int reply_addr_len;
-
-static time_t up_since;
-static char up_since_ctime[MAX_CTIME_LEN];
-
-
-#define PRINT_CMD "print"     /* Diagnostic command */
-#define VERSION_CMD "version" /* Print the version of the server */
-#define UPTIME_CMD "uptime"   /* Print server's uptime */
-#define WHICH_CMD "which"     /* Print available FIFO commands */
-#define PS_CMD "ps"           /* Print server's process table */
-#define ARG_CMD "arg"         /* Print server's command line arguments */
-#define PWD_CMD "pwd"         /* Get the current working directory */
-#define KILL_CMD "kill"       /* Kill the server */
-
-
-/* 
- * Diagnostic and hello-world command 
- */
-static int print_cmd(str* msg)
-{
-	str line;
-	int ret;
-
-	ret = 0;
-
-	if (unixsock_read_line(&line, msg) < 0) {
-		unixsock_reply_asciiz("500 Error while reading text\n");
-		ret = -1;
-		goto end;
-	}
-
-	if (unixsock_reply_printf("200 OK\n%.*s\n", line.len, ZSW(line.s)) < 0) {
-		unixsock_reply_reset();
-		unixsock_reply_asciiz("500 Error while sending reply\n");
-		ret = -1;
-	}
-
- end:
-	if (unixsock_reply_send() < 0) ret = -1;
-	return ret;
-}
-
-
-/*
- * Print the version of the server
- */
-static int version_cmd(str* msg)
-{
-	int ret;
-
-	ret = 0;
-	if (unixsock_reply_asciiz("200 OK\n" SERVER_HDR CRLF) < 0) ret = -1;
-	if (unixsock_reply_send() < 0) ret = -1;
-	return ret;
-}
-
-
-static int uptime_cmd(str* msg)
-{
-	time_t now;
-	int ret;
-
-	time(&now);
-	ret = 0;
-	
-	if (unixsock_reply_printf("200 OK\nNow: %sUp Since: %sUp time: %.0f [sec]\n",
-				  ctime(&now), up_since_ctime, difftime(now, up_since)) < 0) {
-		unixsock_reply_reset();
-		unixsock_reply_asciiz("500 Error while printing reply\n");
-		ret = -1;
-	}
-	
-	if (unixsock_reply_send() < 0) {
-		ret = -1;
-	}
-	
-	return ret;
-}
-
-
-static int which_cmd(str* msg)
-{
-	struct unixsock_cmd* c;
-	int ret;
-
-	ret = 0;
-	unixsock_reply_asciiz("200 OK\n");
-
-	for(c = cmd_list; c; c = c->next) {
-		if (unixsock_reply_printf("%s\n", c->name) < 0) {
-			unixsock_reply_reset();
-			unixsock_reply_asciiz("500 Error while creating reply\n");
-			ret = -1;
-			break;
-		}
-	}
-	
-	if (unixsock_reply_send() < 0) {
-		ret = -1;
-	}
-	return ret;
-}
-
-
-static int ps_cmd(str* msg)
-{
-	int p, ret;
-
-	ret = 0;
-	unixsock_reply_asciiz("200 OK\n");
-	for (p = 0; p < process_count; p++) {
-		if (unixsock_reply_printf("%d\t%d\t%s\n", p, pt[p].pid, pt[p].desc) < 0) {
-			unixsock_reply_reset();
-			unixsock_reply_asciiz("500 Error while printing reply\n");
-			ret = -1;
-			break;
-		}
-	}
-	
-	if (unixsock_reply_send() < 0) {
-		ret = -1;
-	}
-	return ret;
-}
-
-
-static int pwd_cmd(str* msg)
-{
-	char *cwd_buf;
-	int max_len, ret;
-
-	max_len = pathmax();
-	cwd_buf = pkg_malloc(max_len);
-	ret = 0;
-	if (!cwd_buf) {
-		LOG(L_ERR, "pwd_cmd: No memory left\n");
-		unixsock_reply_asciiz("500 No Memory Left\n");
-		ret = -1;
-	}
-
-	if (getcwd(cwd_buf, max_len)) {
-		if (unixsock_reply_printf("200 OK\n%s\n", cwd_buf) < 0) {
-			unixsock_reply_reset();
-			unixsock_reply_asciiz("500 Error while sending reply\n");
-			ret = -1;
-		}
-	} else {
-		unixsock_reply_asciiz("500 getcwd Failed\n");
-		ret = -1;
-	}
-
-	pkg_free(cwd_buf);
-	if (unixsock_reply_send() < 0) {
-		ret = -1;
-	}
-	return ret;
-}
-
-
-static int arg_cmd(str* msg)
-{
-	int p, ret;
-
-	ret = 0;
-	unixsock_reply_asciiz("200 OK\n");
-	for (p = 0; p < my_argc; p++) {
-		if (unixsock_reply_printf("%s\n", my_argv[p]) < 0) {
-			unixsock_reply_reset();
-			unixsock_reply_asciiz("500 Could not create reply\n");
-			ret = -1;
-			break;
-		}
-	}
-			
-	if (unixsock_reply_send() < 0) {
-		ret = -1;
-	}
-	return ret;
-}
-
-
-static int kill_cmd(str* msg)
-{
-	unixsock_reply_asciiz("200 Killing now\n");
-	unixsock_reply_send();
-	kill(0, SIGTERM);
-	return 0;
-}
-
-
-static int register_core_commands(void)
-{
-	if (unixsock_register_cmd(PRINT_CMD, print_cmd) < 0) {
-		return -1;
-	}
-
-	if (unixsock_register_cmd(VERSION_CMD, version_cmd) < 0) {
-		return -1;
-	}
-
-	if (unixsock_register_cmd(UPTIME_CMD, uptime_cmd) < 0) {
-		return -1;
-	}
-
-	if (unixsock_register_cmd(WHICH_CMD, which_cmd) < 0) {
-		return -1;
-	}
-
-	if (unixsock_register_cmd(PS_CMD, ps_cmd) < 0) {
-		return -1;
-	}
-
-	if (unixsock_register_cmd(PWD_CMD, pwd_cmd) < 0) {
-		return -1;
-	}
-
-	if (unixsock_register_cmd(ARG_CMD, arg_cmd) < 0) {
-		return -1;
-	}
-
-	if (unixsock_register_cmd(KILL_CMD, kill_cmd) < 0) {
-		return -1;
-	}
-	return 0;
-}
-
-
-/*
- * Create and bind local socket
- */
-int init_unixsock_socket(void)
-{
-	struct sockaddr_un addr;
-	int len, flags;
-
-	if (unixsock_name == 0) {
-		DBG("init_unixsock_socket: No unix domain socket"
-		    " will be opened\n");
-		return 1;
-	}
-
-	len = strlen(unixsock_name);
-	if (len == 0) {
-		DBG("init_unixsock_socket: Unix domain socket server disabled\n");
-		return 1;
-	} else if (len > 107) {
-		LOG(L_ERR, "ERROR: init_unixsock_socket: Socket name too long\n");
-		return -1;
-	}
-
-	DBG("init_unixsock_socket: Initializing Unix domain socket server @ %s\n", 
-	    unixsock_name);
-
-	if (unlink(unixsock_name) == -1) {
-		if (errno != ENOENT) {
-			LOG(L_ERR, "ERROR: init_unixsock_socket: Error while unlinking "
-			    "old socket (%s): %s\n", unixsock_name, strerror(errno));
-			return -1;
-		}
-	}
-
-	rx_sock = socket(PF_LOCAL, SOCK_DGRAM, 0);
-	if (rx_sock == -1) {
-		LOG(L_ERR, "ERROR: init_unixsock_socket: Cannot create RX "
-				"socket: %s\n", strerror(errno));
-		return -1;
-	}
-
-	memset(&addr, 0, sizeof(addr));
-	addr.sun_family = PF_LOCAL;
-	memcpy(addr.sun_path, unixsock_name, len);
-
-	if (bind(rx_sock, (struct sockaddr*)&addr, SUN_LEN(&addr)) == -1) {
-		LOG(L_ERR, "ERROR: init_unixsock_socket: bind: %s\n", strerror(errno));
-		goto err_rx;
-	}
-	/* try to change the permissions */
-	if (sock_mode){ /* sock_mode==0 doesn't make sense, nobody can read/write*/
-		if (chmod(unixsock_name, sock_mode)<0){
-			LOG(L_ERR, "ERROR: init_unixsock_socket: failed to change the"
-					" permissions for %s to %04o: %s[%d]\n",
-					unixsock_name, sock_mode, strerror(errno), errno);
-			goto err_rx;
-		}
-	}
-	/* try to change the ownership */
-	if ((sock_uid!=-1) || (sock_gid!=-1)){
-		if (chown(unixsock_name, sock_uid, sock_gid)<0){
-			LOG(L_ERR, "ERROR: init_unixsock_socket: failed to change the"
-					" owner/group for %s  to %d.%d; %s[%d]\n",
-					unixsock_name, sock_uid, sock_gid, strerror(errno), errno);
-			goto err_rx;
-		}
-	}
-
-	tx_sock = socket(PF_LOCAL, SOCK_DGRAM, 0);
-	if (tx_sock == -1) {
-		LOG(L_ERR, "ERROR: init_unixsock_socket: Cannot create TX socket:"
-				" %s\n", strerror(errno));
-		goto err_rx;
-	}
-
-	     /* Turn non-blocking mode on */
-	flags = fcntl(tx_sock, F_GETFL);
-	if (flags == -1){
-		LOG(L_ERR, "ERROR: init_unixsock_socket: fcntl failed: %s\n",
-		    strerror(errno));
-		goto err_both;
-	}
-		
-	if (fcntl(tx_sock, F_SETFL, flags | O_NONBLOCK) == -1) {
-		LOG(L_ERR, "ERROR: init_unixsock_socket: fcntl: "
-				"set non-blocking failed: %s\n", strerror(errno));
-		goto err_both;
-	}
-	
-	return 1;
- err_both:
-	close(tx_sock);
- err_rx:
-	close(rx_sock);
-	return -1;
-}
-
-
-static struct unixsock_cmd* lookup_cmd(str* cmd)
-{
-	struct unixsock_cmd* c;
-
-	for(c = cmd_list; c; c = c->next) {
-		if ((cmd->len == c->name.len) &&
-		    (strncasecmp(c->name.s, cmd->s, cmd->len) == 0)) {
-			return c;
-		}
-	}
-	return 0;
-}
-
-
-static int parse_cmd(str* res, str* buffer)
-{
-	char* cmd_end;
-
-	if (!res || !buffer) {
-		LOG(L_ERR, "parse_cmd: Invalid parameter value\n");
-		return -1;
-	}
-
-	if (buffer->len < 3) {
-		LOG(L_ERR, "parse_cmd: Message too short\n");
-		return -1;
-	}
-
-	if (buffer->s[0] != CMD_SEPARATOR) {
-		LOG(L_ERR, "parse_cmd: Command must start with %c\n", 
-		    CMD_SEPARATOR);
-		return -1;
-	}
-	
-	cmd_end = q_memchr(buffer->s + 1, CMD_SEPARATOR, buffer->len - 1);
-	if (!cmd_end) {
-		LOG(L_ERR, "parse_cmd: Closing '%c' missing\n", CMD_SEPARATOR);
-		return -1;
-	}
-
-	res->s = buffer->s + 1;
-	res->len = cmd_end - res->s;
-	return 0;
-} 
-
-
-static void skip_line(str* buffer)
-{
-	if (!buffer) return;
-
-	     /* Find \n */
-	while (buffer->len && (buffer->s[0] != '\n')) {
-		buffer->s++;
-		buffer->len--;
-	}
-
-	if (buffer->len) {
-		buffer->s++;
-		buffer->len--;
-	}
-
-	     /* Skip CR following LF */
-	while (buffer->len && (buffer->s[0] == '\r')) {
-		buffer->s++;
-		buffer->len--;
-	}
-}
-
-
-static void unix_server_loop(void)
-{
-	int ret;
-	str cmd, buffer;
-	static char buf[UNIXSOCK_BUF_SIZE];
-	struct unixsock_cmd* c;
-
-	
-	while(1) {
-		reply_addr_len = sizeof(reply_addr);
-		ret = recvfrom(rx_sock, buf, UNIXSOCK_BUF_SIZE, 0, 
-			       (struct sockaddr*)&reply_addr, &reply_addr_len);
-		if (ret == -1) {
-			LOG(L_ERR, "unix_server_loop: recvfrom: (%d) %s\n", 
-			    errno, strerror(errno));
-			if ((errno == EINTR) || 
-			    (errno == EAGAIN) || 
-			    (errno == EWOULDBLOCK) || 
-			    (errno == ECONNREFUSED)) {
-				DBG("unix_server_loop: Got %d (%s), going on\n",
-				    errno, strerror(errno));
-				continue;
-			}
-			LOG(L_CRIT, "BUG: unix_server_loop: unexpected recvfrom error\n");
-			continue;
-		}
-
-		buffer.s = buf;
-		buffer.len = ret;
-		unixsock_reply_reset();
-
-		if (parse_cmd(&cmd, &buffer) < 0) {
-			unixsock_reply_asciiz("400 First line malformed\n");
-			unixsock_reply_send();
-			continue;
-		}
-
-		buffer.s = cmd.s + cmd.len + 1;
-		buffer.len -= cmd.len + 1 + 1;
-		skip_line(&buffer); /* Skip the reply filename */
-
-		c = lookup_cmd(&cmd);
-		if (c == 0) {
-			LOG(L_ERR, "unix_server_loop: Could not find "
-			    "command '%.*s'\n", cmd.len, ZSW(cmd.s));
-			unixsock_reply_printf("500 Command %.*s not found\n", cmd.len, ZSW(cmd.s));
-			unixsock_reply_send();
-			continue;
-		}
-
-		ret = c->f(&buffer);
-		if (ret < 0) {
-			LOG(L_ERR, "unix_server_loop: Command '%.*s' failed with "
-			    "return value %d\n", cmd.len, ZSW(cmd.s), ret);
-			     /* Note that we do not send reply here, the 
-			      * function is supposed to do so, it knows the 
-			      * reason of the failure better than us
-			      */
-		}
-	}
-}
-
-
-static int get_uptime(void)
-{
-	char* t;
-
-	time(&up_since);
-	t = ctime(&up_since);
-	if (strlen(t) + 1 >= MAX_CTIME_LEN) {
-		LOG(L_ERR, "get_uptime: Too long date %d\n", (int)strlen(t));
-		return -1;
-	}
-	memcpy(up_since_ctime, t, strlen(t) + 1);
-	return 0;
-}
-
-
-/*
- * Spawn listeners
- */
-int init_unixsock_children(void)
-{
-	int i;
-	pid_t pid;
-#ifdef USE_TCP
-	int sockfd[2];
-#endif
-
-	if (!unixsock_name || *unixsock_name == '\0') {
-		return 1;
-	}
-
-	if (get_uptime() < 0) {
-		return -1;
-	}
-	
-        if (register_core_commands() < 0) {
-		close(rx_sock);
-		close(tx_sock);
-		return -1;
-	}
-
-	for(i = 0; i < unixsock_children; i++) {
-		process_no++;
-#ifdef USE_TCP
-		if(!tcp_disable){
- 			if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockfd)<0){
-				LOG(L_ERR, "ERROR: init_unixsock_server: socketpair"
-						" failed: %s\n", strerror(errno));
-				return -1;
-			}
-		}
-#endif
-		pid = fork();
-		if (pid < 0) {
-			LOG(L_ERR, "init_unixsock_server: Unable to fork: %s\n",
-			    strerror(errno));
-			close(rx_sock);
-			close(tx_sock);
-			return -1;
-		} else if (pid == 0) { /* child */
-#ifdef USE_TCP
-			if (!tcp_disable){
-				close(sockfd[0]);
-				unix_tcp_sock=sockfd[1];
-			}
-#endif
-			/* record pid twice to avoid the child using it, before
-			 * parent gets a chance to set it*/
-			pt[process_no].pid=getpid();
-			if (init_child(PROC_UNIXSOCK) < 0) {
-				LOG(L_ERR, "init_unixsock_server: Error in "
-				    "init_child\n");
-				close(rx_sock);
-				close(tx_sock);
-				return -1;
-			}
-
-			unix_server_loop(); /* Never returns */
-		}
-
-		     /* Parent */
-		pt[process_no].pid = pid;
-		strncpy(pt[process_no].desc, "unix domain socket server", 
-			MAX_PT_DESC);
-#ifdef USE_TCP
-		if (!tcp_disable){
-			close(sockfd[1]);
-			pt[process_no].unix_sock=sockfd[0];
-			pt[process_no].idx=-1; /* this is not a "tcp"
-									  process*/
-		}
-#endif
-
-	}
-
-	DBG("init_unixsock_server: Unix domain socket server successfully initialized @ %s\n",
-	    unixsock_name);
-	return 1;
-}
-
-
-/*
- * Clean up
- */
-void close_unixsock_server(void)
-{
-	struct unixsock_cmd* c;
-	close(rx_sock);
-	close(tx_sock);
-
-	while(cmd_list) {
-		c = cmd_list;
-		cmd_list = cmd_list->next;
-		pkg_free(c);
-	}
-}
-
-
-/*
- * Register a new command
- */
-int unixsock_register_cmd(char* command, unixsock_f* f)
-{
-	str cmd;
-	struct unixsock_cmd* new_cmd;
-
-	cmd.s = command;
-	cmd.len = strlen(command);
-
-	if (lookup_cmd(&cmd)) {
-		LOG(L_ERR, "unixsock_register_cmd: Function already exists\n");
-		return -1;
-	}
-
-	new_cmd = pkg_malloc(sizeof(struct unixsock_cmd));
-	if (new_cmd == 0) {
-		LOG(L_ERR, "register_unixsock_cmd: Out of mem\n");
-		return -1;
-	}
-
-	new_cmd->name = cmd;
-	new_cmd->f = f;
-
-	new_cmd->next = cmd_list;
-	cmd_list = new_cmd;
-	
-	DBG("unixsock_register_cmd: New command (%.*s) registered\n", 
-	    cmd.len, ZSW(cmd.s));
-	return 1;
-}
-
-
-int unixsock_add_to_reply(const char* buf, size_t len)
-{
-	if (reply_pos.len < len) {
-		LOG(L_ERR, "unixsock_add_to_reply: Buffer too small\n");
-		return -1;
-	}
-
-	memcpy(reply_pos.s, buf, len);
-	reply_pos.s += len;
-	reply_pos.len -= len;
-	return 0;
-}
-
-
-/*
- * Send a reply
- */
-ssize_t unixsock_reply_send(void)
-{
-	return tsend_dgram(tx_sock, 
-			   reply_buf, reply_pos.s - reply_buf,
-			   (struct sockaddr*)&reply_addr, reply_addr_len, 
-			   unixsock_tx_timeout);
-}
-
-
-/*
- * Send a reply
- */
-ssize_t unixsock_reply_sendto(struct sockaddr_un* to)
-{
-	if (!to) {
-		LOG(L_ERR, "unixsock_reply_sendto: Invalid parameter value\n");
-		return -1;
-	}
-
-	return tsend_dgram(tx_sock, 
-			   reply_buf, reply_pos.s - reply_buf, 
-			   (struct sockaddr*)to, SUN_LEN(to), 
-			   unixsock_tx_timeout);
-}
-
-
-/*
- * Read a line, the result will be stored in line
- * parameter, the data is not copied, it's just
- * a pointer to an existing buffer
- */
-int unixsock_read_line(str* line, str* source)
-{
-	if (!line || !source) {
-		LOG(L_ERR, "unixsock_read_line: Invalid parameter value\n");
-		return -1;
-	}
-
-	*line = *source;
-	skip_line(source);
-	line->len = source->s - line->s;
-	trim_trailing(line);
-	if (line->len) {
-		return 0;
-	} else {
-		return 1;
-	}
-}
-
-
-/*
- * Read body until the closing .CRLF, no CRLF recovery
- * is done so no additional buffer is necessary, body will
- * point to an existing buffer
- */
-int unixsock_read_body(str* body, str* source)
-{
-	int i, state, last_dot;
-
-	enum states {
-		ST_BEGIN,
-		ST_CRLF,
-		ST_DATA,
-		ST_NEWLINE
-	};
-
-	if (!body || !source) {
-		LOG(L_ERR, "unixsock_read_body: Invalid parameter value\n");
-		return -1;
-	}
-
-	if (source->len < 2) {
-		LOG(L_ERR, "unixsock_read_body: Not enough input data "
-		    "(malformed message ?)\n");
-		return -1;
-	}
-
-	state = ST_BEGIN;
-	body->s = source->s;
-	last_dot = 0;
-	for(i = 0; i < source->len; i++) {
-		switch(state) {
-		case ST_BEGIN:
-			if (source->s[i] == '.') {
-				last_dot = i;
-				state = ST_CRLF;
-			} else if (source->s[i] == '\n') {
-				state = ST_NEWLINE;
-			} else {
-				state = ST_DATA;
-			}
-			break;
-			
-		case ST_CRLF:
-			if (source->s[i] == '\n') {
-				body->len = last_dot;
-				source->s += i + 1;
-				source->len -= i + 1;
-				return 0;
-			} else if (source->s[i] != '\r') {
-				state = ST_DATA;
-			}
-			break;
-
-		case ST_DATA:
-			if (source->s[i] == '\n') {
-				state = ST_NEWLINE;
-			}
-			break;
-
-		case ST_NEWLINE:
-			if (source->s[i] == '.') {
-				last_dot = i;
-				state = ST_CRLF;
-			}
-			break;
-		}
-	}
-
-	LOG(L_ERR, "unixsock_read_body: Could not find the end of the body\n");
-	return -1;
-}
-
-
-/*
- * Read a set of lines, the functions performs CRLF recovery,
- * therefore lineset must point to an additional buffer
- * to which the data will be copied. Initial lineset->len contains
- * the size of the buffer
- */
-int unixsock_read_lineset(str* lineset, str* source)
-{
-	int i, state, len;
-
-	enum states {
-		ST_BEGIN,
-		ST_CRLF,
-		ST_DATA,
-		ST_NEWLINE
-	};
-
-	if (!lineset || !source) {
-		LOG(L_ERR, "unixsock_read_lineset: Invalid parameter value\n");
-		return -1;
-	}
-
-	if (!lineset->s || !lineset->len) {
-		LOG(L_ERR, "unixsock_read_lineset: Buffer too small\n");
-		return -1;
-	}
-
-	if (source->len < 2) {
-		LOG(L_ERR, "unixsock_read_lineset: Not enough input "
-		    "data (malformed message ?)\n");
-		return -1;
-	}                 
-
-	state = ST_BEGIN;
-	len = 0;
-	for(i = 0; i < source->len; i++) {
-		if (source->s[i] == '\r') {
-			     /* Filter out CR */
-			continue;
-		}
-
-		switch(state) {
-		case ST_BEGIN:
-			if (source->s[i] == '.') {
-				state = ST_CRLF;
-			} else if (source->s[i] == '\n') {
-				if (len + 2 > lineset->len) goto buf_err;
-				lineset->s[len++] = '\r';
-				lineset->s[len++] = '\n';
-				state = ST_NEWLINE;
-			} else {
-				if (len + 1 > lineset->len) goto buf_err;
-				lineset->s[len++] = source->s[i];
-			}
-			break;
-			
-		case ST_CRLF:
-			if (source->s[i] == '\n') {
-				lineset->len = len;
-				source->s += i + 1;
-				source->len -= i + 1;
-				return 0;
-			} else {
-				if (len + 2 > lineset->len) goto buf_err;
-				lineset->s[len++] = '.';
-				lineset->s[len++] = source->s[i];
-				state = ST_DATA;
-			}
-			break;
-
-		case ST_DATA:
-			if (source->s[i] == '\n') {
-				if (len + 2 > lineset->len) goto buf_err;
-				lineset->s[len++] = '\r';
-				lineset->s[len++] = '\n';
-				state = ST_NEWLINE;
-			} else {
-				if (len + 1 > lineset->len) goto buf_err;
-				lineset->s[len++] = source->s[i];
-			}
-			break;
-
-		case ST_NEWLINE:
-			if (source->s[i] == '.') {
-				state = ST_CRLF;
-			} else {
-				if (len + 1 > lineset->len) goto buf_err;
-				lineset->s[len++] = source->s[i];
-				state = ST_DATA;
-			}
-			break;
-		}
-	}
-
-	LOG(L_ERR, "unixsock_read_body: Could not find the end of the body\n");
-	return -1;
-
- buf_err:
-	LOG(L_ERR, "unixsock_read_lineset: Buffer too small\n");
-	return -1;
-}
-
-
-/*
- * Reset the reply buffer -- start to write
- * at the beginning
- */
-void unixsock_reply_reset(void)
-{
-	reply_pos.s = reply_buf;
-	reply_pos.len = UNIXSOCK_BUF_SIZE;
-}
-
-
-/*
- * Add ASCIIZ to the reply buffer
- */
-int unixsock_reply_asciiz(char* str)
-{
-	int len;
-	
-	if (!str) {
-		LOG(L_ERR, "unixsock_reply_asciiz: Invalid parameter value\n");
-		return -1;
-	}
-
-	len = strlen(str);
-
-	if (reply_pos.len < len) {
-		LOG(L_ERR, "unixsock_reply_asciiz: Buffer too small\n");
-		return -1;
-	}
-
-	memcpy(reply_pos.s, str, len);
-	reply_pos.s += len;
-	reply_pos.len -= len;
-	return 0;
-}
-
-
-/*
- * Add a string represented by str structure
- * to the reply buffer
- */
-int unixsock_reply_str(str* s)
-{
-	if (!s) {
-		LOG(L_ERR, "unixsock_reply_str: Invalid parameter value\n");
-		return -1;
-	}
-
-	if (reply_pos.len < s->len) {
-		LOG(L_ERR, "unixsock_reply_str: Buffer too small\n");
-		return -1;
-	}
-	
-	memcpy(reply_pos.s, s->s, s->len);
-	reply_pos.s += s->len;
-	reply_pos.len -= s->len;
-	return 0;
-}
-
-
-/*
- * Printf-like reply function
- */
-int unixsock_reply_printf(char* fmt, ...)
-{
-	va_list ap;
-	int ret;
-
-	if (!fmt) {
-		LOG(L_ERR, "unixsock_reply_printf: Invalid parameter value\n");
-		return -1;
-	}
-
-	va_start(ap, fmt);
-	ret = vsnprintf(reply_pos.s, reply_pos.len, fmt, ap);
-	if ((ret < 0) || (ret >= reply_pos.len)) {
-		LOG(L_ERR, "unixsock_reply_printf: Buffer too small\n");
-		va_end(ap);
-		return -1;
-	}
-
-	va_end(ap);
-	reply_pos.s += ret;
-	reply_pos.len -= ret;
-	return 0;
-}
-
-
-/*
- * Return the address of the sender
- */
-struct sockaddr_un* unixsock_sender_addr(void)
-{
-	return &reply_addr;
-}

+ 0 - 143
unixsock_server.h

@@ -1,143 +0,0 @@
-/*
- * $Id$
- *
- * UNIX Domain Socket Server
- *
- * Copyright (C) 2001-2004 FhG Fokus
- *
- * This file is part of ser, a free SIP server.
- *
- * ser 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
- *
- * For a license to use the ser software under conditions
- * other than those described here, or to purchase support for this
- * software, please contact iptel.org by e-mail at the following addresses:
- *    [email protected]
- *
- * ser 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 this program; if not, write to the Free Software 
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-#ifndef _UNIXSOCK_SERVER_H
-#define _UNIXSOCK_SERVER_H
-
-
-#include <sys/types.h>
-#include <sys/un.h>
-#include <unistd.h>
-#include "str.h"
-
-
-typedef int (unixsock_f)(str* msg);
-
-
-struct unixsock_cmd {
-	str name;                   /* The name of the function */
-	unixsock_f* f;              /* Function to be called */
-	struct unixsock_cmd* next;  /* Next element in the linked list */
-};
-
-
-/*
- * Initialize Unix domain socket server
- */
-int init_unixsock_socket(void);
-
-
-/*
- * Initialize Unix domain socket server
- */
-int init_unixsock_children(void);
-
-
-/*
- * Clean up
- */
-void close_unixsock_server(void);
-
-
-/*
- * Register a new command
- */
-int unixsock_register_cmd(char* name, unixsock_f* f);
-
-
-/*
- * Reset the reply buffer -- start to write
- * at the beginning
- */
-void unixsock_reply_reset(void);
-
-
-/*
- * Add ASCIIZ to the reply buffer
- */
-int unixsock_reply_asciiz(char* str);
-
-
-/*
- * Add a string represented by str structure
- * to the reply buffer
- */
-int unixsock_reply_str(str* s);
-
-
-/*
- * Printf-like reply function
- */
-int unixsock_reply_printf(char* fmt, ...);
-
-
-/*
- * Send the reply
- */
-ssize_t unixsock_reply_send(void);
-
-
-/*
- * Send the reply to the given destination
- */
-ssize_t unixsock_reply_sendto(struct sockaddr_un* to);
-
-
-/*
- * Read a line, the result will be stored in line
- * parameter, the data is not copied, it's just
- * a pointer to an existing buffer
- */
-int unixsock_read_line(str* line, str* source);
-
-
-/*
- * Read body until the closing .CRLF, no CRLF recovery
- * is done so no additional buffer is necessary, body will
- * point to an existing buffer
- */
-int unixsock_read_body(str* body, str* source);
-
-
-/*
- * Read a set of lines, the functions performs CRLF recovery,
- * therefore lineset must point to an additional buffer
- * to which the data will be copied. Initial lineset->len contains
- * the size of the buffer
- */
-int unixsock_read_lineset(str* lineset, str* source);
-
-
-/*
- * Return the address of the sender
- */
-struct sockaddr_un* unixsock_sender_addr(void);
-
-
-#endif /* _UNIXSOCK_SERVER_H */