4 * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
5 * Copyright (c) 2002-2014, Professor Benoit Macq
6 * Copyright (c) 2010-2011, Kaori Hagihara
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
34 #include "session_manager.h"
35 #include "target_manager.h"
38 #include "fcgi_stdio.h"
39 #define logstream FCGI_stdout
41 #define FCGI_stdout stdout
42 #define FCGI_stderr stderr
43 #define logstream stderr
47 sessionlist_param_t * gene_sessionlist(void)
49 sessionlist_param_t *sessionlist;
51 sessionlist = (sessionlist_param_t *)opj_malloc(sizeof(sessionlist_param_t));
53 sessionlist->first = NULL;
54 sessionlist->last = NULL;
59 session_param_t * gene_session(sessionlist_param_t *sessionlist)
61 session_param_t *session;
63 session = (session_param_t *)opj_malloc(sizeof(session_param_t));
65 session->channellist = gene_channellist();
66 session->cachemodellist = gene_cachemodellist();
70 if (sessionlist->first) { /* there are one or more entries */
71 sessionlist->last->next = session;
72 } else { /* first entry */
73 sessionlist->first = session;
75 sessionlist->last = session;
80 OPJ_BOOL search_session_and_channel(char cid[],
81 sessionlist_param_t *sessionlist,
82 session_param_t **foundsession,
83 channel_param_t **foundchannel)
85 *foundsession = sessionlist->first;
87 while (*foundsession != NULL) {
89 *foundchannel = (*foundsession)->channellist->first;
91 while (*foundchannel != NULL) {
93 if (strcmp(cid, (*foundchannel)->cid) == 0) {
97 *foundchannel = (*foundchannel)->next;
99 *foundsession = (*foundsession)->next;
102 fprintf(FCGI_stdout, "Status: 503\r\n");
103 fprintf(FCGI_stdout, "Reason: Channel %s not found\r\n", cid);
108 void insert_cachemodel_into_session(session_param_t *session,
109 cachemodel_param_t *cachemodel)
116 fprintf(logstream, "local log: insert cachemodel into session\n");
118 if (session->cachemodellist->first != NULL) {
119 session->cachemodellist->last->next = cachemodel;
121 session->cachemodellist->first = cachemodel;
123 session->cachemodellist->last = cachemodel;
126 OPJ_BOOL delete_session(session_param_t **session,
127 sessionlist_param_t *sessionlist)
129 session_param_t *ptr;
131 if (*session == NULL) {
136 if (*session == sessionlist->first) {
137 sessionlist->first = (*session)->next;
139 ptr = sessionlist->first;
140 while (ptr->next != *session) {
143 ptr->next = (*session)->next;
145 if (*session == sessionlist->last) {
146 sessionlist->last = ptr;
150 delete_channellist(&((*session)->channellist));
151 delete_cachemodellist(&((*session)->cachemodellist));
154 fprintf(logstream, "local log: session: %p deleted!\n", (void *)(*session));
161 void delete_sessionlist(sessionlist_param_t **sessionlist)
163 session_param_t *sessionPtr, *sessionNext;
165 sessionPtr = (*sessionlist)->first;
166 while (sessionPtr != NULL) {
167 sessionNext = sessionPtr->next;
169 delete_channellist(&(sessionPtr->channellist));
170 delete_cachemodellist(&(sessionPtr->cachemodellist));
173 fprintf(logstream, "local log: session: %p deleted!\n", (void *)sessionPtr);
175 opj_free(sessionPtr);
177 sessionPtr = sessionNext;
180 (*sessionlist)->first = NULL;
181 (*sessionlist)->last = NULL;
183 opj_free(*sessionlist);
186 void print_allsession(sessionlist_param_t *sessionlist)
188 session_param_t *ptr;
189 cachemodel_param_t *cachemodel;
192 fprintf(logstream, "SESSIONS info:\n");
194 ptr = sessionlist->first;
195 while (ptr != NULL) {
196 fprintf(logstream, "session No.%d\n", i++);
197 print_allchannel(ptr->channellist);
198 cachemodel = ptr->cachemodellist->first;
200 print_target(cachemodel->target);
201 cachemodel = cachemodel->next;