ctrl_socks.h

00001 /*
00002  * $Id$
00003  *
00004  * Copyright (C) 2006 iptelorg GmbH
00005  *
00006  * This file is part of ser, a free SIP server.
00007  *
00008  * ser is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version
00012  *
00013  * For a license to use the ser software under conditions
00014  * other than those described here, or to purchase support for this
00015  * software, please contact iptel.org by e-mail at the following addresses:
00016  *    info@iptel.org
00017  *
00018  * ser is distributed in the hope that it will be useful,
00019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021  * GNU General Public License for more details.
00022  *
00023  * You should have received a copy of the GNU General Public License 
00024  * along with this program; if not, write to the Free Software 
00025  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00026  */
00027 /* History:
00028  * --------
00029  *  2006-02-14  created by andrei
00030  */
00031 
00032 #ifndef _ctrl_socks_h
00033 #define _ctrl_socks_h
00034 #include <sys/types.h>
00035 #include <sys/socket.h>
00036 #include <sys/un.h>
00037 #include <sys/uio.h> /* iovec */
00038 #include "../../ip_addr.h"
00039 #include "init_socks.h"
00040 
00041 
00042 
00043 enum payload_proto      { P_BINRPC , P_FIFO };
00044 
00045 struct id_list{
00046         char* name;
00047         enum socket_protos proto;
00048         enum payload_proto data_proto;
00049         int port;
00050         char* buf; /* name points somewhere here */
00051         struct id_list* next;
00052 };
00053 
00054 union sockaddr_u{
00055         union sockaddr_union sa_in;
00056         struct sockaddr_un sa_un;
00057 };
00058 
00059 
00060 
00061 /* list of control sockets */
00062 struct ctrl_socket{
00063         int fd;
00064         int write_fd; /* used only by fifo */
00065         enum socket_protos transport;
00066         enum payload_proto p_proto;
00067         char* name;
00068         int port;
00069         struct ctrl_socket* next;
00070         union sockaddr_u u;
00071         void *data; /* extra data, socket dependent */
00072 };
00073 
00074 
00075 
00076 struct id_list* parse_listen_id(char*, int, enum socket_protos);
00077 
00078 int init_ctrl_sockets(struct ctrl_socket** c_lst, struct id_list* lst,
00079                                                 int def_port, int perm, int uid, int gid);
00080 void free_id_list(struct id_list*);
00081 void free_ctrl_socket_list(struct ctrl_socket* l);
00082 
00083 
00084 inline static char* payload_proto_name(enum payload_proto p)
00085 {
00086         switch(p){
00087                 case P_BINRPC:
00088                         return "binrpc";
00089                 case P_FIFO:
00090                         return "fifo";
00091                 default:
00092                         ;
00093         }
00094         return "<unknown>";
00095 }
00096 
00097 #endif