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: 84 108 77.8 %
Date: 2014-03-26 Functions: 13 17 76.5 %

          Line data    Source code
       1             : /*
       2             :   Liquid War 6 is a unique multiplayer wargame.
       3             :   Copyright (C)  2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014  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             :  * mod_udpd_is_GPL_compatible
      33             :  *
      34             :  * Defined to tell mod_udpd is compatible with GNU General Public License
      35             :  * Of course it is. This function does nothing, but the fact it's declared
      36             :  * makes its GPL compatibility obvious. Having this declared is required.
      37             :  *
      38             :  * Return value: none
      39             :  */
      40             : void
      41           0 : mod_udpd_is_GPL_compatible ()
      42             : {
      43             : /*
      44             :  * http://www.gnu.org/prep/standards/html_node/Dynamic-Plug_002dIn-Interfaces.html
      45             :  */
      46           0 : }
      47             : 
      48             : /**
      49             :  * mod_udpd_is_dlclose_safe
      50             :  *
      51             :  * Defined to tell mod_udpd has no dlclose issue, once can safely call
      52             :  * lt_dlclose on it when done with it, without risking any segfault.
      53             :  * Some other LW6 modules/shared libraries do have this problem.
      54             :  *
      55             :  * Return value: none
      56             :  */
      57             : void
      58           0 : mod_udpd_is_dlclose_safe ()
      59             : {
      60           0 : }
      61             : 
      62             : static void *
      63          47 : _init (int argc, const char *argv[], lw6cnx_properties_t * properties,
      64             :        lw6srv_listener_t * listener)
      65             : {
      66          47 :   _mod_udpd_context_t *udpd_context =
      67             :     _mod_udpd_init (argc, argv, properties, listener);
      68             : 
      69          47 :   return (void *) udpd_context;
      70             : }
      71             : 
      72             : static void
      73          47 : _quit (void *srv_context)
      74             : {
      75          47 :   _mod_udpd_context_t *udpd_context = (_mod_udpd_context_t *) srv_context;
      76             : 
      77          47 :   if (udpd_context)
      78             :     {
      79          47 :       _mod_udpd_quit (udpd_context);
      80             :     }
      81          47 : }
      82             : 
      83             : static int
      84     3741308 : _analyse_tcp (void *srv_context, lw6srv_tcp_accepter_t * tcp_accepter,
      85             :               lw6nod_info_t * node_info,
      86             :               u_int64_t * remote_id, char **remote_url)
      87             : {
      88     3741308 :   _mod_udpd_context_t *udpd_context = (_mod_udpd_context_t *) srv_context;
      89     3741308 :   int ret = 0;
      90             : 
      91     3741308 :   if (udpd_context)
      92             :     {
      93     3741308 :       ret =
      94             :         _mod_udpd_analyse_tcp (udpd_context, tcp_accepter, node_info,
      95             :                                remote_id, remote_url);
      96             :     }
      97             : 
      98     3741308 :   return ret;
      99             : }
     100             : 
     101             : static int
     102        4017 : _analyse_udp (void *srv_context, lw6srv_udp_buffer_t * udp_buffer,
     103             :               lw6nod_info_t * node_info,
     104             :               u_int64_t * remote_id, char **remote_url)
     105             : {
     106        4017 :   _mod_udpd_context_t *udpd_context = (_mod_udpd_context_t *) srv_context;
     107        4017 :   int ret = 0;
     108             : 
     109        4017 :   if (udpd_context)
     110             :     {
     111        4017 :       ret =
     112             :         _mod_udpd_analyse_udp (udpd_context, udp_buffer, node_info, remote_id,
     113             :                                remote_url);
     114             :     }
     115             : 
     116        4017 :   return ret;
     117             : }
     118             : 
     119             : static int
     120         289 : _process_oob (void *srv_context, lw6nod_info_t * node_info,
     121             :               lw6srv_oob_data_t * oob_data)
     122             : {
     123         289 :   _mod_udpd_context_t *udpd_context = (_mod_udpd_context_t *) srv_context;
     124         289 :   int ret = 0;
     125             : 
     126         289 :   if (udpd_context)
     127             :     {
     128         289 :       ret = _mod_udpd_process_oob (udpd_context, node_info, oob_data);
     129             :     }
     130             : 
     131         289 :   return ret;
     132             : }
     133             : 
     134             : static lw6cnx_connection_t *
     135          33 : _open (void *srv_context, lw6srv_listener_t * listener, const char *local_url,
     136             :        const char *remote_url, const char *remote_ip,
     137             :        int remote_port, const char *password,
     138             :        u_int64_t local_id, u_int64_t remote_id, int dns_ok,
     139             :        int network_reliability, lw6cnx_recv_callback_t recv_callback_func,
     140             :        void *recv_callback_data)
     141             : {
     142          33 :   _mod_udpd_context_t *udpd_context = (_mod_udpd_context_t *) srv_context;
     143          33 :   lw6cnx_connection_t *ret = NULL;
     144             : 
     145          33 :   if (udpd_context)
     146             :     {
     147          33 :       ret =
     148             :         _mod_udpd_open (udpd_context, listener, local_url, remote_url,
     149             :                         remote_ip, remote_port, password, local_id, remote_id,
     150             :                         dns_ok, network_reliability, recv_callback_func,
     151             :                         recv_callback_data);
     152             :     }
     153             : 
     154          33 :   return ret;
     155             : }
     156             : 
     157             : static int
     158           0 : _feed_with_tcp (void *srv_context, lw6cnx_connection_t * connection,
     159             :                 lw6srv_tcp_accepter_t * tcp_accepter)
     160             : {
     161           0 :   _mod_udpd_context_t *udpd_context = (_mod_udpd_context_t *) srv_context;
     162           0 :   int ret = 0;
     163             : 
     164           0 :   if (connection)
     165             :     {
     166           0 :       ret = _mod_udpd_feed_with_tcp (udpd_context, connection, tcp_accepter);
     167             :     }
     168             : 
     169           0 :   return ret;
     170             : }
     171             : 
     172             : static int
     173        3662 : _feed_with_udp (void *srv_context, lw6cnx_connection_t * connection,
     174             :                 lw6srv_udp_buffer_t * udp_buffer)
     175             : {
     176        3662 :   _mod_udpd_context_t *udpd_context = (_mod_udpd_context_t *) srv_context;
     177        3662 :   int ret = 0;
     178             : 
     179        3662 :   if (connection)
     180             :     {
     181        3662 :       ret = _mod_udpd_feed_with_udp (udpd_context, connection, udp_buffer);
     182             :     }
     183             : 
     184        3662 :   return ret;
     185             : }
     186             : 
     187             : static void
     188          33 : _close (void *srv_context, lw6cnx_connection_t * connection)
     189             : {
     190          33 :   _mod_udpd_context_t *udpd_context = (_mod_udpd_context_t *) srv_context;
     191             : 
     192          33 :   if (udpd_context)
     193             :     {
     194          33 :       _mod_udpd_close (udpd_context, connection);
     195             :     }
     196          33 : }
     197             : 
     198             : static int
     199        9934 : _send (void *srv_context, lw6cnx_connection_t * connection, int64_t now,
     200             :        u_int32_t physical_ticket_sig, u_int32_t logical_ticket_sig,
     201             :        u_int64_t logical_from_id, u_int64_t logical_to_id,
     202             :        const char *message)
     203             : {
     204        9934 :   _mod_udpd_context_t *udpd_context = (_mod_udpd_context_t *) srv_context;
     205        9934 :   int ret = 0;
     206             : 
     207        9934 :   if (udpd_context)
     208             :     {
     209        9934 :       ret =
     210             :         _mod_udpd_send (udpd_context, connection, now, physical_ticket_sig,
     211             :                         logical_ticket_sig, logical_from_id, logical_to_id,
     212             :                         message);
     213             :     }
     214             : 
     215        9934 :   return ret;
     216             : }
     217             : 
     218             : static int
     219      523290 : _can_send (void *srv_context, lw6cnx_connection_t * connection)
     220             : {
     221      523290 :   _mod_udpd_context_t *udpd_context = (_mod_udpd_context_t *) srv_context;
     222      523290 :   int ret = 0;
     223             : 
     224      523290 :   if (udpd_context)
     225             :     {
     226      523290 :       ret = _mod_udpd_can_send (udpd_context, connection);
     227             :     }
     228             : 
     229      523290 :   return ret;
     230             : }
     231             : 
     232             : static void
     233     3572604 : _poll (void *srv_context, lw6cnx_connection_t * connection)
     234             : {
     235     3572604 :   _mod_udpd_context_t *udpd_context = (_mod_udpd_context_t *) srv_context;
     236             : 
     237     3572604 :   if (udpd_context)
     238             :     {
     239     3572604 :       _mod_udpd_poll (udpd_context, connection);
     240             :     }
     241     3572604 : }
     242             : 
     243             : static char *
     244          33 : _repr (void *srv_context, lw6cnx_connection_t * connection)
     245             : {
     246          33 :   _mod_udpd_context_t *udpd_context = (_mod_udpd_context_t *) srv_context;
     247          33 :   char *ret = NULL;
     248             : 
     249          33 :   if (udpd_context)
     250             :     {
     251          33 :       ret = _mod_udpd_repr (udpd_context, connection);
     252             :     }
     253             : 
     254          33 :   return ret;
     255             : }
     256             : 
     257             : lw6sys_module_pedigree_t *
     258           0 : mod_udpd_get_pedigree ()
     259             : {
     260           0 :   lw6sys_module_pedigree_t *module_pedigree = NULL;
     261             : 
     262           0 :   module_pedigree =
     263             :     (lw6sys_module_pedigree_t *)
     264             :     LW6SYS_CALLOC (sizeof (lw6sys_module_pedigree_t));
     265           0 :   if (module_pedigree)
     266             :     {
     267           0 :       module_pedigree->id = MOD_UDPD_BACKEND_ID;
     268           0 :       module_pedigree->category = "srv";
     269           0 :       module_pedigree->name = _("UDPD");
     270           0 :       module_pedigree->readme =
     271             :         _x_ ("Basic UDP/IP server, the fastest way to communicate.");
     272           0 :       module_pedigree->version = VERSION;
     273           0 :       module_pedigree->copyright =
     274             :         "Copyright (C)  2014  Christian Mauduit <ufoot@ufoot.org>";
     275           0 :       module_pedigree->license = "GPLv3+ (GNU GPL version 3 or later)";
     276           0 :       module_pedigree->date = __DATE__;
     277           0 :       module_pedigree->time = __TIME__;
     278             :     }
     279             : 
     280           0 :   return module_pedigree;
     281             : }
     282             : 
     283             : lw6srv_backend_t *
     284          47 : mod_udpd_create_backend ()
     285             : {
     286             :   lw6srv_backend_t *backend;
     287             : 
     288          47 :   backend = LW6SYS_MALLOC (sizeof (lw6srv_backend_t));
     289          47 :   if (backend)
     290             :     {
     291          47 :       memset (backend, 0, sizeof (lw6srv_backend_t));
     292             : 
     293          47 :       backend->init = _init;
     294          47 :       backend->quit = _quit;
     295          47 :       backend->analyse_tcp = _analyse_tcp;
     296          47 :       backend->analyse_udp = _analyse_udp;
     297          47 :       backend->process_oob = _process_oob;
     298          47 :       backend->open = _open;
     299          47 :       backend->feed_with_tcp = _feed_with_tcp;
     300          47 :       backend->feed_with_udp = _feed_with_udp;
     301          47 :       backend->close = _close;
     302          47 :       backend->send = _send;
     303          47 :       backend->can_send = _can_send;
     304          47 :       backend->poll = _poll;
     305          47 :       backend->repr = _repr;
     306             :     }
     307             : 
     308          47 :   return backend;
     309             : }

Generated by: LCOV version 1.10