~ubuntu-branches/debian/squeeze/axis2c/squeeze

« back to all changes in this revision

Viewing changes to src/core/transport/http/common/simple_http_svr_conn.c

  • Committer: Bazaar Package Importer
  • Author(s): Kyo Lee
  • Date: 2009-12-16 20:27:31 UTC
  • mfrom: (6.1.9 karmic)
  • Revision ID: james.westby@ubuntu.com-20091216202731-ucim9tlbmpwucfz0
Tags: 1.6.0-1
Build for debian package based largely on Ubuntu package (#497594)

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
#include <axutil_http_chunked_stream.h>
23
23
#include <platforms/axutil_platform_auto_sense.h>
24
24
#include <string.h>
 
25
#include <axis2_http_simple_response.h>
 
26
#include <axis2_http_transport_utils.h>
25
27
 
26
28
struct axis2_simple_http_svr_conn
27
29
{
152
154
    axis2_simple_http_svr_conn_t * svr_conn,
153
155
    const axutil_env_t * env)
154
156
{
155
 
    axis2_char_t str_line[2048];
 
157
    axis2_char_t* str_line = NULL;
156
158
    axis2_char_t tmp_buf[2048];
157
159
    int read = -1;
158
160
    axis2_bool_t end_of_line = AXIS2_FALSE;
160
162
    axis2_http_request_line_t *request_line = NULL;
161
163
    axis2_http_simple_request_t *request = NULL;
162
164
 
163
 
    memset(str_line, 0, 2048);
164
165
    while ((read =
165
166
            axutil_stream_peek_socket(svr_conn->stream, env, tmp_buf,
166
167
                                      2048 - 1)) > 0)
176
177
                                   end - start + 2);
177
178
            if (read > 0)
178
179
            {
 
180
                axis2_char_t* tmp_str_line = NULL;
179
181
                tmp_buf[read] = AXIS2_ESC_NULL;
180
 
                strcat(str_line, tmp_buf);
 
182
                tmp_str_line = axutil_stracat(env, str_line, tmp_buf);
 
183
                if(tmp_str_line)
 
184
                {
 
185
                    AXIS2_FREE(env->allocator, str_line);
 
186
                    str_line = tmp_str_line;
 
187
                }
181
188
                break;
182
189
            }
183
190
            else
192
199
            read = axutil_stream_read(svr_conn->stream, env, tmp_buf, 2048 - 1);
193
200
            if (read > 0)
194
201
            {
 
202
                axis2_char_t* tmp_str_line = NULL;
195
203
                tmp_buf[read] = AXIS2_ESC_NULL;
196
 
                strcat(str_line, tmp_buf);
 
204
                tmp_str_line = axutil_stracat(env, str_line, tmp_buf);
 
205
                if(tmp_str_line)
 
206
                {
 
207
                    AXIS2_FREE(env->allocator, str_line);
 
208
                    str_line = tmp_str_line;
 
209
                }
197
210
            }
198
211
        }
199
212
    }
200
213
 
201
214
    request_line = axis2_http_request_line_parse_line(env, str_line);
 
215
    AXIS2_FREE(env->allocator, str_line);
 
216
    str_line = NULL;
 
217
 
202
218
    if (!request_line)
203
219
    {
204
220
        AXIS2_HANDLE_ERROR(env,
209
225
    request = axis2_http_simple_request_create(env, request_line, NULL, 0,
210
226
                                               svr_conn->stream);
211
227
    /* now read the headers */
212
 
    memset(str_line, 0, 2048);
213
228
    end_of_line = AXIS2_FALSE;
214
229
    while (AXIS2_FALSE == end_of_headers)
215
230
    {
 
231
        axis2_bool_t is_read = AXIS2_FALSE;
216
232
        while ((read =
217
233
                axutil_stream_peek_socket(svr_conn->stream, env, tmp_buf,
218
234
                                          2048 - 1)) > 0)
219
235
        {
220
236
            axis2_char_t *start = tmp_buf;
221
237
            axis2_char_t *end = NULL;
 
238
            is_read = AXIS2_TRUE;
222
239
            tmp_buf[read] = AXIS2_ESC_NULL;
223
240
            end = strstr(tmp_buf, AXIS2_HTTP_CRLF);
224
241
            if (end)
228
245
                                       end - start + 2);
229
246
                if (read > 0)
230
247
                {
 
248
                    axis2_char_t* tmp_str_line = NULL;
231
249
                    tmp_buf[read] = AXIS2_ESC_NULL;
232
 
                    strcat(str_line, tmp_buf);
 
250
                    tmp_str_line = axutil_stracat(env, str_line, tmp_buf);
 
251
                    if(tmp_str_line)
 
252
                    {
 
253
                        AXIS2_FREE(env->allocator, str_line);
 
254
                        str_line = tmp_str_line;
 
255
                    }
233
256
                    end_of_line = AXIS2_TRUE;
234
257
                    break;
235
258
                }
245
268
                                       2048 - 1);
246
269
                if (read > 0)
247
270
                {
 
271
                    axis2_char_t* tmp_str_line = NULL;
248
272
                    tmp_buf[read] = AXIS2_ESC_NULL;
249
 
                    strcat(str_line, tmp_buf);
 
273
                    tmp_str_line = axutil_stracat(env, str_line, tmp_buf);
 
274
                    if(tmp_str_line)
 
275
                    {
 
276
                        AXIS2_FREE(env->allocator, str_line);
 
277
                        str_line = tmp_str_line;
 
278
                    }
250
279
                }
251
280
            }
252
281
 
262
291
            {
263
292
                axis2_http_header_t *tmp_header =
264
293
                    axis2_http_header_create_by_str(env, str_line);
265
 
                memset(str_line, 0, 2048);
 
294
                AXIS2_FREE(env->allocator, str_line);
 
295
                str_line = NULL;
266
296
                if (tmp_header)
267
297
                {
268
298
                    axis2_http_simple_request_add_header(request, env,
271
301
            }
272
302
        }
273
303
        end_of_line = AXIS2_FALSE;
 
304
        if(!is_read)
 
305
        {
 
306
            /*if nothing is read, this loop should be broken. Otherwise, going to be endless loop */
 
307
            break; 
 
308
        }
274
309
    }
275
310
    return request;
276
311
}
373
408
        response_body[body_size] = AXIS2_ESC_NULL;
