Changeset 508:a682a6b47af7 in verona


Ignore:
Timestamp:
Aug 13, 2012 4:11:31 PM (9 months ago)
Author:
Nikita Kozlov <nikita@…>
Branch:
default
Message:

add tunneling for csl

Files:
10 edited

Legend:

Unmodified
Added
Removed
  • .hgsubstate

    r505 r508  
    22cb83411a9e6657814a3f0e0b5d96bbb132540511 libs/miniini 
    333f74e14cf5cf1f82bde7e859a8e44114b31423ca libs/srtp 
    4 8023ec21a684649d07772d2e785b6e2c779e8717 mediastreamer2 
     407590391fa90ac87c41c1011d3739660d650e621 mediastreamer2 
  • libeXosip2/CMakeLists.txt

    r435 r508  
    5353 
    5454if(USE_CSL) 
     55  if(IOS) 
     56    add_definitions(-DIOS) 
     57  endif(IOS) 
    5558  add_definitions( -DHAVE_CSL ) 
    5659  list(REMOVE_ITEM EXOSIP2_SRCS src/eXtl_socks.c src/eXtl_tls.c src/eXtl_dtls.c) 
     60  add_definitions( -DENABLE_SOCKS) 
    5761else(USE_CSL) 
    5862  add_definitions( -DENABLE_SOCKS) 
  • libeXosip2/src/eXconf.c

    r423 r508  
    3232int ipv6_enable = 0; 
    3333 
     34#ifdef ENABLE_SOCKS 
     35static struct eXtl_protocol* socks_proto_tab[] = { 
     36 &eXtl_socks_tcp, 
     37 &eXtl_socks_http, 
     38 &eXtl_socks_tcp2udp, 
     39 &eXtl_socks_http2udp, 
     40 0 
     41}; 
     42#else 
     43static struct eXtl_protocol* socks_proto_tab[] = { 0 }; 
     44#endif 
     45 
    3446#ifdef OSIP_MT 
    3547static void *_eXosip_thread(void *arg); 
     
    7890void eXosip_masquerade_contact(const char *public_address, int port) 
    7991{ 
     92        int i; 
     93        struct eXtl_protocol* proto; 
     94 
    8095        eXtl_udp.tl_masquerade_contact(public_address, port); 
    8196        eXtl_tcp.tl_masquerade_contact(public_address, port); 
     97        for(i = 0; proto = socks_proto_tab[i]; i++) { 
     98                proto->tl_masquerade_contact(public_address, port); 
     99        } 
    82100#ifdef HAVE_OPENSSL_SSL_H 
    83101        eXtl_tls.tl_masquerade_contact(public_address, port); 
     
    276294        eXtl_udp.tl_free(); 
    277295        eXtl_tcp.tl_free(); 
     296        if (eXosip_new_transport()) 
     297        eXosip.eXtl->tl_free(); 
    278298#ifdef HAVE_OPENSSL_SSL_H 
    279299#if !(OPENSSL_VERSION_NUMBER < 0x00908000L) 
     
    598618        else if (transport == IPPROTO_TCP && secure == 0) 
    599619                snprintf(eXosip.transport, sizeof(eXosip.transport), "%s", "TCP"); 
    600         //FIXME: ce n'est peut être pas la meilleur maniÚre de la faire car du coup on ne peut pas avoir openssl et csl en meme temps 
    601         //utiliser secure == 1 pour openssl et secure == pour CSL 
    602620        else if (transport == IPPROTO_UDP) 
    603621                snprintf(eXosip.transport, sizeof(eXosip.transport), "%s", "DTLS-UDP"); 
     
    619637        return OSIP_SUCCESS; 
    620638} 
    621 #ifdef ENABLE_SOCKS 
    622 static struct eXtl_protocol* socks_proto_tab[] = { 
    623  &eXtl_socks_tcp, 
    624  &eXtl_socks_http, 
    625  &eXtl_socks_tcp2udp, 
    626  &eXtl_socks_http2udp, 
    627  0 
    628 }; 
    629 #else 
    630 static struct eXtl_protocol* socks_proto_tab[] = { 0 }; 
    631 #endif 
    632639 
    633640int 
  • libeXosip2/src/eXtl_socks.c

    r450 r508  
    33  Copyright (C) 2002,2003,2004,2005,2006,2007  Aymeric MOIZARD  - jack@atosc.org 
    44  Socks support Copyright (C) 2011  MBDSYS  - (vadim@mbdsys.com) 
    5    
     5 
    66  eXosip is free software; you can redistribute it and/or modify 
    77  it under the terms of the GNU General Public License as published by 
    88  the Free Software Foundation; either version 2 of the License, or 
    99  (at your option) any later version. 
    10    
     10 
    1111  eXosip is distributed in the hope that it will be useful, 
    1212  but WITHOUT ANY WARRANTY; without even the implied warranty of 
    1313  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    1414  GNU General Public License for more details. 
    15    
     15 
    1616  You should have received a copy of the GNU General Public License 
    1717  along with this program; if not, write to the Free Software 
    1818  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
    19 */ 
     19 */ 
    2020 
    2121 
     
    9292#endif 
    9393 
    94 extern struct eXtl_protocol eXtl_socks_tcp; 
    9594 
    9695static struct _socks_socket socks_socket_tab[EXOSIP_MAX_SOCKETS]; 
     
    186185 
    187186static socks_http_negotiate(struct _socks_socket *sk) 
    188 { 
     187                { 
    189188        char buf[4*1024]; 
    190189 
     
    192191 
    193192        snprintf(buf, sizeof(buf), "CONNECT %s:%d HTTP/1.1\r\n%s:%s\r\n\r\n", 
    194                 sk->remote_ip, sk->remote_port, (sk->socktype & SOCKST_UDPMASK) ? "UdpHost" : "Host", sk->remote_ip); 
     193                        sk->remote_ip, sk->remote_port, (sk->socktype & SOCKST_UDPMASK) ? "UdpHost" : "Host", sk->remote_ip); 
    195194 
    196195        ret = send(sk->socket, buf, strlen(buf), 0); 
     
    234233        } 
    235234        return -1; 
    236 } 
     235                } 
    237236 
    238237#ifdef _MSC_VER 
    239238#pragma pack(push, r1, 1) 
    240239__declspec(align(1)) struct socks5_req { 
    241        char    ver;          /* Version number */ 
    242        char    cmd;          /* Command */ 
    243        char    _nop;         /* Reserved */ 
    244        char    atp ;        /* Address type */ 
    245        uint32_t destip;    /* Dest address */ 
    246        uint16_t dport;    /* Dest port */ 
     240        char    ver;          /* Version number */ 
     241        char    cmd;          /* Command */ 
     242        char    _nop;         /* Reserved */ 
     243        char    atp ;        /* Address type */ 
     244        uint32_t destip;    /* Dest address */ 
     245        uint16_t dport;    /* Dest port */ 
    247246}; 
    248247#pragma pack(pop, r1) 
     
    325324 
    326325} 
    327 static socks_connect(struct _socks_socket *sk, const char *addr, int port) 
     326static int socks_connect(struct _socks_socket *sk, const char *addr, int port, int local_port) 
    328327{ 
    329328        struct addrinfo *addrinfo = NULL; 
     
    332331        int res; 
    333332 
     333        struct sockaddr_in si; 
     334 
    334335        res = eXosip_get_addrinfo(&addrinfo, 
    335                                                           socks_firewall_ip, 
    336                                                           atoi(socks_firewall_port), eXtl_socks_tcp.proto_num); 
     336                        socks_firewall_ip, 
     337                        atoi(socks_firewall_port), eXtl_socks_tcp.proto_num); 
    337338        if (res) 
    338339                return -1; 
     
    341342                if (curinfo->ai_protocol && curinfo->ai_protocol != IPPROTO_TCP) { 
    342343                        OSIP_TRACE(osip_trace 
    343                                            (__FILE__, __LINE__, OSIP_INFO2, NULL, 
    344                                                 "Skipping protocol %d\n", curinfo->ai_protocol)); 
     344                                        (__FILE__, __LINE__, OSIP_INFO2, NULL, 
     345                                                        "Skipping protocol %d\n", curinfo->ai_protocol)); 
    345346                        continue; 
    346347                } 
     
    358359        } 
    359360 
    360  
     361        memset(&si, 0, sizeof(si)); 
     362        si.sin_family = AF_INET; 
     363        si.sin_port = htons(local_port); 
     364 
     365        if (bind(sock, (struct sockaddr*) &si, sizeof(struct sockaddr_in))) { 
     366                OSIP_TRACE(osip_trace 
     367                                (__FILE__, __LINE__, OSIP_ERROR, NULL, 
     368                                                "Cannot bind socket %s!\n", strerror(ex_errno))); 
     369 
     370        } 
     371 
     372 
     373        //TODO do an async connect + timer at 3sec 
    361374        if ((sock >= 0) && !connect(sock, curinfo->ai_addr, curinfo->ai_addrlen)) { 
    362375                sk->socket = sock; 
     
    377390 
    378391static struct _socks_socket * 
    379 socks_connect_to(const char *host, int port, int mode) 
     392socks_connect_to(const char *host, int port, int local_port, int mode) 
    380393{ 
    381394        int pos; 
     
    386399                if (sk->socket == 0) { 
    387400                        sk->socktype = mode; 
    388                         if (!socks_connect(sk, host, port)) { 
     401                        if (!socks_connect(sk, host, port, local_port)) { 
    389402                                if (mode & SOCKST_UDPMASK) { 
    390403                                        sk->pbuf = osip_malloc(SIP_MESSAGE_MAX_LENGTH); 
     
    397410                        } 
    398411 
    399  
    400                 } 
    401         } 
    402          
     412                } 
     413        } 
     414 
    403415        return 0; 
    404416} 
     
    410422        int need_more = sizeof(sk->prefix.data) - sk->prefixlen; 
    411423 
     424        if (sk->pbuflen != sk->udplen) 
     425                return 0; 
     426 
    412427        t = recv(sk->socket, sk->prefix.buf+sk->prefixlen, need_more, 0); 
    413428        if (t <= 0) 
     
    446461} 
    447462 
     463static int socks_internal_read_udp(int socket, char *message, int *length) { 
     464 
     465        union { 
     466                int size; 
     467                char buf[4]; 
     468        } usize; 
     469 
     470        int i = recv(socket, usize.buf, 4, MSG_PEEK); 
     471        if (i < 0) { 
     472                /*OSIP_TRACE(osip_trace 
     473                                (__FILE__, __LINE__, OSIP_ERROR, NULL, 
     474                                                "Cannot read on socket %d %s!\n",socket,  strerror(errno)));*/ 
     475                errno = EWOULDBLOCK; 
     476                return -1; 
     477        } else if (i == 0) { 
     478                return 0; 
     479        } else { 
     480                if (i == 4) { 
     481                        usize.size = ntohl(usize.size); 
     482                } else { 
     483                        errno = EWOULDBLOCK; 
     484                        return -1; 
     485                } 
     486        } 
     487 
     488        i = recv(socket, message, usize.size + 4, MSG_PEEK); 
     489        if (i < 0) { 
     490                OSIP_TRACE(osip_trace 
     491                                (__FILE__, __LINE__, OSIP_ERROR, NULL, 
     492                                                "Cannot read %d bytes on socket %s!\n", usize.size + 4, strerror(errno))); 
     493                errno = EWOULDBLOCK; 
     494                return -1; 
     495        }else if (i == 0) 
     496                return 0; 
     497        else if (i > 0) { 
     498                if (usize.size + 4 != i) { 
     499                        errno = EWOULDBLOCK; 
     500                        return -1; 
     501                } else { 
     502 
     503                        i = recv(socket, message, 4, 0); 
     504                        i = recv(socket, message, usize.size, 0); 
     505                        *length = usize.size; 
     506 
     507                        return  i; 
     508                } 
     509        } 
     510 
     511        return 0; 
     512} 
     513 
     514int socks_tl_internal_read(int socket, char *message, int *length, int mode) { 
     515        if (mode & SOCKST_TCP2UDP) 
     516                return socks_internal_read_udp(socket, message, length); 
     517        return -1; 
     518} 
     519 
    448520static int 
    449521socks_tl_read_message(fd_set * osip_fdset) 
     
    460532 
    461533                if (sk->socket > 0 
    462                         && FD_ISSET(sk->socket, osip_fdset)) { 
     534                                && FD_ISSET(sk->socket, osip_fdset)) { 
    463535                        int i; 
    464536 
     
    474546                                                        sk->pbuf[sk->udplen] = 0; 
    475547                                                        _eXosip_handle_incoming_message(sk->pbuf, 
    476                                                                                                                         sk->udplen, 
    477                                                                                                                         sk->socket, 
    478                                                                                                                         sk->remote_ip, 
    479                                                                                                                         sk->remote_port); 
     548                                                                        sk->udplen, 
     549                                                                        sk->socket, 
     550                                                                        sk->remote_ip, 
     551                                                                        sk->remote_port); 
    480552                                                        sk->udplen = 0; 
    481553                                                        sk->pbuflen = 0; 
     
    504576                                        /* concat old data with new data */ 
    505577                                        sk->pbuf = 
    506                                                 (char *) osip_realloc(sk->pbuf, 
    507                                                                                           sk->pbuflen + i + 1); 
     578                                                        (char *) osip_realloc(sk->pbuf, 
     579                                                                        sk->pbuflen + i + 1); 
    508580                                        if (sk->pbuf == NULL) { 
    509581                                                OSIP_TRACE(osip_trace 
    510                                                                    (__FILE__, __LINE__, OSIP_ERROR, NULL, 
    511                                                                         "Reallocation error: (len=%i)", 
    512                                                                         sk->pbuflen + i + 1)); 
     582                                                                (__FILE__, __LINE__, OSIP_ERROR, NULL, 
     583                                                                                "Reallocation error: (len=%i)", 
     584                                                                                sk->pbuflen + i + 1)); 
    513585                                                sk->pbuflen = 0; 
    514586                                                continue;       /* give up: realloc issue */ 
     
    530602                                        /* a content-legnth MUST exist before the CRLFCRLF */ 
    531603                                        cl_header = 
    532                                                 osip_strcasestr(sk->pbuf, 
    533                                                                                 "\ncontent-length "); 
     604                                                        osip_strcasestr(sk->pbuf, 
     605                                                                        "\ncontent-length "); 
    534606                                        if (cl_header == NULL || cl_header > end_sip) 
    535607                                                cl_header = osip_strcasestr(sk->pbuf, "\ncontent-length:"); 
     
    551623                                                if (sk->pbuf == NULL) { 
    552624                                                        OSIP_TRACE(osip_trace 
    553                                                                            (__FILE__, __LINE__, OSIP_ERROR, NULL, 
    554                                                                                 "Reallocation error: (len=%i)", sk->pbuflen + 1)); 
     625                                                                        (__FILE__, __LINE__, OSIP_ERROR, NULL, 
     626                                                                                        "Reallocation error: (len=%i)", sk->pbuflen + 1)); 
    555627                                                        sk->pbuflen = 0; 
    556628                                                        break; 
     
    565637 
    566638                                        if (cl_size == 0 
    567                                                 || (cl_size > 0 && end_sip + 4 + cl_size <= sk->pbuf + sk->pbuflen)) { 
     639                                                        || (cl_size > 0 && end_sip + 4 + cl_size <= sk->pbuf + sk->pbuflen)) { 
    568640                                                /* we have beg_sip & end_sip */ 
    569641                                                _eXosip_handle_incoming_message(sk->pbuf, 
    570                                                                                                                 end_sip + 4 + cl_size - sk->pbuf, 
    571                                                                                                                 sk->socket, 
    572                                                                                                                 sk->remote_ip, 
    573                                                                                                                 sk->remote_port); 
     642                                                                end_sip + 4 + cl_size - sk->pbuf, 
     643                                                                sk->socket, 
     644                                                                sk->remote_ip, 
     645                                                                sk->remote_port); 
    574646 
    575647                                                if (sk->pbuflen - (end_sip + 4 + cl_size -  sk->pbuf) == 0) { 
    576648                                                        end_sip = NULL; 
    577649                                                        OSIP_TRACE(osip_trace 
    578                                                                            (__FILE__, __LINE__, OSIP_INFO2, NULL, 
    579                                                                                 "All TCP data consumed\n")); 
     650                                                                        (__FILE__, __LINE__, OSIP_INFO2, NULL, 
     651                                                                                        "All TCP data consumed\n")); 
    580652                                                        sk->pbuflen = 0; 
    581653                                                        osip_free(sk->pbuf); 
     
    594666                                                if (sk->pbuf == NULL) { 
    595667                                                        OSIP_TRACE(osip_trace 
    596                                                                            (__FILE__, __LINE__, OSIP_ERROR, NULL, 
    597                                                                                 "Reallocation error: (len=%i)", 
    598                                                                                 sk->pbuflen + 1)); 
     668                                                                        (__FILE__, __LINE__, OSIP_ERROR, NULL, 
     669                                                                                        "Reallocation error: (len=%i)", 
     670                                                                                        sk->pbuflen + 1)); 
    599671                                                        sk->pbuflen = 0; 
    600672                                                        break; 
     
    607679                                        end_sip = NULL; 
    608680                                        OSIP_TRACE(osip_trace 
    609                                                            (__FILE__, __LINE__, OSIP_INFO2, NULL, 
    610                                                                 "Uncomplete TCP data (%s)\n", buf)); 
     681                                                        (__FILE__, __LINE__, OSIP_INFO2, NULL, 
     682                                                                        "Uncomplete TCP data (%s)\n", buf)); 
    611683                                        continue; 
    612684                                } 
     
    617689                                } 
    618690#else 
    619                         if (i > 5) { 
    620                                 osip_strncpy(buf + i, "\0", 1); 
    621                                 OSIP_TRACE(osip_trace 
    622                                                    (__FILE__, __LINE__, OSIP_INFO2, NULL, 
    623                                                         "Received TCP message: \n%s\n", buf)); 
    624                                 _eXosip_handle_incoming_message(buf, i, 
    625                                                                                                 sk->socket, 
    626                                                                                                 sk->remote_ip, 
    627                                                                                                 sk->remote_port); 
     691                                if (i > 5) { 
     692                                        osip_strncpy(buf + i, "\0", 1); 
     693                                        OSIP_TRACE(osip_trace 
     694                                                        (__FILE__, __LINE__, OSIP_INFO2, NULL, 
     695                                                                        "Received TCP message: \n%s\n", buf)); 
     696                                        _eXosip_handle_incoming_message(buf, i, 
     697                                                        sk->socket, 
     698                                                        sk->remote_ip, 
     699                                                        sk->remote_port); 
    628700#endif 
    629                         } else if (i < 0) { 
    630                                 int status = ex_errno; 
    631                                 if (status != EAGAIN) { 
     701                                } else if (i < 0) { 
     702                                        int status = ex_errno; 
     703                                        if (status != EAGAIN) { 
     704                                                OSIP_TRACE(osip_trace 
     705                                                                (__FILE__, __LINE__, OSIP_ERROR, NULL, 
     706                                                                                "Could not read socket (%s)- close it\n", 
     707                                                                                strerror(status))); 
     708                                                closesocket(sk->socket); 
     709                                                if (sk->pbuf) 
     710                                                        osip_free(sk->pbuf); 
     711                                                memset(sk, 0, sizeof(socks_socket_tab[pos])); 
     712                                        } 
     713                                } else if (i == 0) { 
    632714                                        OSIP_TRACE(osip_trace 
    633                                                            (__FILE__, __LINE__, OSIP_ERROR, NULL, 
    634                                                                 "Could not read socket (%s)- close it\n", 
    635                                                                 strerror(status))); 
     715                                                        (__FILE__, __LINE__, OSIP_INFO1, NULL, 
     716                                                                        "End of stream (read 0 byte from %s:%i)\n", 
     717                                                                        sk->remote_ip, 
     718                                                                        sk->remote_port)); 
    636719                                        closesocket(sk->socket); 
    637720                                        if (sk->pbuf) 
     
    639722                                        memset(sk, 0, sizeof(socks_socket_tab[pos])); 
    640723                                } 
    641                         } else if (i == 0) { 
     724#ifndef MINISIZE 
     725                                else { 
     726                                        /* we expect at least one byte, otherwise there's no doubt that it is not a sip message ! */ 
     727                                        OSIP_TRACE(osip_trace 
     728                                                        (__FILE__, __LINE__, OSIP_INFO1, NULL, 
     729                                                                        "Dummy SIP message received (size=%i)\n", i)); 
     730                                } 
     731#endif 
     732                        } 
     733                } 
     734 
     735                if (buf != NULL) 
     736                        osip_free(buf); 
     737 
     738                return OSIP_SUCCESS; 
     739        } 
     740 
     741        static int _socks_tl_find_socket(char *host, int port) 
     742        { 
     743                int pos; 
     744 
     745                for (pos = 0; pos < EXOSIP_MAX_SOCKETS; pos++) { 
     746                        struct _socks_socket *sk = &socks_socket_tab[pos]; 
     747 
     748                        if (sk->socket != 0) { 
     749                                if (0 == osip_strcasecmp(sk->remote_ip, host) 
     750                                                && port == sk->remote_port) 
     751                                        return sk->socket; 
     752                        } 
     753                } 
     754                return -1; 
     755        } 
     756 
     757        static int _socks_tl_is_connected(int sock) 
     758        { 
     759                int res; 
     760                struct timeval tv; 
     761                fd_set wrset; 
     762                int valopt; 
     763                socklen_t sock_len; 
     764                tv.tv_sec = SOCKET_TIMEOUT / 1000; 
     765                tv.tv_usec = (SOCKET_TIMEOUT % 1000) * 1000; 
     766 
     767                FD_ZERO(&wrset); 
     768                FD_SET(sock, &wrset); 
     769 
     770                res = select(sock + 1, NULL, &wrset, NULL, &tv); 
     771                if (res > 0) { 
     772                        sock_len = sizeof(int); 
     773                        if (getsockopt(sock, SOL_SOCKET, SO_ERROR, (void *) (&valopt), &sock_len) 
     774                                        == 0) { 
     775                                if (valopt) { 
     776                                        OSIP_TRACE(osip_trace 
     777                                                        (__FILE__, __LINE__, OSIP_INFO2, NULL, 
     778                                                                        "Cannot connect socket node / %s[%d]\n", 
     779                                                                        strerror(ex_errno), ex_errno)); 
     780                                        return -1; 
     781                                } else { 
     782                                        return 0; 
     783                                } 
     784                        } else { 
    642785                                OSIP_TRACE(osip_trace 
    643                                                    (__FILE__, __LINE__, OSIP_INFO1, NULL, 
    644                                                         "End of stream (read 0 byte from %s:%i)\n", 
    645                                                         sk->remote_ip, 
    646                                                         sk->remote_port)); 
     786                                                (__FILE__, __LINE__, OSIP_INFO2, NULL, 
     787                                                                "Cannot connect socket node / error in getsockopt %s[%d]\n", 
     788                                                                strerror(ex_errno), ex_errno)); 
     789                                return -1; 
     790                        } 
     791                } else if (res < 0) { 
     792                        OSIP_TRACE(osip_trace 
     793                                        (__FILE__, __LINE__, OSIP_INFO2, NULL, 
     794                                                        "Cannot connect socket node / error in select %s[%d]\n", 
     795                                                        strerror(ex_errno), ex_errno)); 
     796                        return -1; 
     797                } else { 
     798                        OSIP_TRACE(osip_trace 
     799                                        (__FILE__, __LINE__, OSIP_INFO2, NULL, 
     800                                                        "Cannot connect socket node / select timeout (%d ms)\n", 
     801                                                        SOCKET_TIMEOUT)); 
     802                        return 1; 
     803                } 
     804        } 
     805 
     806        static int _socks_tl_connect_socket2(char *host, int port, int local_port, int mode, int *tabx) 
     807        { 
     808                int res; 
     809                int sock = -1; 
     810                struct _socks_socket *sk = 0; 
     811                int i = _socks_tl_find_socket(host, port); 
     812                if (i >= 0) { 
     813                        return i; 
     814                } 
     815 
     816                OSIP_TRACE(osip_trace 
     817                                (__FILE__, __LINE__, OSIP_INFO2, NULL, 
     818                                                "New binding with %s:%d local_port %d mode %d\n", host, port, local_port, mode)); 
     819 
     820 
     821                sk = socks_connect_to(host, port, local_port, mode); 
     822                if (!sk) 
     823                        return -1; 
     824 
     825 
     826                sock = sk->socket; 
     827 
     828 
     829                if (sock > 0) { 
     830                        if (*tabx) 
     831                                *tabx = sk - socks_socket_tab; 
     832                        return sock; 
     833                } 
     834 
     835                return -1; 
     836        } 
     837 
     838        int socks_tl_connect_socket(char *host, int dst_port, int local_port, int mode) { 
     839                int i; 
     840                int sock = _socks_tl_connect_socket2(host, dst_port, local_port, mode, &i); 
     841                OSIP_TRACE(osip_trace 
     842                                                                (__FILE__, __LINE__, OSIP_INFO1, NULL, 
     843                                                                                "socks_tl_connect_socket res %i \n", 
     844                                                                                sock)); 
     845                return sock; 
     846        } 
     847 
     848        static int socks_tl_fix_message(osip_message_t *sip,  int tlx) 
     849        { 
     850                char  portstr[16]; 
     851 
     852                osip_contact_t *ctct = (osip_contact_t*) osip_list_get(&sip->contacts, 0); 
     853                osip_via_t *via = (osip_via_t *) osip_list_get(&sip->vias, 0); 
     854 
     855                snprintf(portstr,16,"%d", socks_socket_tab[tlx].public_port); 
     856 
     857 
     858                if (ctct && ctct->url) { 
     859                        if (ctct->url->port) 
     860                                osip_free(ctct->url->port); 
     861 
     862                        ctct->url->port = osip_strdup(portstr); 
     863                        sip->message_property = 2; 
     864                } 
     865 
     866                if (via) { 
     867                        if (via->port) 
     868                                osip_free(via->port); 
     869                        via->port = osip_strdup(portstr); 
     870                        sip->message_property = 2; 
     871                } 
     872 
     873                return 0; 
     874 
     875        } 
     876 
     877        int socks_tl_closesocket(int socket) { 
     878 
     879                int pos; 
     880 
     881                for (pos = 0; pos < EXOSIP_MAX_SOCKETS; pos++) { 
     882                        struct _socks_socket *sk = &socks_socket_tab[pos]; 
     883 
     884                        if (sk->socket == socket) { 
     885                                OSIP_TRACE(osip_trace 
     886                                                (__FILE__, __LINE__, OSIP_INFO1, NULL, 
     887                                                                "End of stream (read 0 byte from %s:%i)\n", 
     888                                                                sk->remote_ip, 
     889                                                                sk->remote_port)); 
    647890                                closesocket(sk->socket); 
    648891                                if (sk->pbuf) 
    649892                                        osip_free(sk->pbuf); 
    650893                                memset(sk, 0, sizeof(socks_socket_tab[pos])); 
     894                                break; 
    651895                        } 
    652 #ifndef MINISIZE 
    653                         else { 
    654                                 /* we expect at least one byte, otherwise there's no doubt that it is not a sip message ! */ 
    655                                 OSIP_TRACE(osip_trace 
    656                                                    (__FILE__, __LINE__, OSIP_INFO1, NULL, 
    657                                                         "Dummy SIP message received (size=%i)\n", i)); 
    658                         } 
    659 #endif 
    660                 } 
    661         } 
    662  
    663         if (buf != NULL) 
    664                 osip_free(buf); 
    665  
    666         return OSIP_SUCCESS; 
    667 } 
    668  
    669 static int _socks_tl_find_socket(char *host, int port) 
    670 { 
    671         int pos; 
    672  
    673         for (pos = 0; pos < EXOSIP_MAX_SOCKETS; pos++) { 
    674                 struct _socks_socket *sk = &socks_socket_tab[pos]; 
    675  
    676                 if (sk->socket != 0) { 
    677                         if (0 == osip_strcasecmp(sk->remote_ip, host) 
    678                                 && port == sk->remote_port) 
    679                                 return sk->socket; 
    680                 } 
    681         } 
    682         return -1; 
    683 } 
    684  
    685 static int _socks_tl_is_connected(int sock) 
    686 { 
    687         int res; 
    688         struct timeval tv; 
    689         fd_set wrset; 
    690         int valopt; 
    691         socklen_t sock_len; 
    692         tv.tv_sec = SOCKET_TIMEOUT / 1000; 
    693         tv.tv_usec = (SOCKET_TIMEOUT % 1000) * 1000; 
    694  
    695         FD_ZERO(&wrset); 
    696         FD_SET(sock, &wrset); 
    697  
    698         res = select(sock + 1, NULL, &wrset, NULL, &tv); 
    699         if (res > 0) { 
    700                 sock_len = sizeof(int); 
    701                 if (getsockopt(sock, SOL_SOCKET, SO_ERROR, (void *) (&valopt), &sock_len) 
    702                         == 0) { 
    703                         if (valopt) { 
    704                                 OSIP_TRACE(osip_trace 
    705                                                    (__FILE__, __LINE__, OSIP_INFO2, NULL, 
    706                                                         "Cannot connect socket node / %s[%d]\n", 
    707                                                         strerror(ex_errno), ex_errno)); 
     896                } 
     897 
     898                return 0; 
     899        } 
     900 
     901        int socks_tl_internal_send(int out_socket, char *message, int length, int mode) { 
     902                int i; 
     903 
     904                if (mode & SOCKST_UDPMASK) { 
     905                        struct socks_udp_prefix *pfx; 
     906 
     907                        pfx = (struct socks_udp_prefix *)osip_malloc(length + sizeof(*pfx)); 
     908                        if (!pfx) 
    708909                                return -1; 
    709                         } else { 
    710                                 return 0; 
    711                         } 
    712                 } else { 
    713                         OSIP_TRACE(osip_trace 
    714                                            (__FILE__, __LINE__, OSIP_INFO2, NULL, 
    715                                                 "Cannot connect socket node / error in getsockopt %s[%d]\n", 
    716                                                 strerror(ex_errno), ex_errno)); 
    717                         return -1; 
    718                 } 
    719         } else if (res < 0) { 
    720                 OSIP_TRACE(osip_trace 
    721                                    (__FILE__, __LINE__, OSIP_INFO2, NULL, 
    722                                         "Cannot connect socket node / error in select %s[%d]\n", 
    723                                         strerror(ex_errno), ex_errno)); 
    724                 return -1; 
    725         } else { 
    726                 OSIP_TRACE(osip_trace 
    727                                    (__FILE__, __LINE__, OSIP_INFO2, NULL, 
    728                                         "Cannot connect socket node / select timeout (%d ms)\n", 
    729                                         SOCKET_TIMEOUT)); 
    730                 return 1; 
    731         } 
    732 } 
    733  
    734 static int _socks_tl_connect_socket2(char *host, int port, int mode, int *tabx) 
    735 { 
    736         int res; 
    737         int sock = -1; 
    738         struct _socks_socket *sk = 0; 
    739         int i = _socks_tl_find_socket(host, port); 
    740         if (i >= 0) { 
    741                 return i; 
    742         } 
    743  
    744         OSIP_TRACE(osip_trace 
    745                            (__FILE__, __LINE__, OSIP_INFO2, NULL, 
    746                                 "New binding with %s\n", host)); 
    747  
    748  
    749         sk = socks_connect_to(host, port, mode); 
    750         if (!sk) 
    751                 return -1; 
    752  
    753  
    754         sock = sk->socket; 
    755  
    756  
    757         if (sock > 0) { 
    758                 if (*tabx) 
    759                         *tabx = sk - socks_socket_tab; 
    760                 return sock; 
    761         } 
    762  
    763         return -1; 
    764 } 
    765  
    766 static int socks_tl_fix_message(osip_message_t *sip,  int tlx) 
    767 { 
    768         char  portstr[16]; 
    769  
    770         osip_contact_t *ctct = (osip_contact_t*) osip_list_get(&sip->contacts, 0); 
    771         osip_via_t *via = (osip_via_t *) osip_list_get(&sip->vias, 0); 
    772  
    773         snprintf(portstr,16,"%d", socks_socket_tab[tlx].public_port); 
    774  
    775  
    776         if (ctct && ctct->url) { 
    777                 if (ctct->url->port) 
    778                         osip_free(ctct->url->port); 
    779  
    780                 ctct->url->port = osip_strdup(portstr); 
    781                 sip->message_property = 2; 
    782         } 
    783  
    784         if (via) { 
    785                 if (via->port) 
    786                         osip_free(via->port); 
    787                 via->port = osip_strdup(portstr); 
    788                 sip->message_property = 2; 
    789         } 
    790  
    791         return 0; 
    792  
    793 } 
    794  
    795 static int 
    796 socks_tl_send_message2(osip_transaction_t * tr, osip_message_t * sip, char *host, 
    797                                         int port, int out_socket, int mode) 
    798 { 
    799         size_t length = 0; 
    800         char *message = NULL; 
    801         int i; 
    802  
    803         if (host == NULL) { 
    804                 host = sip->req_uri->host; 
    805                 if (sip->req_uri->port != NULL) 
    806                         port = osip_atoi(sip->req_uri->port); 
    807                 else 
    808                         port = 5060; 
    809         } 
    810  
    811         /* Step 1: find existing socket to send message */ 
    812         if (out_socket <= 0) { 
    813                 out_socket = _socks_tl_find_socket(host, port); 
    814  
    815                 /* Step 2: create new socket with host:port */ 
    816                 if (out_socket <= 0) { 
    817                         int tlx; 
    818  
    819                         out_socket = _socks_tl_connect_socket2(host, port, mode, &tlx); 
    820                         if (out_socket > 0) { 
    821  
    822                                 socks_tl_fix_message(sip, tlx); 
    823                         } 
    824                 } 
    825         } else { 
    826                 OSIP_TRACE(osip_trace(__FILE__, __LINE__, OSIP_INFO1, NULL, 
    827                                                           "reusing REQUEST connection (to dest=%s:%i)\n", 
    828                                                           host, port)); 
    829         } 
    830  
    831         if (out_socket <= 0) { 
    832                 osip_free(message); 
    833                 return -1; 
    834         } 
    835  
    836         /* remove preloaded route if there is no tag in the To header 
    837          */ 
    838         { 
    839                 osip_route_t *route = NULL; 
    840                 osip_generic_param_t *tag = NULL; 
    841                 osip_message_get_route(sip, 0, &route); 
    842  
    843                 osip_to_get_tag(sip->to, &tag); 
    844                 if (tag == NULL && route != NULL && route->url != NULL) { 
    845                         osip_list_remove(&sip->routes, 0); 
    846                 } 
    847                 i = osip_message_to_str(sip, &message, &length); 
    848                 if (tag == NULL && route != NULL && route->url != NULL) { 
    849                         osip_list_add(&sip->routes, route, 0); 
    850                 } 
    851         } 
    852  
    853         if (i != 0 || length <= 0) { 
    854                 return -1; 
    855         } 
    856  
    857  
    858         i = _socks_tl_is_connected(out_socket); 
    859         if (i > 0) { 
    860                 time_t now; 
    861                 now = time(NULL); 
    862                 OSIP_TRACE(osip_trace 
    863                                    (__FILE__, __LINE__, OSIP_INFO2, NULL, 
    864                                         "socket node:%s, socket %d [pos=%d], in progress\n", 
    865                                         host, out_socket, -1)); 
    866                 osip_free(message); 
    867                 if (tr != NULL && now - tr->birth_time > 10) 
    868                         return -1; 
    869                 return 1; 
    870         } else if (i == 0) { 
    871                 OSIP_TRACE(osip_trace 
    872                                    (__FILE__, __LINE__, OSIP_INFO2, NULL, 
    873                                         "socket node:%s , socket %d [pos=%d], connected\n", 
    874                                         host, out_socket, -1)); 
    875         } else { 
    876                 OSIP_TRACE(osip_trace 
    877                                    (__FILE__, __LINE__, OSIP_ERROR, NULL, 
    878                                         "socket node:%s, socket %d [pos=%d], socket error\n", 
    879                                         host, out_socket, -1)); 
    880                 osip_free(message); 
    881                 return -1; 
    882         } 
    883  
    884         OSIP_TRACE(osip_trace(__FILE__, __LINE__, OSIP_INFO1, NULL, 
    885                                                   "Message sent: (to dest=%s:%i) \n%s\n", 
    886                                                   host, port, message)); 
    887  
    888         if (mode & SOCKST_UDPMASK) { 
    889                 struct socks_udp_prefix *pfx; 
    890  
    891                 pfx = (struct socks_udp_prefix *)osip_malloc(length + sizeof(*pfx)); 
    892                 if (!pfx) 
    893                         return -1; 
    894                 memcpy(pfx+1, message, length); 
    895                 pfx->len = htonl(length); 
    896                 length += sizeof(*pfx); 
    897                 osip_free(message); 
    898                 message = (char *)pfx; 
    899         } 
    900  
    901         while (1) { 
    902                 i = send(out_socket, (const void *) message, length, 0); 
    903                 if (i < 0) { 
    904                         int status = ex_errno; 
    905                         if (EAGAIN == status || EWOULDBLOCK == status) { 
    906                                 struct timeval tv; 
    907                                 fd_set wrset; 
    908                                 tv.tv_sec = SOCKET_TIMEOUT / 1000; 
    909                                 tv.tv_usec = (SOCKET_TIMEOUT % 1000) * 1000; 
    910  
    911                                 FD_ZERO(&wrset); 
    912                                 FD_SET(out_socket, &wrset); 
    913  
    914                                 i = select(out_socket + 1, NULL, &wrset, NULL, &tv); 
    915                                 if (i > 0) { 
    916                                         continue; 
    917                                 } else if (i < 0) { 
     910                        memcpy(pfx+1, message, length); 
     911                        pfx->len = htonl(length); 
     912                        length += sizeof(*pfx); 
     913                        //osip_free(message); 
     914                        message = (char *)pfx; 
     915                } 
     916 
     917                int sent = 0; 
     918                while (sent < length) { 
     919                        i = send(out_socket, (const void *) message + sent, length - sent, 0); 
     920                        if (i < 0) { 
     921                                int status = ex_errno; 
     922                                if (EAGAIN == status || EWOULDBLOCK == status) { 
     923                                        struct timeval tv; 
     924                                        fd_set wrset; 
     925                                        tv.tv_sec = SOCKET_TIMEOUT / 1000; 
     926                                        tv.tv_usec = (SOCKET_TIMEOUT % 1000) * 1000; 
     927 
     928                                        FD_ZERO(&wrset); 
     929                                        FD_SET(out_socket, &wrset); 
     930 
     931                                        i = select(out_socket + 1, NULL, &wrset, NULL, &tv); 
     932                                        if (i > 0) { 
     933                                                continue; 
     934                                        } else if (i < 0) { 
     935                                                OSIP_TRACE(osip_trace(__FILE__, __LINE__, OSIP_ERROR, NULL, 
     936                                                                "TCP select error: %s\n", 
     937                                                                strerror(ex_errno))); 
     938                                                //osip_free(message); 
     939                                                return -1; 
     940                                        } else { 
     941                                                OSIP_TRACE(osip_trace(__FILE__, __LINE__, OSIP_ERROR, NULL, 
     942                                                                "TCP timeout: %d ms\n", SOCKET_TIMEOUT)); 
     943                                                //osip_free(message); 
     944                                                return -1; 
     945                                        } 
     946                                } else { 
     947                                        /* SIP_NETWORK_ERROR; */ 
    918948                                        OSIP_TRACE(osip_trace(__FILE__, __LINE__, OSIP_ERROR, NULL, 
    919                                                                                   "TCP select error: %s\n", 
    920                                                                                   strerror(ex_errno))); 
    921                                         osip_free(message); 
    922                                         return -1; 
    923                                 } else { 
    924                                         OSIP_TRACE(osip_trace(__FILE__, __LINE__, OSIP_ERROR, NULL, 
    925                                                                                   "TCP timeout: %d ms\n", SOCKET_TIMEOUT)); 
    926                                         osip_free(message); 
     949                                                        "TCP error: %s\n", strerror(status))); 
     950                                        //osip_free(message); 
    927951                                        return -1; 
    928952                                } 
    929953                        } else { 
    930                                 /* SIP_NETWORK_ERROR; */ 
    931                                 OSIP_TRACE(osip_trace(__FILE__, __LINE__, OSIP_ERROR, NULL, 
    932                                                                           "TCP error: %s\n", strerror(status))); 
    933                                 osip_free(message); 
     954                                sent += i; 
     955                        } 
     956                } 
     957 
     958                //osip_free(message); 
     959                return OSIP_SUCCESS; 
     960        } 
     961 
     962        static int 
     963        socks_tl_send_message2(osip_transaction_t * tr, osip_message_t * sip, char *host, 
     964                        int port, int out_socket, int mode) 
     965        { 
     966                size_t length = 0; 
     967                char *message = NULL; 
     968                int i; 
     969 
     970                if (host == NULL) { 
     971                        host = sip->req_uri->host; 
     972                        if (sip->req_uri->port != NULL) 
     973                                port = osip_atoi(sip->req_uri->port); 
     974                        else 
     975                                port = 5060; 
     976                } 
     977 
     978                /* Step 1: find existing socket to send message */ 
     979                if (out_socket <= 0) { 
     980                        out_socket = _socks_tl_find_socket(host, port); 
     981 
     982                        /* Step 2: create new socket with host:port */ 
     983                        if (out_socket <= 0) { 
     984                                int tlx; 
     985 
     986                                out_socket = _socks_tl_connect_socket2(host, port, mode, 0, &tlx); 
     987                                if (out_socket > 0) { 
     988 
     989                                        socks_tl_fix_message(sip, tlx); 
     990                                } 
     991                        } 
     992                } else { 
     993                        OSIP_TRACE(osip_trace(__FILE__, __LINE__, OSIP_INFO1, NULL, 
     994                                        "reusing REQUEST connection (to dest=%s:%i)\n", 
     995                                        host, port)); 
     996                } 
     997 
     998                if (out_socket <= 0) { 
     999                        return -1; 
     1000                } 
     1001 
     1002                /* remove preloaded route if there is no tag in the To header 
     1003                 */ 
     1004                { 
     1005                        osip_route_t *route = NULL; 
     1006                        osip_generic_param_t *tag = NULL; 
     1007                        osip_message_get_route(sip, 0, &route); 
     1008 
     1009                        osip_to_get_tag(sip->to, &tag); 
     1010                        if (tag == NULL && route != NULL && route->url != NULL) { 
     1011                                osip_list_remove(&sip->routes, 0); 
     1012                        } 
     1013                        i = osip_message_to_str(sip, &message, &length); 
     1014                        if (tag == NULL && route != NULL && route->url != NULL) { 
     1015                                osip_list_add(&sip->routes, route, 0); 
     1016                        } 
     1017                } 
     1018 
     1019                if (i != 0 || length <= 0) { 
     1020                        return -1; 
     1021                } 
     1022 
     1023 
     1024                i = _socks_tl_is_connected(out_socket); 
     1025                if (i > 0) { 
     1026                        time_t now; 
     1027                        now = time(NULL); 
     1028                        OSIP_TRACE(osip_trace 
     1029                                        (__FILE__, __LINE__, OSIP_INFO2, NULL, 
     1030                                                        "socket node:%s, socket %d [pos=%d], in progress\n", 
     1031                                                        host, out_socket, -1)); 
     1032                        osip_free(message); 
     1033                        if (tr != NULL && now - tr->birth_time > 10) 
    9341034                                return -1; 
    935                         } 
    936                 } 
    937                 break; 
    938         } 
    939  
    940         osip_free(message); 
    941         return OSIP_SUCCESS; 
    942 } 
    943  
    944 static int 
    945 socks_tcp_tl_send_message(osip_transaction_t * tr, osip_message_t * sip, char *host, 
    946                                         int port, int out_socket) 
    947 { 
    948         return socks_tl_send_message2(tr, sip, host, port, out_socket, SOCKST_TCP); 
    949 } 
    950  
    951 static int 
    952 http_tl_send_message(osip_transaction_t * tr, osip_message_t * sip, char *host, 
    953                                         int port, int out_socket) 
    954 { 
    955         return socks_tl_send_message2(tr, sip, host, port, out_socket, SOCKST_HTTP); 
    956 } 
    957  
    958  
    959 static int 
    960 socks_udp_tl_send_message(osip_transaction_t * tr, osip_message_t * sip, char *host, 
    961                                         int port, int out_socket) 
    962 { 
    963         return socks_tl_send_message2(tr, sip, host, port, out_socket, SOCKST_TCP2UDP); 
    964 } 
    965  
    966 static int 
    967 http_udp_tl_send_message(osip_transaction_t * tr, osip_message_t * sip, char *host, 
    968                                         int port, int out_socket) 
    969 { 
    970         return socks_tl_send_message2(tr, sip, host, port, out_socket, SOCKST_HTTP2UDP); 
    971 } 
    972  
    973  
    974  
    975 static int socks_tl_keepalive(void) 
    976 { 
    977         return 1; 
    978 } 
    979  
    980 static int socks_tl_set_socket(int socket) 
    981 { 
    982 //      socks_socket = socket; 
    983  
    984         return OSIP_SUCCESS; 
    985 } 
    986  
    987  
    988 static int socks_tl_masquerade_contact(const char *public_address, int port) 
    989 { 
    990         if (public_address == NULL || public_address[0] == '\0') { 
    991                 memset(socks_firewall_ip, '\0', sizeof(socks_firewall_ip)); 
    992                 memset(socks_firewall_port, '\0', sizeof(socks_firewall_port)); 
    993                 if (eXtl_socks_tcp.proto_port > 0) 
    994                         snprintf(socks_firewall_port, sizeof(socks_firewall_port), "%i", 
    995                                          eXtl_socks_tcp.proto_port); 
     1035                        return 1; 
     1036                } else if (i == 0) { 
     1037                        OSIP_TRACE(osip_trace 
     1038                                        (__FILE__, __LINE__, OSIP_INFO2, NULL, 
     1039                                                        "socket node:%s , socket %d [pos=%d], connected\n", 
     1040                                                        host, out_socket, -1)); 
     1041                } else { 
     1042                        OSIP_TRACE(osip_trace 
     1043                                        (__FILE__, __LINE__, OSIP_ERROR, NULL, 
     1044                                                        "socket node:%s, socket %d [pos=%d], socket error\n", 
     1045                                                        host, out_socket, -1)); 
     1046                        osip_free(message); 
     1047                        return -1; 
     1048                } 
     1049 
     1050                int res = socks_tl_internal_send(out_socket, message, length, mode); 
     1051                if (res == OSIP_SUCCESS) 
     1052                        OSIP_TRACE(osip_trace(__FILE__, __LINE__, OSIP_INFO1, NULL, 
     1053                                        "Message sent: (to dest=%s:%i) \n%s\n", 
     1054                                        host, port, message)); 
     1055                return res; 
     1056        } 
     1057 
     1058        static int 
     1059        socks_tcp_tl_send_message(osip_transaction_t * tr, osip_message_t * sip, char *host, 
     1060                        int port, int out_socket) 
     1061        { 
     1062                return socks_tl_send_message2(tr, sip, host, port, out_socket, SOCKST_TCP); 
     1063        } 
     1064 
     1065        static int 
     1066        http_tl_send_message(osip_transaction_t * tr, osip_message_t * sip, char *host, 
     1067                        int port, int out_socket) 
     1068        { 
     1069                return socks_tl_send_message2(tr, sip, host, port, out_socket, SOCKST_HTTP); 
     1070        } 
     1071 
     1072 
     1073        static int 
     1074        socks_udp_tl_send_message(osip_transaction_t * tr, osip_message_t * sip, char *host, 
     1075                        int port, int out_socket) 
     1076        { 
     1077                return socks_tl_send_message2(tr, sip, host, port, out_socket, SOCKST_TCP2UDP); 
     1078        } 
     1079 
     1080        static int 
     1081        http_udp_tl_send_message(osip_transaction_t * tr, osip_message_t * sip, char *host, 
     1082                        int port, int out_socket) 
     1083        { 
     1084                return socks_tl_send_message2(tr, sip, host, port, out_socket, SOCKST_HTTP2UDP); 
     1085        } 
     1086 
     1087 
     1088 
     1089        static int socks_tl_keepalive(void) 
     1090        { 
     1091                return 1; 
     1092        } 
     1093 
     1094        static int socks_tl_set_socket(int socket) 
     1095        { 
     1096                //      socks_socket = socket; 
     1097 
    9961098                return OSIP_SUCCESS; 
    9971099        } 
    998         snprintf(socks_firewall_ip, sizeof(socks_firewall_ip), "%s", public_address); 
    999         if (port > 0) { 
    1000                 snprintf(socks_firewall_port, sizeof(socks_firewall_port), "%i", port); 
    1001         } 
    1002         return OSIP_SUCCESS; 
    1003 } 
    1004  
    1005 static int 
    1006 socks_tl_get_masquerade_contact(char *ip, int ip_size, char *port, int port_size) 
    1007 { 
    1008     int pos; 
    1009     struct _socks_socket *sk = 0; 
    1010  
    1011         memset(ip, 0, ip_size); 
    1012         memset(port, 0, port_size); 
    1013         for (pos = 0; pos < EXOSIP_MAX_SOCKETS; pos++) { 
    1014                 sk = &socks_socket_tab[pos]; 
    1015                 if (sk->socket > 0) 
    1016                         break; 
    1017         } 
    1018  
    1019         if (!sk) 
    1020                 return -1; 
    1021  
    1022         if (socks_firewall_ip[0] != '\0') 
    1023                 snprintf(ip, ip_size, "%s", sk->public_ip); 
    1024  
    1025         if (socks_firewall_port[0] != '\0') 
    1026                 snprintf(port, port_size, "%d", sk->public_port); 
    1027         return OSIP_SUCCESS; 
    1028 } 
    1029  
    1030 struct eXtl_protocol eXtl_socks_tcp = { 
    1031         1, 
    1032         7070, 
    1033         "SOCKS+TCP", 
    1034         "0.0.0.0", 
    1035         IPPROTO_TCP, 
    1036         AF_INET, 
    1037         0, 
    1038         0, 
    1039  
    1040         &socks_tl_init, 
    1041         &socks_tl_free, 
    1042         &socks_tl_open, 
    1043         &socks_tl_set_fdset, 
    1044         &socks_tl_read_message, 
    1045         &socks_tcp_tl_send_message, 
    1046         &socks_tl_keepalive, 
    1047         &socks_tl_set_socket, 
    1048         &socks_tl_masquerade_contact, 
    1049         &socks_tl_get_masquerade_contact 
    1050 }; 
    1051  
    1052 struct eXtl_protocol eXtl_socks_http = { 
    1053         1, 
    1054         7070, 
    1055         "HTTP+TCP", 
    1056         "0.0.0.0", 
    1057         IPPROTO_TCP, 
    1058         AF_INET, 
    1059         0, 
    1060         0, 
    1061  
    1062         &socks_tl_init, 
    1063         &socks_tl_free, 
    1064         &socks_tl_open, 
    1065         &socks_tl_set_fdset, 
    1066         &socks_tl_read_message, 
    1067         &http_tl_send_message, 
    1068         &socks_tl_keepalive, 
    1069         &socks_tl_set_socket, 
    1070         &socks_tl_masquerade_contact, 
    1071         &socks_tl_get_masquerade_contact 
    1072 }; 
    1073  
    1074 struct eXtl_protocol eXtl_socks_tcp2udp = { 
    1075         1, 
    1076         7070, 
    1077         "SOCKS+UDP", 
    1078         "0.0.0.0", 
    1079         IPPROTO_UDP, 
    1080         AF_INET, 
    1081         0, 
    1082         0, 
    1083  
    1084         &socks_tl_init, 
    1085         &socks_tl_free, 
    1086         &socks_tl_open, 
    1087         &socks_tl_set_fdset, 
    1088         &socks_tl_read_message, 
    1089         &socks_udp_tl_send_message, 
    1090         &socks_tl_keepalive, 
    1091         &socks_tl_set_socket, 
    1092         &socks_tl_masquerade_contact, 
    1093         &socks_tl_get_masquerade_contact 
    1094 }; 
    1095  
    1096 struct eXtl_protocol eXtl_socks_http2udp = { 
    1097         1, 
    1098         7070, 
    1099         "HTTP+UDP", 
    1100         "0.0.0.0", 
    1101         IPPROTO_UDP, 
    1102         AF_INET, 
    1103         0, 
    1104         0, 
    1105  
    1106         &socks_tl_init, 
    1107         &socks_tl_free, 
    1108         &socks_tl_open, 
    1109         &socks_tl_set_fdset, 
    1110         &socks_tl_read_message, 
    1111         &http_udp_tl_send_message, 
    1112         &socks_tl_keepalive, 
    1113         &socks_tl_set_socket, 
    1114         &socks_tl_masquerade_contact, 
    1115         &socks_tl_get_masquerade_contact 
    1116 }; 
    1117  
    1118  
     1100 
     1101 
     1102        static int socks_tl_masquerade_contact(const char *public_address, int port) 
     1103        { 
     1104                if (public_address == NULL || public_address[0] == '\0') { 
     1105                        memset(socks_firewall_ip, '\0', sizeof(socks_firewall_ip)); 
     1106                        memset(socks_firewall_port, '\0', sizeof(socks_firewall_port)); 
     1107                        if (eXtl_socks_tcp.proto_port > 0) 
     1108                                snprintf(socks_firewall_port, sizeof(socks_firewall_port), "%i", 
     1109                                                eXtl_socks_tcp.proto_port); 
     1110                        return OSIP_SUCCESS; 
     1111                } 
     1112                snprintf(socks_firewall_ip, sizeof(socks_firewall_ip), "%s", public_address); 
     1113                if (port > 0) { 
     1114                        snprintf(socks_firewall_port, sizeof(socks_firewall_port), "%i", port); 
     1115                } 
     1116                return OSIP_SUCCESS; 
     1117        } 
     1118 
     1119        static int 
     1120        socks_tl_get_masquerade_contact(char *ip, int ip_size, char *port, int port_size) 
     1121        { 
     1122                int pos; 
     1123                struct _socks_socket *sk = 0; 
     1124 
     1125                memset(ip, 0, ip_size); 
     1126                memset(port, 0, port_size); 
     1127                for (pos = 0; pos < EXOSIP_MAX_SOCKETS; pos++) { 
     1128                        sk = &socks_socket_tab[pos]; 
     1129                        if (sk->socket > 0) 
     1130                                break; 
     1131                } 
     1132 
     1133                if (!sk) 
     1134                        return -1; 
     1135 
     1136                if (socks_firewall_ip[0] != '\0') 
     1137                        snprintf(ip, ip_size, "%s", sk->public_ip); 
     1138 
     1139                if (socks_firewall_port[0] != '\0') 
     1140                        snprintf(port, port_size, "%d", sk->public_port); 
     1141                return OSIP_SUCCESS; 
     1142        } 
     1143 
     1144        struct eXtl_protocol eXtl_socks_tcp = { 
     1145                        1, 
     1146                        7070, 
     1147                        "SOCKS+TCP", 
     1148                        "0.0.0.0", 
     1149                        IPPROTO_TCP, 
     1150                        AF_INET, 
     1151                        0, 
     1152                        0, 
     1153 
     1154                        &socks_tl_init, 
     1155                        &socks_tl_free, 
     1156                        &socks_tl_open, 
     1157                        &socks_tl_set_fdset, 
     1158                        &socks_tl_read_message, 
     1159                        &socks_tcp_tl_send_message, 
     1160                        &socks_tl_keepalive, 
     1161                        &socks_tl_set_socket, 
     1162                        &socks_tl_masquerade_contact, 
     1163                        &socks_tl_get_masquerade_contact 
     1164        }; 
     1165 
     1166        struct eXtl_protocol eXtl_socks_http = { 
     1167                        1, 
     1168                        7070, 
     1169                        "HTTP+TCP", 
     1170                        "0.0.0.0", 
     1171                        IPPROTO_TCP, 
     1172                        AF_INET, 
     1173                        0, 
     1174                        0, 
     1175 
     1176                        &socks_tl_init, 
     1177                        &socks_tl_free, 
     1178                        &socks_tl_open, 
     1179                        &socks_tl_set_fdset, 
     1180                        &socks_tl_read_message, 
     1181                        &http_tl_send_message, 
     1182                        &socks_tl_keepalive, 
     1183                        &socks_tl_set_socket, 
     1184                        &socks_tl_masquerade_contact, 
     1185                        &socks_tl_get_masquerade_contact 
     1186        }; 
     1187 
     1188        struct eXtl_protocol eXtl_socks_tcp2udp = { 
     1189                        1, 
     1190                        7070, 
     1191                        "SOCKS+UDP", 
     1192                        "0.0.0.0", 
     1193                        IPPROTO_UDP, 
     1194                        AF_INET, 
     1195                        0, 
     1196                        0, 
     1197 
     1198                        &socks_tl_init, 
     1199                        &socks_tl_free, 
     1200                        &socks_tl_open, 
     1201                        &socks_tl_set_fdset, 
     1202                        &socks_tl_read_message, 
     1203                        &socks_udp_tl_send_message, 
     1204                        &socks_tl_keepalive, 
     1205                        &socks_tl_set_socket, 
     1206                        &socks_tl_masquerade_contact, 
     1207                        &socks_tl_get_masquerade_contact 
     1208        }; 
     1209 
     1210        struct eXtl_protocol eXtl_socks_http2udp = { 
     1211                        1, 
     1212                        7070, 
     1213                        "HTTP+UDP", 
     1214                        "0.0.0.0", 
     1215                        IPPROTO_UDP, 
     1216                        AF_INET, 
     1217                        0, 
     1218                        0, 
     1219 
     1220                        &socks_tl_init, 
     1221                        &socks_tl_free, 
     1222                        &socks_tl_open, 
     1223                        &socks_tl_set_fdset, 
     1224                        &socks_tl_read_message, 
     1225                        &http_udp_tl_send_message, 
     1226                        &socks_tl_keepalive, 
     1227                        &socks_tl_set_socket, 
     1228                        &socks_tl_masquerade_contact, 
     1229                        &socks_tl_get_masquerade_contact 
     1230        }; 
     1231 
     1232 
  • libeXosip2/src/udp.c

    r422 r508  
    101101 
    102102 
    103 static eXosip_new_transport() 
     103int eXosip_new_transport() 
    104104{ 
    105105        return !(  eXosip.eXtl == &eXtl_udp 
  • phapi/CMakeLists.txt

    r478 r508  
    105105) 
    106106 
     107add_definitions(-DENABLE_SOCKS=1) 
     108set(PHAPI_SRCS ${PHAPI_SRCS} ph_socks_rtp.c) 
     109 
    107110if(USE_CSL) 
    108111  add_definitions( -DHAVE_CSL ) 
     
    114117        add_definitions(-DISL_DLLENTRY=) 
    115118  endif(WIN32) 
    116 else(USE_CSL) 
    117   add_definitions(-DENABLE_SOCKS=1) 
    118   set(PHAPI_SRCS ${PHAPI_SRCS} ph_socks_rtp.c) 
    119119endif(USE_CSL) 
    120120   
  • phapi/phapi.c

    r507 r508  
    11171117} 
    11181118 
    1119 ph_prepare_stream_ports(phcall_t *ca) 
     1119void ph_prepare_stream_ports(phcall_t *ca) 
    11201120{ 
    11211121          struct tunnel_info *tun; 
  • phtest/phtests.h

    r502 r508  
    4545        char sipport[512]; 
    4646        char addrbook[512]; 
     47        char tunnel[512]; 
    4748 
    4849        int regtime; 
  • phtest/phtests_conf.cpp

    r361 r508  
    136136        strcpy(conf.audiodev_out, tmp); 
    137137 
     138        if (!defs->ReadString("tunnel", tmp)) 
     139                tmp = ""; 
     140        strcpy(conf.tunnel, tmp); 
     141 
    138142        if (!defs->ReadInt("regtime", port)) 
    139143                port = 600; 
  • phtest/phtests_funcs.cpp

    r506 r508  
    6969        if (conf->jitter) 
    7070          phconf->jitterdepth = conf->jitter; 
     71        if (conf->tunnel[0]) { 
     72                phconf->use_tunnel = PH_TUNNEL_USE | PH_RTP_TUNNEL_USE; 
     73                strcpy(phconf->sip_tunnel_uris, conf->tunnel); 
     74                strcpy(phconf->rtp_tunnel_uris, conf->tunnel); 
     75        } 
     76 
    7177        testsphapi.setDebugLevel(phTestsDebugLevel); 
    7278        res = testsphapi.init(); 
Note: See TracChangeset for help on using the changeset viewer.