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>
26
28
struct axis2_simple_http_svr_conn
152
154
axis2_simple_http_svr_conn_t * svr_conn,
153
155
const axutil_env_t * env)
155
axis2_char_t str_line[2048];
157
axis2_char_t* str_line = NULL;
156
158
axis2_char_t tmp_buf[2048];
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;
163
memset(str_line, 0, 2048);
165
166
axutil_stream_peek_socket(svr_conn->stream, env, tmp_buf,
176
177
end - start + 2);
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);
185
AXIS2_FREE(env->allocator, str_line);
186
str_line = tmp_str_line;
192
199
read = axutil_stream_read(svr_conn->stream, env, tmp_buf, 2048 - 1);
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);
207
AXIS2_FREE(env->allocator, str_line);
208
str_line = tmp_str_line;
201
214
request_line = axis2_http_request_line_parse_line(env, str_line);
215
AXIS2_FREE(env->allocator, str_line);
202
218
if (!request_line)
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)
231
axis2_bool_t is_read = AXIS2_FALSE;
217
233
axutil_stream_peek_socket(svr_conn->stream, env, tmp_buf,
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);
228
245
end - start + 2);
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);
253
AXIS2_FREE(env->allocator, str_line);
254
str_line = tmp_str_line;
233
256
end_of_line = AXIS2_TRUE;
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);
276
AXIS2_FREE(env->allocator, str_line);
277
str_line = tmp_str_line;
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);
268
298
axis2_http_simple_request_add_header(request, env,
373
408
response_body[body_size] = AXIS2_ESC_NULL;
411
if (body_size <= 0 && !binary_content)
378
413
axis2_http_response_writer_free(response_writer, env);
379
414
return AXIS2_SUCCESS;
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)
384
420
axis2_status_t write_stat = AXIS2_FAILURE;
385
421
if (AXIS2_FALSE == binary_content)
404
440
return AXIS2_FAILURE;
444
/* In the MTOM case we enable chunking inorder to send the attachment */
446
else if(binary_content)
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;
453
mime_parts = axis2_http_simple_response_get_mime_parts(response, env);
455
mtom_sending_callback_name = axis2_http_simple_response_get_mtom_sending_callback_name(
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 */
462
if(!mtom_sending_callback_name)
464
if(axis2_http_transport_utils_is_callback_required(
467
AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Sender callback not specified");
468
return AXIS2_FAILURE;
411
472
chunked_stream = axutil_http_chunked_stream_create(env,
412
473
svr_conn->stream);
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;
482
if(write_stat == AXIS2_FAILURE)
489
return AXIS2_FAILURE;
493
/* Sending a normal SOAP response enabling htpp chunking */
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);
415
501
left -= axutil_http_chunked_stream_write(chunked_stream, env,
416
response_body, body_size);
502
response_body, body_size);
418
504
axutil_http_chunked_stream_write_last_chunk(chunked_stream, env);
419
505
axutil_http_chunked_stream_free(chunked_stream, env);