LCOV - code coverage report
Current view: top level - src/lib/srv/mod-udpd - mod-udpd-oob.c (source / functions) Hit Total Coverage
Test: liquidwar6.info Lines: 41 44 93.2 %
Date: 2011-12-24 Functions: 2 2 100.0 %
Branches: 18 28 64.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-internal.h"
      29                 :            : 
      30                 :            : int
      31                 :         17 : _mod_udpd_process_oob (_udpd_context_t * udpd_context,
      32                 :            :                        lw6nod_info_t * node_info,
      33                 :            :                        lw6srv_oob_data_t * oob_data)
      34                 :            : {
      35                 :         17 :   int ret = 0;
      36                 :         17 :   char *request_line = NULL;
      37                 :         17 :   int syntax_ok = 0;
      38                 :         17 :   char *command = NULL;
      39                 :         17 :   int password_ok = 0;
      40                 :         17 :   char *given_public_url = NULL;
      41                 :         17 :   char *response = NULL;
      42                 :            : 
      43                 :         17 :   lw6sys_log (LW6SYS_LOG_DEBUG, _x_ ("process udpd oob"));
      44         [ +  - ]:         17 :   if (_mod_udpd_oob_should_continue (udpd_context, oob_data))
      45                 :            :     {
      46                 :         17 :       request_line = oob_data->first_line;
      47         [ +  - ]:         17 :       if (request_line)
      48                 :            :         {
      49         [ +  + ]:         17 :           if (lw6msg_oob_analyse_request (&syntax_ok, &command, &password_ok,
      50                 :            :                                           &given_public_url, request_line,
      51                 :            :                                           node_info->const_info.url,
      52                 :            :                                           node_info->const_info.password))
      53                 :            :             {
      54         [ +  + ]:         16 :               if (lw6sys_str_is_same_no_case (command, LW6MSG_OOB_PING))
      55                 :            :                 {
      56                 :         12 :                   lw6sys_log (LW6SYS_LOG_INFO,
      57                 :            :                               _x_ ("mod_udpd %s response to %s:%d"),
      58                 :            :                               LW6MSG_OOB_PONG, oob_data->remote_ip,
      59                 :            :                               oob_data->remote_port);
      60                 :         12 :                   response = lw6msg_oob_generate_pong (node_info);
      61                 :            :                 }
      62         [ +  + ]:         16 :               if (lw6sys_str_is_same_no_case (command, LW6MSG_OOB_INFO))
      63                 :            :                 {
      64                 :          2 :                   lw6sys_log (LW6SYS_LOG_INFO,
      65                 :            :                               _x_ ("mod_udpd %s response to %s:%d"),
      66                 :            :                               LW6MSG_OOB_INFO, oob_data->remote_ip,
      67                 :            :                               oob_data->remote_port);
      68                 :          2 :                   response = lw6msg_oob_generate_info (node_info);
      69                 :            :                 }
      70         [ +  + ]:         16 :               if (lw6sys_str_is_same_no_case (command, LW6MSG_OOB_LIST))
      71                 :            :                 {
      72                 :          2 :                   lw6sys_log (LW6SYS_LOG_INFO,
      73                 :            :                               _x_ ("mod_udpd %s response to %s:%d"),
      74                 :            :                               LW6MSG_OOB_LIST, oob_data->remote_ip,
      75                 :            :                               oob_data->remote_port);
      76                 :          2 :                   response = lw6msg_oob_generate_list (node_info);
      77                 :            :                 }
      78         [ +  - ]:         16 :               if (given_public_url)
      79                 :            :                 {
      80         [ +  - ]:         16 :                   if (strlen (given_public_url) > 0)
      81                 :            :                     {
      82                 :         16 :                       lw6sys_log (LW6SYS_LOG_DEBUG,
      83                 :            :                                   _x_
      84                 :            :                                   ("discovered node \"%s\" from given url"),
      85                 :            :                                   given_public_url);
      86                 :         16 :                       lw6nod_info_add_discovered_node (node_info,
      87                 :            :                                                        given_public_url);
      88                 :            :                     }
      89                 :         16 :                   LW6SYS_FREE (given_public_url);
      90                 :            :                 }
      91                 :            :             }
      92                 :            :           else
      93                 :            :             {
      94 [ +  - ][ +  - ]:          1 :               if (syntax_ok && !password_ok)
      95                 :            :                 {
      96                 :          1 :                   lw6sys_log (LW6SYS_LOG_INFO,
      97                 :            :                               _x_ ("mod_udpd %s response to %s:%d"),
      98                 :            :                               LW6MSG_FORBIDDEN, oob_data->remote_ip,
      99                 :            :                               oob_data->remote_port);
     100                 :          1 :                   response = lw6sys_new_sprintf ("%s\n", LW6MSG_FORBIDDEN);
     101                 :            :                 }
     102                 :            :               else
     103                 :            :                 {
     104                 :          0 :                   lw6sys_log (LW6SYS_LOG_INFO,
     105                 :            :                               _x_ ("mod_udpd %s response to %s:%d"),
     106                 :            :                               LW6MSG_ERROR, oob_data->remote_ip,
     107                 :            :                               oob_data->remote_port);
     108                 :          0 :                   response = lw6sys_new_sprintf ("%s\n", LW6MSG_ERROR);
     109                 :            :                 }
     110                 :            :             }
     111                 :            :         }
     112                 :            :     }
     113                 :            : 
     114         [ +  - ]:         17 :   if (response)
     115                 :            :     {
     116                 :         17 :       lw6sys_log (LW6SYS_LOG_DEBUG,
     117                 :            :                   _x_ ("sending OOB response \"%s\" on UDP to %s:%d"),
     118                 :            :                   response, oob_data->remote_ip, oob_data->remote_port);
     119                 :         17 :       lw6net_udp_send (oob_data->sock, response, strlen (response),
     120                 :            :                        oob_data->remote_ip, oob_data->remote_port);
     121                 :            :     }
     122                 :            :   else
     123                 :            :     {
     124                 :          0 :       lw6net_send_line_udp (oob_data->sock, LW6MSG_ERROR,
     125                 :            :                             oob_data->remote_ip, oob_data->remote_port);
     126                 :            :     }
     127                 :            : 
     128         [ +  - ]:         17 :   if (response)
     129                 :            :     {
     130                 :         17 :       LW6SYS_FREE (response);
     131                 :            :     }
     132                 :            : 
     133                 :         17 :   return ret;
     134                 :            : }
     135                 :            : 
     136                 :            : int
     137                 :         17 : _mod_udpd_oob_should_continue (_udpd_context_t * udpd_context,
     138                 :            :                                lw6srv_oob_data_t * oob_data)
     139                 :            : {
     140                 :         17 :   int ret = 0;
     141                 :            : 
     142         [ +  - ]:         17 :   ret = (_mod_udpd_timeout_ok (udpd_context, oob_data->creation_timestamp)
     143         [ -  + ]:         17 :          && (!oob_data->do_not_finish));
     144                 :            : 
     145                 :         17 :   return ret;
     146                 :            : }

Generated by: LCOV version 1.9