root/src/ftmod/ftmod_sangoma_boost/sangoma_boost_client.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. sctp_no_nagle

   1 /*
   2  * Copyright (c) 2007, Anthony Minessale II, Nenad Corbic
   3  * All rights reserved.
   4  * 
   5  * Redistribution and use in source and binary forms, with or without
   6  * modification, are permitted provided that the following conditions
   7  * are met:
   8  * 
   9  * * Redistributions of source code must retain the above copyright
  10  * notice, this list of conditions and the following disclaimer.
  11  * 
  12  * * Redistributions in binary form must reproduce the above copyright
  13  * notice, this list of conditions and the following disclaimer in the
  14  * documentation and/or other materials provided with the distribution.
  15  * 
  16  * * Neither the name of the original author; nor the names of any contributors
  17  * may be used to endorse or promote products derived from this software
  18  * without specific prior written permission.
  19  * 
  20  * 
  21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24  * A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER
  25  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  26  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  27  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  28  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  29  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  30  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  31  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32  */
  33 
  34 #ifndef _SANGOMABC_H
  35 #define _SANGOMABC_H
  36 
  37 #include "sangoma_boost_interface.h"
  38 
  39 #include <ctype.h>
  40 #include <string.h>
  41 #ifndef WIN32
  42 #include <unistd.h>
  43 #include <sys/socket.h>
  44 #include <netinet/in.h>
  45 #ifdef HAVE_NETINET_SCTP_H
  46 #include <netinet/sctp.h>
  47 #endif
  48 #include <arpa/inet.h>
  49 #include <netdb.h>
  50 #include <sys/time.h>
  51 #endif
  52 #include <stdlib.h>
  53 #include <errno.h>
  54 #include <stdarg.h>
  55 #include <stdio.h>
  56 #include <sys/types.h>
  57 #include <stdarg.h>
  58 #include "sigboost.h"
  59 
  60 #define sangomabc_test_flag(p,flag) ((p)->flags & (flag))
  61 
  62 #define sangomabc_set_flag(p,flag)              do {            \
  63                 ((p)->flags |= (flag));                                 \
  64         } while (0)
  65 
  66 #define sangomabc_clear_flag(p,flag)            do {    \
  67                 ((p)->flags &= ~(flag));                                \
  68         } while (0)
  69 
  70 #define sangomabc_copy_flags(dest,src,flagz)    do {    \
  71                 (dest)->flags &= ~(flagz);                                      \
  72                 (dest)->flags |= ((src)->flags & (flagz));      \
  73         } while (0)
  74 
  75 typedef  t_sigboost_callstart sangomabc_event_t;
  76 typedef  t_sigboost_short sangomabc_short_event_t;
  77 typedef uint32_t sangomabc_event_id_t;
  78 
  79 typedef struct sangomabc_ip_cfg
  80 {
  81         char local_ip[25];
  82         int local_port;
  83         char remote_ip[25];
  84         int remote_port;
  85 }sangomabc_ip_cfg_t;
  86 
  87 typedef enum {
  88         MSU_FLAG_EVENT = (1 << 0),
  89         MSU_FLAG_DOWN = (1 << 1)
  90 } sangomabc_flag_t;
  91 
  92 
  93 struct sangomabc_connection {
  94         ftdm_socket_t socket;
  95         struct sockaddr_in local_addr;
  96         struct sockaddr_in remote_addr;
  97         sangomabc_event_t event;
  98         struct hostent remote_hp;
  99         struct hostent local_hp;
 100         unsigned int flags;
 101         ftdm_mutex_t *mutex;
 102         FILE *log;
 103         unsigned int txseq;
 104         unsigned int rxseq;
 105         unsigned int txwindow;
 106         unsigned int rxseq_reset;
 107         sangomabc_ip_cfg_t cfg;
 108         /* boost signaling mod interface pointer (if not working in TCP mode) */
 109         boost_sigmod_interface_t *sigmod;
 110         ftdm_queue_t *boost_queue;      
 111         ftdm_interrupt_t *sock_interrupt;
 112         ftdm_span_t *span;
 113         int debuglevel;
 114 };
 115 
 116 typedef struct sangomabc_connection sangomabc_connection_t;
 117 
 118 typedef struct sangomabc_queue_element {
 119         unsigned char boostmsg[sizeof(sangomabc_event_t)];
 120         ftdm_size_t size;
 121 } sangomabc_queue_element_t;
 122 
 123 /* disable nagle's algorythm */
 124 static __inline__ void sctp_no_nagle(int socket)
 125 {
 126 #ifdef HAVE_NETINET_SCTP_H
 127     int flag = 1;
 128     setsockopt(socket, IPPROTO_SCTP, SCTP_NODELAY, (char *) &flag, sizeof(int));
 129 #endif
 130 }
 131 
 132 int sangomabc_connection_close(sangomabc_connection_t *mcon);
 133 int sangomabc_connection_open(sangomabc_connection_t *mcon, char *local_ip, int local_port, char *ip, int port);
 134 sangomabc_event_t *__sangomabc_connection_read(sangomabc_connection_t *mcon, int iteration, const char *file, const char *func, int line);
 135 sangomabc_event_t *__sangomabc_connection_readp(sangomabc_connection_t *mcon, int iteration, const char *file, const char *func, int line);
 136 int __sangomabc_connection_write(sangomabc_connection_t *mcon, sangomabc_event_t *event, const char *file, const char *func, int line);
 137 int __sangomabc_connection_writep(sangomabc_connection_t *mcon, sangomabc_event_t *event, const char *file, const char *func, int line);
 138 #define sangomabc_connection_write(_m,_e) __sangomabc_connection_write(_m, _e, __FILE__, __FUNCTION__, __LINE__)
 139 #define sangomabc_connection_writep(_m,_e) __sangomabc_connection_writep(_m, _e, __FILE__, __FUNCTION__, __LINE__)
 140 #define sangomabc_connection_read(_m,_e) __sangomabc_connection_read(_m, _e, __FILE__, __FUNCTION__, __LINE__)
 141 #define sangomabc_connection_readp(_m,_e) __sangomabc_connection_readp(_m, _e, __FILE__, __FUNCTION__, __LINE__)
 142 void sangomabc_event_init(sangomabc_short_event_t *event, sangomabc_event_id_t event_id, int chan, int span);
 143 void sangomabc_call_init(sangomabc_event_t *event, const char *calling, const char *called, int setup_id);
 144 const char *sangomabc_event_id_name(uint32_t event_id);
 145 int sangomabc_exec_command(sangomabc_connection_t *mcon, int span, int chan, int id, int cmd, int cause, int flags);
 146 int sangomabc_exec_commandp(sangomabc_connection_t *pcon, int span, int chan, int id, int cmd, int cause);
 147 
 148 #define BOOST_EVENT_SPAN(sigmod, event) ((sigmod) ? event->span : event->span + 1)
 149 #define BOOST_EVENT_CHAN(sigmod, event) ((sigmod) ? event->chan : event->chan + 1)
 150 
 151 
 152 #endif
 153 
 154 
 155 /* For Emacs:
 156  * Local Variables:
 157  * mode:c
 158  * indent-tabs-mode:t
 159  * tab-width:4
 160  * c-basic-offset:4
 161  * End:
 162  * For VIM:
 163  * vim:set softtabstop=4 shiftwidth=4 tabstop=4:
 164  */

/* [<][>][^][v][top][bottom][index][help] */