1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3 /* Monkey HTTP Server
4 * ==================
5 * Copyright 2001-2017 Eduardo Silva <eduardo@monkey.io>
6 * Copyright (C) 2012-2013, Lauri Kasanen
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20
21 #include "cgi.h"
22
cgi_req_create(int fd,int socket,struct mk_plugin * plugin,struct mk_http_request * sr,struct mk_http_session * cs)23 struct cgi_request *cgi_req_create(int fd, int socket,
24 struct mk_plugin *plugin,
25 struct mk_http_request *sr,
26 struct mk_http_session *cs)
27 {
28 struct cgi_request *cgi;
29
30 cgi = mk_api->mem_alloc_z(sizeof(struct cgi_request));
31 if (!cgi) {
32 return NULL;
33 }
34
35 cgi->fd = fd;
36 cgi->socket = socket;
37 cgi->plugin = plugin;
38 cgi->sr = sr;
39 cgi->cs = cs;
40 cgi->hangup = MK_TRUE;
41 cgi->active = MK_TRUE;
42 cgi->in_len = 0;
43
44 cgi->event.mask = MK_EVENT_EMPTY;
45 cgi->event.status = MK_EVENT_NONE;
46
47 return cgi;
48 }
49
cgi_req_add(struct cgi_request * r)50 void cgi_req_add(struct cgi_request *r)
51 {
52 struct mk_list *list;
53
54 list = pthread_getspecific(cgi_request_list);
55 mk_list_add(&r->_head, list);
56 }
57
cgi_req_del(struct cgi_request * r)58 int cgi_req_del(struct cgi_request *r)
59 {
60 PLUGIN_TRACE("Delete request child_fd=%i child_pid=%lu",
61 r->fd, r->child);
62
63 mk_list_del(&r->_head);
64 if (r->active == MK_FALSE) {
65 mk_api->sched_event_free(&r->event);
66 }
67 else {
68 mk_mem_free(r);
69 }
70
71 return 0;
72 }
73