LCOV - code coverage report
Current view: top level - msus/webserver - write_msu.c (source / functions) Hit Total Coverage
Test: unnamed Lines: 23 28 82.1 %
Date: 2018-01-11 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /*
       2             : START OF LICENSE STUB
       3             :     DeDOS: Declarative Dispersion-Oriented Software
       4             :     Copyright (C) 2017 University of Pennsylvania, Georgetown University
       5             : 
       6             :     This program is free software: you can redistribute it and/or modify
       7             :     it under the terms of the GNU General Public License as published by
       8             :     the Free Software Foundation, either version 3 of the License, or
       9             :     (at your option) any later version.
      10             : 
      11             :     This program is distributed in the hope that it will be useful,
      12             :     but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14             :     GNU General Public License for more details.
      15             : 
      16             :     You should have received a copy of the GNU General Public License
      17             :     along with this program.  If not, see <http://www.gnu.org/licenses/>.
      18             : END OF LICENSE STUB
      19             : */
      20             : #include "webserver/write_msu.h"
      21             : #include "socket_msu.h"
      22             : #include "webserver/connection-handler.h"
      23             : #include "msu_state.h"
      24             : #include "logging.h"
      25             : #include "routing_strategies.h"
      26             : #include "profiler.h"
      27             : #include "local_msu.h"
      28             : 
      29         141 : static int write_http_response(struct local_msu *self,
      30             :                                struct msu_msg *msg) {
      31         141 :     struct response_state *resp_in = msg->data;
      32             : 
      33         141 :     size_t size = 0;
      34         141 :     struct response_state *resp = msu_get_state(self, &msg->hdr.key, &size);
      35         141 :     if (resp == NULL) {
      36         141 :         resp = msu_init_state(self, &msg->hdr.key, sizeof(*resp));
      37         141 :         memcpy(resp, resp_in, sizeof(*resp_in));
      38             :     }
      39             : 
      40         141 :     int rtn = write_response(resp);
      41         141 :     if (rtn & WS_ERROR) {
      42           1 :         msu_error(self, NULL, 0);
      43           1 :         msu_remove_fd_monitor(resp->conn.fd);
      44           1 :         if (close_connection(&resp->conn) == WS_ERROR) {
      45           0 :             msu_error(self, NULL, 0);
      46             :         }
      47           1 :         msu_free_state(self, &msg->hdr.key);
      48           1 :         free(resp_in);
      49           1 :         return -1;
      50         140 :     } else if (rtn & (WS_INCOMPLETE_READ | WS_INCOMPLETE_WRITE)) {
      51           0 :         rtn = msu_monitor_fd(resp->conn.fd, RTN_TO_EVT(rtn), self, &msg->hdr);
      52           0 :         free(resp_in);
      53           0 :         return rtn;
      54             :     } else {
      55             :         PROFILE_EVENT(msg->hdr, PROF_DEDOS_EXIT);
      56         140 :         msu_remove_fd_monitor(resp->conn.fd);
      57         140 :         if (close_connection(&resp->conn) == WS_ERROR) {
      58           0 :             msu_error(self, NULL, 0);
      59             :         }
      60         140 :         log(LOG_WEBSERVER_WRITE, "Successful connection to fd %d closed",
      61             :                    resp->conn.fd);
      62         140 :         log(LOG_WEBSERVER_WRITE, "Wrote request: %s", resp->body);
      63         140 :         msu_free_state(self, &msg->hdr.key);
      64         140 :         free(resp_in);
      65         140 :         return 0;
      66             :     }
      67             : }
      68             : 
      69             : struct msu_type WEBSERVER_WRITE_MSU_TYPE = {
      70             :     .name = "Webserver_write_MSU",
      71             :     .id = WEBSERVER_WRITE_MSU_TYPE_ID,
      72             :     .receive = write_http_response,
      73             :     .route = route_to_origin_runtime
      74             : };
      75             : 
      76             : 

Generated by: LCOV version 1.10