unixsock_server.h
50a0659f
 /*
  * $Id$
  *
  * UNIX Domain Socket Server
  *
53c7e0f1
  * Copyright (C) 2001-2004 FhG Fokus
50a0659f
  *
  * 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:
  *    info@iptel.org
  *
  * 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
 
 
8ebe2904
 #include <sys/types.h>
50a0659f
 #include <sys/un.h>
8729ac5e
 #include <unistd.h>
50a0659f
 #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
  */
b3fef92b
 int init_unixsock_socket(void);
 
 
 /*
  * Initialize Unix domain socket server
  */
 int init_unixsock_children(void);
50a0659f
 
 
 /*
  * Clean up
  */
 void close_unixsock_server(void);
 
 
 /*
  * Register a new command
  */
4421b319
 int unixsock_register_cmd(char* name, unixsock_f* f);
50a0659f
 
 
 /*
4421b319
  * Reset the reply buffer -- start to write
  * at the beginning
50a0659f
  */
4421b319
 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, ...);
50a0659f
 
 
 /*
  * Send the reply
  */
4421b319
 ssize_t unixsock_reply_send(void);
50a0659f
 
 
 /*
8b3c4193
  * Send the reply to the given destination
  */
 ssize_t unixsock_reply_sendto(struct sockaddr_un* to);
 
 
 /*
50a0659f
  * 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);
 
 
8b3c4193
 /*
  * Return the address of the sender
  */
037024d7
 struct sockaddr_un* unixsock_sender_addr(void);
8b3c4193
 
 
50a0659f
 #endif /* _UNIXSOCK_SERVER_H */