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 "channel_manager.h"
36 #define snprintf _snprintf /* Visual Studio */
40 #include "fcgi_stdio.h"
41 #define logstream FCGI_stdout
43 #define FCGI_stdout stdout
44 #define FCGI_stderr stderr
45 #define logstream stderr
48 channellist_param_t * gene_channellist(void)
50 channellist_param_t *channellist;
52 channellist = (channellist_param_t *)opj_malloc( sizeof(channellist_param_t));
54 channellist->first = NULL;
55 channellist->last = NULL;
60 channel_param_t * gene_channel( query_param_t query_param, auxtrans_param_t auxtrans, cachemodel_param_t *cachemodel, channellist_param_t *channellist)
62 channel_param_t *channel;
63 const char transport[4][10] = { "non", "http", "http-tcp", "http-udp"};
66 fprintf( FCGI_stdout, "Status: 404\r\n");
67 fprintf( FCGI_stdout, "Reason: cnew cancelled\r\n");
71 channel = (channel_param_t *)opj_malloc( sizeof(channel_param_t));
72 channel->cachemodel = cachemodel;
74 /* set channel ID and get present time */
75 snprintf( channel->cid, MAX_LENOFCID, "%x%x", (unsigned int)time( &channel->start_tm), (unsigned int)rand());
77 channel->aux = query_param.cnew;
79 /* only tcp implemented for now */
80 if( channel->aux == udp)
85 set_channel_variable_param( query_param, channel);
87 if( channellist->first != NULL)
88 channellist->last->next = channel;
90 channellist->first = channel;
91 channellist->last = channel;
93 fprintf( FCGI_stdout, "JPIP-cnew: cid=%s", channel->cid);
94 fprintf( FCGI_stdout, ",transport=%s", transport[channel->aux]);
96 if( channel->aux == tcp || channel->aux == udp)
97 fprintf( FCGI_stdout, ",auxport=%d", channel->aux==tcp ? auxtrans.tcpauxport : auxtrans.udpauxport);
99 fprintf( FCGI_stdout, "\r\n");
105 void set_channel_variable_param( query_param_t query_param, channel_param_t *channel)
107 /* set roi information */
113 void delete_channel( channel_param_t **channel, channellist_param_t *channellist)
115 channel_param_t *ptr;
117 if( *channel == channellist->first)
118 channellist->first = (*channel)->next;
120 ptr = channellist->first;
121 while( ptr->next != *channel){
125 ptr->next = (*channel)->next;
127 if( *channel == channellist->last)
128 channellist->last = ptr;
131 fprintf( logstream, "local log: channel: %s deleted\n", (*channel)->cid);
136 void delete_channellist( channellist_param_t **channellist)
138 channel_param_t *channelPtr, *channelNext;
140 channelPtr = (*channellist)->first;
141 while( channelPtr != NULL){
142 channelNext=channelPtr->next;
144 fprintf( logstream, "local log: channel %s deleted!\n", channelPtr->cid);
146 opj_free(channelPtr);
147 channelPtr=channelNext;
149 opj_free( *channellist);
152 void print_allchannel( channellist_param_t *channellist)
154 channel_param_t *ptr;
156 ptr = channellist->first;
158 fprintf( logstream,"channel-ID=%s \t target=%s\n", ptr->cid, ptr->cachemodel->target->targetname);
163 channel_param_t * search_channel( const char cid[], channellist_param_t *channellist)
165 channel_param_t *foundchannel;
167 foundchannel = channellist->first;
169 while( foundchannel != NULL){
171 if( strcmp( cid, foundchannel->cid) == 0)
174 foundchannel = foundchannel->next;
176 fprintf( FCGI_stdout, "Status: 503\r\n");
177 fprintf( FCGI_stdout, "Reason: Channel %s not found in this session\r\n", cid);