4 * Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
5 * Copyright (c) 2002-2011, 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;
74 sessionlist->last = session;
79 bool search_session_and_channel( char cid[],
80 sessionlist_param_t *sessionlist,
81 session_param_t **foundsession,
82 channel_param_t **foundchannel)
84 *foundsession = sessionlist->first;
86 while( *foundsession != NULL){
88 *foundchannel = (*foundsession)->channellist->first;
90 while( *foundchannel != NULL){
92 if( strcmp( cid, (*foundchannel)->cid) == 0)
95 *foundchannel = (*foundchannel)->next;
97 *foundsession = (*foundsession)->next;
100 fprintf( FCGI_stdout, "Status: 503\r\n");
101 fprintf( FCGI_stdout, "Reason: Channel %s not found\r\n", cid);
106 void insert_cachemodel_into_session( session_param_t *session, cachemodel_param_t *cachemodel)
112 fprintf( logstream, "local log: insert cachemodel into session\n");
114 if( session->cachemodellist->first != NULL)
115 session->cachemodellist->last->next = cachemodel;
117 session->cachemodellist->first = cachemodel;
118 session->cachemodellist->last = cachemodel;
121 bool delete_session( session_param_t **session, sessionlist_param_t *sessionlist)
123 session_param_t *ptr;
125 if( *session == NULL)
129 if( *session == sessionlist->first)
130 sessionlist->first = (*session)->next;
132 ptr = sessionlist->first;
133 while( ptr->next != *session)
135 ptr->next = (*session)->next;
137 if( *session == sessionlist->last)
138 sessionlist->last = ptr;
141 delete_channellist( &((*session)->channellist));
142 delete_cachemodellist( &((*session)->cachemodellist));
145 fprintf( logstream, "local log: session: %p deleted!\n", (void *)(*session));
152 void delete_sessionlist( sessionlist_param_t **sessionlist)
154 session_param_t *sessionPtr, *sessionNext;
156 sessionPtr = (*sessionlist)->first;
157 while( sessionPtr != NULL){
158 sessionNext=sessionPtr->next;
160 delete_channellist( &(sessionPtr->channellist));
161 delete_cachemodellist( &(sessionPtr->cachemodellist));
164 fprintf( logstream, "local log: session: %p deleted!\n", (void *)sessionPtr);
166 opj_free( sessionPtr);
168 sessionPtr=sessionNext;
171 (*sessionlist)->first = NULL;
172 (*sessionlist)->last = NULL;
174 opj_free(*sessionlist);
177 void print_allsession( sessionlist_param_t *sessionlist)
179 session_param_t *ptr;
180 cachemodel_param_t *cachemodel;
183 fprintf( logstream, "SESSIONS info:\n");
185 ptr = sessionlist->first;
187 fprintf( logstream, "session No.%d\n", i++);
188 print_allchannel( ptr->channellist);
189 cachemodel = ptr->cachemodellist->first;
191 print_target( cachemodel->target);
192 cachemodel = cachemodel->next;