1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
5 * Copyright (C) 2001-2010, Eduardo Silva P.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Library General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30 struct mk_palm_request
*mk_palm_request_create(int client_fd
,
32 struct client_request
*cr
,
36 struct mk_palm_request
*new;
38 new = mk_api
->mem_alloc(sizeof(struct mk_palm_request
));
39 new->client_fd
= client_fd
;
40 new->palm_fd
= palm_fd
;
44 new->headers_sent
= VAR_OFF
;
52 void mk_palm_request_add(struct mk_palm_request
*pr
)
54 struct mk_palm_request
*pr_list
, *aux
;
57 pr_list
= pthread_getspecific(_mkp_data
);
59 /* No connection previously was found */
61 pthread_setspecific(_mkp_data
, pr
);
72 pthread_setspecific(_mkp_data
, pr_list
);
75 /* It register the request and connection data, if it doesn't
76 * exists it will be create it, otherwise will return the pointer
77 * to the mk_palm_request struct node
79 struct mk_palm_request
*mk_palm_request_get(int socket
)
81 struct mk_palm_request
*pr
, *aux
;
84 pr
= pthread_getspecific(_mkp_data
);
86 /* No connection previously was found */
94 if(aux
->palm_fd
== socket
){
103 struct mk_palm_request
*mk_palm_request_get_by_http(int socket
)
105 struct mk_palm_request
*pr
, *aux
;
107 /* Get thread data */
108 pr
= pthread_getspecific(_mkp_data
);
110 /* No connection previously was found */
118 if(aux
->client_fd
== socket
){
127 void mk_palm_request_update(int socket
, struct mk_palm_request
*pr
)
129 struct mk_palm_request
*aux
, *list
;
131 list
= pthread_getspecific(_mkp_data
);
139 if (aux
->palm_fd
== socket
) {
140 aux
->bytes_sent
= pr
->bytes_sent
;
141 aux
->bytes_read
= pr
->bytes_read
;
142 aux
->headers_sent
= pr
->headers_sent
;
145 pthread_setspecific(_mkp_data
, list
);
152 void mk_palm_request_delete(int socket
)
154 struct mk_palm_request
*aux
, *prev
, *list
;
156 list
= pthread_getspecific(_mkp_data
);
164 if (aux
->palm_fd
== socket
) {
171 while(prev
->next
!= aux
) {
174 prev
->next
= aux
->next
;
176 mk_api
->mem_free(aux
);
177 pthread_setspecific(_mkp_data
, list
);
184 void mk_palm_free_request(int sockfd
)
186 /* get palm request node */
187 mk_palm_request_get(sockfd
);
188 /* delete palm request node */
189 mk_palm_request_delete(sockfd
);
190 mk_api
->socket_close(sockfd
);