LCOV - code coverage report
Current view: top level - src/lib/srv/mod-udpd - mod-udpd-backend.c (source / functions) Hit Total Coverage
Test: liquidwar6.info Lines: 77 99 77.8 %
Date: 2011-12-24 Functions: 12 15 80.0 %
Branches: 11 26 42.3 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :   Liquid War 6 is a unique multiplayer wargame.
       3                 :            :   Copyright (C)  2005, 2006, 2007, 2008, 2009, 2010, 2011  Christian Mauduit <ufoot@ufoot.org>
       4                 :            : 
       5                 :            :   This program is free software; you can redistribute it and/or modify
       6                 :            :   it under the terms of the GNU General Public License as published by
       7                 :            :   the Free Software Foundation, either version 3 of the License, or
       8                 :            :   (at your option) any later version.
       9                 :            : 
      10                 :            :   This program is distributed in the hope that it will be useful,
      11                 :            :   but WITHOUT ANY WARRANTY; without even the implied warranty of
      12                 :            :   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      13                 :            :   GNU General Public License for more details.
      14                 :            : 
      15                 :            :   You should have received a copy of the GNU General Public License
      16                 :            :   along with this program.  If not, see <http://www.gnu.org/licenses/>.
      17                 :            : 
      18                 :            : 
      19                 :            :   Liquid War 6 homepage : http://www.gnu.org/software/liquidwar6/
      20                 :            :   Contact author        : ufoot@ufoot.org
      21                 :            : */
      22                 :            : 
      23                 :            : #ifdef HAVE_CONFIG_H
      24                 :            : #include "config.h"
      25                 :            : #endif
      26                 :            : 
      27                 :            : #include "../srv.h"
      28                 :            : #include "mod-udpd.h"
      29                 :            : #include "mod-udpd-internal.h"
      30                 :            : 
      31                 :            : /*
      32                 :            :  * http://www.gnu.org/prep/standards/html_node/Dynamic-Plug_002dIn-Interfaces.html
      33                 :            :  */
      34                 :            : void
      35                 :          0 : mod_udpd_is_GPL_compatible ()
      36                 :            : {
      37                 :          0 : }
      38                 :            : 
      39                 :            : static void *
      40                 :         27 : _init (int argc, char *argv[], lw6srv_listener_t * listener)
      41                 :            : {
      42                 :         27 :   _udpd_context_t *udpd_context = _mod_udpd_init (argc, argv, listener);
      43                 :            : 
      44                 :         27 :   return (void *) udpd_context;
      45                 :            : }
      46                 :            : 
      47                 :            : static void
      48                 :         27 : _quit (void *srv_context)
      49                 :            : {
      50                 :         27 :   _udpd_context_t *udpd_context = (_udpd_context_t *) srv_context;
      51                 :            : 
      52         [ +  - ]:         27 :   if (udpd_context)
      53                 :            :     {
      54                 :         27 :       _mod_udpd_quit (udpd_context);
      55                 :            :     }
      56                 :         27 : }
      57                 :            : 
      58                 :            : static int
      59                 :         17 : _analyse_tcp (void *srv_context, lw6srv_tcp_accepter_t * tcp_accepter,
      60                 :            :               lw6nod_info_t * node_info,
      61                 :            :               u_int64_t * remote_id, char **remote_url)
      62                 :            : {
      63                 :         17 :   _udpd_context_t *udpd_context = (_udpd_context_t *) srv_context;
      64                 :         17 :   int ret = 0;
      65                 :            : 
      66         [ +  - ]:         17 :   if (udpd_context)
      67                 :            :     {
      68                 :         17 :       ret =
      69                 :            :         _mod_udpd_analyse_tcp (udpd_context, tcp_accepter, node_info,
      70                 :            :                                remote_id, remote_url);
      71                 :            :     }
      72                 :            : 
      73                 :         17 :   return ret;
      74                 :            : }
      75                 :            : 
      76                 :            : static int
      77                 :         90 : _analyse_udp (void *srv_context, lw6srv_udp_buffer_t * udp_buffer,
      78                 :            :               lw6nod_info_t * node_info,
      79                 :            :               u_int64_t * remote_id, char **remote_url)
      80                 :            : {
      81                 :         90 :   _udpd_context_t *udpd_context = (_udpd_context_t *) srv_context;
      82                 :         90 :   int ret = 0;
      83                 :            : 
      84         [ +  - ]:         90 :   if (udpd_context)
      85                 :            :     {
      86                 :         90 :       ret =
      87                 :            :         _mod_udpd_analyse_udp (udpd_context, udp_buffer, node_info, remote_id,
      88                 :            :                                remote_url);
      89                 :            :     }
      90                 :            : 
      91                 :         90 :   return ret;
      92                 :            : }
      93                 :            : 
      94                 :            : static int
      95                 :         17 : _process_oob (void *srv_context, lw6nod_info_t * node_info,
      96                 :            :               lw6srv_oob_data_t * oob_data)
      97                 :            : {
      98                 :         17 :   _udpd_context_t *udpd_context = (_udpd_context_t *) srv_context;
      99                 :         17 :   int ret = 0;
     100                 :            : 
     101         [ +  - ]:         17 :   if (udpd_context)
     102                 :            :     {
     103                 :         17 :       ret = _mod_udpd_process_oob (udpd_context, node_info, oob_data);
     104                 :            :     }
     105                 :            : 
     106                 :         17 :   return ret;
     107                 :            : }
     108                 :            : 
     109                 :            : static lw6cnx_connection_t *
     110                 :         22 : _open (void *srv_context, lw6srv_listener_t * listener, char *local_url,
     111                 :            :        char *remote_url, char *remote_ip,
     112                 :            :        int remote_port, char *password,
     113                 :            :        u_int64_t local_id, u_int64_t remote_id, int dns_ok,
     114                 :            :        int network_reliability, lw6cnx_recv_callback_t recv_callback_func,
     115                 :            :        void *recv_callback_data)
     116                 :            : {
     117                 :         22 :   _udpd_context_t *udpd_context = (_udpd_context_t *) srv_context;
     118                 :         22 :   lw6cnx_connection_t *ret = NULL;
     119                 :            : 
     120         [ +  - ]:         22 :   if (udpd_context)
     121                 :            :     {
     122                 :         22 :       ret =
     123                 :            :         _mod_udpd_open (udpd_context, listener, local_url, remote_url,
     124                 :            :                         remote_ip, remote_port, password, local_id, remote_id,
     125                 :            :                         dns_ok, network_reliability, recv_callback_func,
     126                 :            :                         recv_callback_data);
     127                 :            :     }
     128                 :            : 
     129                 :         22 :   return ret;
     130                 :            : }
     131                 :            : 
     132                 :            : static int
     133                 :          0 : _feed_with_tcp (void *srv_context, lw6cnx_connection_t * connection,
     134                 :            :                 lw6srv_tcp_accepter_t * tcp_accepter)
     135                 :            : {
     136                 :          0 :   _udpd_context_t *udpd_context = (_udpd_context_t *) srv_context;
     137                 :          0 :   int ret = 0;
     138                 :            : 
     139         [ #  # ]:          0 :   if (connection)
     140                 :            :     {
     141                 :          0 :       ret = _mod_udpd_feed_with_tcp (udpd_context, connection, tcp_accepter);
     142                 :            :     }
     143                 :            : 
     144                 :          0 :   return ret;
     145                 :            : }
     146                 :            : 
     147                 :            : static int
     148                 :         56 : _feed_with_udp (void *srv_context, lw6cnx_connection_t * connection,
     149                 :            :                 lw6srv_udp_buffer_t * udp_buffer)
     150                 :            : {
     151                 :         56 :   _udpd_context_t *udpd_context = (_udpd_context_t *) srv_context;
     152                 :         56 :   int ret = 0;
     153                 :            : 
     154         [ +  - ]:         56 :   if (connection)
     155                 :            :     {
     156                 :         56 :       ret = _mod_udpd_feed_with_udp (udpd_context, connection, udp_buffer);
     157                 :            :     }
     158                 :            : 
     159                 :         56 :   return ret;
     160                 :            : }
     161                 :            : 
     162                 :            : static void
     163                 :         22 : _close (void *srv_context, lw6cnx_connection_t * connection)
     164                 :            : {
     165                 :         22 :   _udpd_context_t *udpd_context = (_udpd_context_t *) srv_context;
     166                 :            : 
     167         [ +  - ]:         22 :   if (udpd_context)
     168                 :            :     {
     169                 :         22 :       _mod_udpd_close (udpd_context, connection);
     170                 :            :     }
     171                 :         22 : }
     172                 :            : 
     173                 :            : static int
     174                 :         73 : _send (void *srv_context, lw6cnx_connection_t * connection,
     175                 :            :        u_int32_t physical_ticket_sig, u_int32_t logical_ticket_sig,
     176                 :            :        u_int64_t logical_from_id, u_int64_t logical_to_id, char *message)
     177                 :            : {
     178                 :         73 :   _udpd_context_t *udpd_context = (_udpd_context_t *) srv_context;
     179                 :         73 :   int ret = 0;
     180                 :            : 
     181         [ +  - ]:         73 :   if (udpd_context)
     182                 :            :     {
     183                 :         73 :       ret =
     184                 :            :         _mod_udpd_send (udpd_context, connection, physical_ticket_sig,
     185                 :            :                         logical_ticket_sig, logical_from_id, logical_to_id,
     186                 :            :                         message);
     187                 :            :     }
     188                 :            : 
     189                 :         73 :   return ret;
     190                 :            : }
     191                 :            : 
     192                 :            : static void
     193                 :        236 : _poll (void *srv_context, lw6cnx_connection_t * connection)
     194                 :            : {
     195                 :        236 :   _udpd_context_t *udpd_context = (_udpd_context_t *) srv_context;
     196                 :            : 
     197         [ +  - ]:        236 :   if (udpd_context)
     198                 :            :     {
     199                 :        236 :       _mod_udpd_poll (udpd_context, connection);
     200                 :            :     }
     201                 :        236 : }
     202                 :            : 
     203                 :            : static char *
     204                 :         22 : _repr (void *srv_context, lw6cnx_connection_t * connection)
     205                 :            : {
     206                 :         22 :   _udpd_context_t *udpd_context = (_udpd_context_t *) srv_context;
     207                 :         22 :   char *ret = NULL;
     208                 :            : 
     209         [ +  - ]:         22 :   if (udpd_context)
     210                 :            :     {
     211                 :         22 :       ret = _mod_udpd_repr (udpd_context, connection);
     212                 :            :     }
     213                 :            : 
     214                 :         22 :   return ret;
     215                 :            : }
     216                 :            : 
     217                 :            : lw6sys_module_pedigree_t *
     218                 :          0 : mod_udpd_get_pedigree ()
     219                 :            : {
     220                 :          0 :   lw6sys_module_pedigree_t *module_pedigree = NULL;
     221                 :            : 
     222                 :          0 :   module_pedigree =
     223                 :            :     (lw6sys_module_pedigree_t *)
     224                 :            :     LW6SYS_CALLOC (sizeof (lw6sys_module_pedigree_t));
     225         [ #  # ]:          0 :   if (module_pedigree)
     226                 :            :     {
     227                 :          0 :       module_pedigree->id = "udpd";
     228                 :          0 :       module_pedigree->category = "srv";
     229                 :          0 :       module_pedigree->name = _("UDPD");
     230                 :          0 :       module_pedigree->readme =
     231                 :            :         _x_ ("Basic UDP/IP server, the fastest way to communicate.");
     232                 :          0 :       module_pedigree->version = VERSION;
     233                 :          0 :       module_pedigree->copyright =
     234                 :            :         "Copyright (C)  2011  Christian Mauduit <ufoot@ufoot.org>";
     235                 :          0 :       module_pedigree->license = "GPLv3+ (GNU GPL version 3 or later)";
     236                 :          0 :       module_pedigree->date = __DATE__;
     237                 :          0 :       module_pedigree->time = __TIME__;
     238                 :            :     }
     239                 :            : 
     240                 :          0 :   return module_pedigree;
     241                 :            : }
     242                 :            : 
     243                 :            : lw6srv_backend_t *
     244                 :         27 : mod_udpd_create_backend ()
     245                 :            : {
     246                 :            :   lw6srv_backend_t *backend;
     247                 :            : 
     248                 :         27 :   backend = LW6SYS_MALLOC (sizeof (lw6srv_backend_t));
     249         [ +  - ]:         27 :   if (backend)
     250                 :            :     {
     251                 :         27 :       memset (backend, 0, sizeof (lw6srv_backend_t));
     252                 :            : 
     253                 :         27 :       backend->init = _init;
     254                 :         27 :       backend->quit = _quit;
     255                 :         27 :       backend->analyse_tcp = _analyse_tcp;
     256                 :         27 :       backend->analyse_udp = _analyse_udp;
     257                 :         27 :       backend->process_oob = _process_oob;
     258                 :         27 :       backend->open = _open;
     259                 :         27 :       backend->feed_with_tcp = _feed_with_tcp;
     260                 :         27 :       backend->feed_with_udp = _feed_with_udp;
     261                 :         27 :       backend->close = _close;
     262                 :         27 :       backend->send = _send;
     263                 :         27 :       backend->poll = _poll;
     264                 :         27 :       backend->repr = _repr;
     265                 :            :     }
     266                 :            : 
     267                 :         27 :   return backend;
     268                 :            : }

Generated by: LCOV version 1.9