374
409
    }
375
410
 
376
 
    if (body_size <= 0)
 
411
    if (body_size <= 0 && !binary_content)
377
412
    {
378
413
        axis2_http_response_writer_free(response_writer, env);
379
414
        return AXIS2_SUCCESS;
380
415
    }
381
416
 
382
 
    if (AXIS2_FALSE == chuked_encoding)
 
417
    /* This sending a normal SOAP response without chunk transfer encoding */
 
418
    if (AXIS2_FALSE == chuked_encoding && !binary_content)
383
419
    {
384
420
        axis2_status_t write_stat = AXIS2_FAILURE;
385
421
        if (AXIS2_FALSE == binary_content)
404
440
            return AXIS2_FAILURE;
405
441
        }
406
442
    }
407
 
    else
 
443
    
 
444
    /* In the MTOM case we enable chunking inorder to send the attachment */
 
445
    
 
446
    else if(binary_content)
408
447
    {
409
448
        axutil_http_chunked_stream_t *chunked_stream = NULL;
410
 
        int left = body_size;
 
449
        axis2_status_t write_stat = AXIS2_FAILURE;
 
450
        axutil_array_list_t *mime_parts = NULL;
 
451
        axis2_char_t *mtom_sending_callback_name = NULL;
 
452
        
 
453
        mime_parts = axis2_http_simple_response_get_mime_parts(response, env);
 
454
 
 
455
        mtom_sending_callback_name = axis2_http_simple_response_get_mtom_sending_callback_name(
 
456
            response, env);
 
457
 
 
458
        /* If the callback name is not there, then we will check whether there 
 
459
         * is any mime_parts which has type callback. If we found then no point 
 
460
         * of continuing we should return a failure */
 
461
 
 
462
        if(!mtom_sending_callback_name)
 
463
        {
 
464
            if(axis2_http_transport_utils_is_callback_required(
 
465
                env, mime_parts))
 
466
            {
 
467
                AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Sender callback not specified");
 
468
                return AXIS2_FAILURE;
 
469
            }
 
470
        }
 
471
 
411
472
        chunked_stream = axutil_http_chunked_stream_create(env,
412
473
                                                          svr_conn->stream);
 
474
 
 
475
        if(mime_parts)
 
476
        {            
 
477
            write_stat = axis2_http_transport_utils_send_mtom_message(
 
478
                    chunked_stream, env, mime_parts, mtom_sending_callback_name);
 
479
            axutil_http_chunked_stream_free(chunked_stream, env);
 
480
            chunked_stream = NULL;
 
481
                    
 
482
            if(write_stat == AXIS2_FAILURE)
 
483
            {
 
484
                return write_stat;
 
485
            }
 
486
        }    
 
487
        else
 
488
        {
 
489
            return AXIS2_FAILURE;
 
490
        }
 
491
    } 
 
492
    
 
493
    /* Sending a normal SOAP response enabling htpp chunking */
 
494
    else 
 
495
    {    
 
496
        axutil_http_chunked_stream_t *chunked_stream = NULL;
 
497
        int left = body_size;
 
498
        chunked_stream = axutil_http_chunked_stream_create(env, svr_conn->stream);
413
499
        while (left > 0)
414
500
        {
415
501
            left -= axutil_http_chunked_stream_write(chunked_stream, env,
416
 
                                                    response_body, body_size);
 
502
                response_body, body_size);
417
503
        }
418
504
        axutil_http_chunked_stream_write_last_chunk(chunked_stream, env);
419
505
        axutil_http_chunked_stream_free(chunked_stream, env);
464
550
{
465
551
    return axutil_network_handler_get_peer_ip(env, svr_conn->socket);
466
552
}
 
553
 
 
554