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: 44 48 91.7 %
Date: 2014-03-26 Functions: 2 2 100.0 %

          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-internal.h"
      29             : 
      30             : int
      31         289 : _mod_udpd_process_oob (_mod_udpd_context_t * udpd_context,
      32             :                        lw6nod_info_t * node_info,
      33             :                        lw6srv_oob_data_t * oob_data)
      34             : {
      35         289 :   int ret = 0;
      36         289 :   char *request_line = NULL;
      37         289 :   int syntax_ok = 0;
      38         289 :   char *command = NULL;
      39         289 :   int password_ok = 0;
      40         289 :   char *given_public_url = NULL;
      41         289 :   char *response = NULL;
      42             : 
      43         289 :   lw6sys_log (LW6SYS_LOG_DEBUG, _x_ ("process udpd oob"));
      44         289 :   if (_mod_udpd_oob_should_continue (udpd_context, oob_data))
      45             :     {
      46         289 :       request_line = oob_data->first_line;
      47         289 :       if (request_line)
      48             :         {
      49         289 :           if (lw6msg_oob_analyse_request (&syntax_ok, &command, &password_ok,
      50             :                                           &given_public_url, request_line,
      51         289 :                                           node_info->const_info.ref_info.url,
      52         289 :                                           node_info->const_info.password))
      53             :             {
      54         256 :               if (lw6sys_str_is_same_no_case (command, LW6MSG_OOB_PING))
      55             :                 {
      56         178 :                   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         178 :                   response = lw6msg_oob_generate_pong (node_info);
      61             :                 }
      62         256 :               if (lw6sys_str_is_same_no_case (command, LW6MSG_OOB_INFO))
      63             :                 {
      64          39 :                   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          39 :                   response = lw6msg_oob_generate_info (node_info);
      69             :                 }
      70         256 :               if (lw6sys_str_is_same_no_case (command, LW6MSG_OOB_LIST))
      71             :                 {
      72          39 :                   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          39 :                   response = lw6msg_oob_generate_list (node_info);
      77             :                 }
      78         256 :               if (given_public_url)
      79             :                 {
      80         256 :                   if (strlen (given_public_url) > 0)
      81             :                     {
      82         256 :                       lw6sys_log (LW6SYS_LOG_DEBUG,
      83             :                                   _x_
      84             :                                   ("discovered node \"%s\" from given url"),
      85             :                                   given_public_url);
      86         256 :                       lw6nod_info_add_discovered_node (node_info,
      87             :                                                        given_public_url);
      88             :                     }
      89         256 :                   LW6SYS_FREE (given_public_url);
      90             :                 }
      91             :             }
      92             :           else
      93             :             {
      94          33 :               if (syntax_ok && !password_ok)
      95             :                 {
      96          33 :                   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          33 :                   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         289 :   if (response)
     115             :     {
     116         289 :       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         578 :       lw6net_udp_send (oob_data->sock, response, strlen (response),
     120         289 :                        oob_data->remote_ip, oob_data->remote_port);
     121             :     }
     122             :   else
     123             :     {
     124           0 :       lw6net_send_line_udp (oob_data->sock, LW6MSG_ERROR,
     125           0 :                             oob_data->remote_ip, oob_data->remote_port);
     126             :     }
     127             : 
     128         289 :   if (response)
     129             :     {
     130         289 :       LW6SYS_FREE (response);
     131             :     }
     132             : 
     133         289 :   return ret;
     134             : }
     135             : 
     136             : int
     137         289 : _mod_udpd_oob_should_continue (_mod_udpd_context_t * udpd_context,
     138             :                                lw6srv_oob_data_t * oob_data)
     139             : {
     140         289 :   int ret = 0;
     141             : 
     142         578 :   ret = (_mod_udpd_timeout_ok (udpd_context, oob_data->creation_timestamp)
     143         289 :          && (!oob_data->do_not_finish));
     144             : 
     145         289 :   return ret;
     146             : }

Generated by: LCOV version 1.10