Web Wispers 1.2.2 C++ Unit Test Coverage
Current view: top level - ssrc/wispers/fcgi - FCGIRequest.cc (source / functions) Hit Total Coverage
Test: Web Wispers 1.2.2 C++ Unit Tests Lines: 3 26 11.5 %
Date: 2012-04-09 Functions: 2 4 50.0 %
Branches: 2 72 2.8 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Copyright 2006-2009 Savarese Software Research Corporation
       3                 :            :  *
       4                 :            :  * Licensed under the Apache License, Version 2.0 (the "License");
       5                 :            :  * you may not use this file except in compliance with the License.
       6                 :            :  * You may obtain a copy of the License at
       7                 :            :  *
       8                 :            :  *     https://www.savarese.com/software/ApacheLicense-2.0
       9                 :            :  *
      10                 :            :  * Unless required by applicable law or agreed to in writing, software
      11                 :            :  * distributed under the License is distributed on an "AS IS" BASIS,
      12                 :            :  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      13                 :            :  * See the License for the specific language governing permissions and
      14                 :            :  * limitations under the License.
      15                 :            :  */
      16                 :            : 
      17                 :            : #include <ssrc/wispers/fcgi/FCGIRequest.h>
      18                 :            : #include <ssrc/wispers/fcgi/URI.h>
      19                 :            : 
      20                 :            : #include <sstream>
      21                 :            : 
      22                 :            : __BEGIN_NS_SSRC_WSPR_FCGI
      23                 :            : 
      24                 :            : const FCGIRequest::HTTPRequestMethodMap
      25                 :          2 : FCGIRequest::RequestMethodMap(&RequestMethodName[0],
      26                 :          2 :                               &RequestMethodName[MethodNum]);
      27                 :            : 
      28                 :            : /**
      29                 :            :  * At the moment, we do not employ a generic cookie mechanism.  If
      30                 :            :  * we needed one, we'd implement a Cookie class and store all cookies
      31                 :            :  * in a cookie map a la parameter_map.  Instead, we simply extract
      32                 :            :  * the WSPRSID cookie value if it exists.  We don't properly parse the
      33                 :            :  * cookie and instead search for WSPRSID= and grab everything between
      34                 :            :  * the = and the next semi-colon.  _session_id must be empty before
      35                 :            :  * calling this function because the data is appended to it.
      36                 :            :  */
      37                 :          0 : void FCGIRequest::set_session_id() {
      38                 :            :   const char *cookie_str =
      39                 :          0 :     FCGI::FCGX_GetParam("HTTP_COOKIE", _fcgx_request->envp);
      40                 :            :   /*
      41                 :            :   if(cookie_str == 0 || *cookie_str == 0)
      42                 :            :     cookie_str = FCGI::FCGX_GetParam("HTTP_COOKIE2", _fcgx_request->envp);
      43                 :            :   */
      44   [ #  #  #  # ]:          0 :   if(cookie_str && *cookie_str != 0) {
      45                 :          0 :     const char *data = std::strstr(cookie_str, "WSPRSID=");
      46                 :            : 
      47         [ #  # ]:          0 :     if(data) {
      48                 :          0 :       const char *end = std::strchr(data, ';');
      49                 :            : 
      50         [ #  # ]:          0 :       if(end) {
      51                 :          0 :         _session_id.append(data, end - data + 8);
      52                 :            :       } else {
      53                 :          0 :         _session_id.append(data + 8);
      54                 :            :       }
      55                 :            :     }
      56                 :            :   }
      57                 :          0 : }
      58                 :            : 
      59                 :          0 : string FCGIRequest::to_absolute_url(const string & url) const
      60                 :            :   SSRC_DECL_THROW(std::invalid_argument)
      61                 :            : {
      62                 :          0 :   URI uri(url);
      63                 :            : 
      64   [ #  #  #  # ]:          0 :   if(uri.absolute())
      65         [ #  # ]:          0 :     return url;
      66                 :            :   else {
      67   [ #  #  #  # ]:          0 :     std::ostringstream location;
      68                 :            : 
      69   [ #  #  #  #  :          0 :     location << scheme() << "://" << server_name();
          #  #  #  #  #  
             #  #  #  #  
                      # ]
      70                 :            : 
      71         [ #  # ]:          0 :     int port = server_port();
      72                 :            :      
      73   [ #  #  #  #  :          0 :     if((!https() && port != PORT_HTTP) || (https() && port != PORT_HTTPS))
          #  #  #  #  #  
             #  #  #  #  
                      # ]
      74   [ #  #  #  # ]:          0 :       location << ':' << port;
      75                 :            : 
      76                 :            :     // Relative redirects treat the request uri as a directory.  We
      77                 :            :     // could figure out if the uri refers to a directory or a file and
      78                 :            :     // use the parent if a file, but this is sufficient for our needs.
      79   [ #  #  #  # ]:          0 :     if(url[0] != '/')
      80   [ #  #  #  #  :          0 :       location << request_uri() << '/'; 
             #  #  #  # ]
      81                 :            : 
      82         [ #  # ]:          0 :     location << url;
      83                 :            : 
      84         [ #  # ]:          0 :     return location.str();
      85                 :            :   }
      86                 :            : }
      87                 :            : 
      88   [ +  -  +  - ]:          6 : __END_NS_SSRC_WSPR_FCGI