My Project
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
regex_msu.c
Go to the documentation of this file.
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 "local_msu.h"
21 #include "msu_type.h"
22 #include "msu_message.h"
23 #include "msu_calls.h"
24 #include "logging.h"
25 #include "routing_strategies.h"
26 
27 #include "webserver/write_msu.h"
28 #include "webserver/regex_msu.h"
30 #include "webserver/httpops.h"
31 
32 static int craft_ws_regex_response(struct local_msu *self,
33  struct msu_msg *msg) {
34  struct response_state *resp = msg->data;
35 
36  if (!has_regex(resp->url)) {
37  log_error("Regex MSU received request without regex");
38  return -1;
39  }
40 
41  resp->body_len = craft_regex_response(resp->url, resp->body);
42  resp->header_len = generate_header(resp->header, 200, MAX_HEADER_LEN,
43  resp->body_len, "text/html");
44  call_msu_type(self, &WEBSERVER_WRITE_MSU_TYPE, &msg->hdr, sizeof(*resp), resp);
45  return 0;
46 }
47 
49  .name = "Webserver_regex_msu",
51  .receive = craft_ws_regex_response,
52  .route = shortest_queue_route
53 };
static int craft_ws_regex_response(struct local_msu *self, struct msu_msg *msg)
Definition: regex_msu.c:32
int has_regex(char *url)
int shortest_queue_route(struct msu_type *type, struct local_msu *sender, struct msu_msg *msg, struct msu_endpoint *output)
Chooses the local MSU with the shortest queue.
Defines a type of MSU, including callback and accessor functions.
struct msu_type WEBSERVER_REGEX_MSU_TYPE
Definition: regex_msu.c:48
int craft_regex_response(char *url, char *response)
void * data
Payload.
Definition: msu_message.h:104
Logging of status messages to the terminal.
struct msu_type WEBSERVER_WRITE_MSU_TYPE
Definition: write_msu.c:69
Declares the methods available for calling an MSU from another MSU.
#define log_error(fmt,...)
Definition: logging.h:101
Declares the structures and functions applicable to MSUs on the local machine.
The structure that represents an MSU located on the local machine.
Definition: local_msu.h:38
int call_msu_type(struct local_msu *sender, struct msu_type *dst_type, struct msu_msg_hdr *hdr, size_t data_size, void *data)
Sends an MSU message to a destination of the given type, utilizing the sending MSU's routing function...
Definition: msu_calls.c:146
Defines a type of MSU.
Definition: msu_type.h:46
struct msu_msg_hdr hdr
Definition: msu_message.h:102
int generate_header(char *dest, int code, int capacity, int body_len, char *mime_type)
Definition: httpops.c:88
A message that is to be delivered to an instance of an MSU.
Definition: msu_message.h:101
Messages passed to MSUs.
#define MAX_HEADER_LEN
char * name
Name for the msu type.
Definition: msu_type.h:48
Declares strategies that MSUs can use for routing to endpoints.
#define WEBSERVER_REGEX_MSU_TYPE_ID
Definition: msu_ids.h:27