Hello, I am new to apache and c and need help in developing output filter which need to collect (headers and body ) and send PUT request to external webserver. Currently I am getting child pid 7106 exit signal Segmentation fault (11) error in my filter: Can somebody pinpoint if I do something fundamentally wrong, my code snippet: #include "httpd.h" #include "http_connection.h" #include "http_config.h" #include "http_core.h" #include "http_log.h" #include "apr_strings.h" #include "apr_tables.h" #define HEADEREND CRLF CRLF char *authHost = "localhost"; static const char *const tabaseurl= "http://localhost:8080/"; typedef struct { apr_socket_t *sock; } s_ctx; static int logError(apr_status_t status, char *message, request_rec *request) { ap_log_rerror(APLOG_MARK, APLOG_ERR, status, request, "ta_put: error %s", message); return HTTP_SERVICE_UNAVAILABLE; } static int ta_filter_init(ap_filter_t* f) { request_rec *r = f->r; //apr_socket_t *sock; apr_sockaddr_t *sockaddr; apr_status_t status; apr_interval_time_t timeout = 5000000; conn_rec *c = f->c; struct iovec vec[1]; apr_size_t len; char *authRequest; authRequest = apr_pstrcat(r->pool, "PUT " , tabaseurl," /HTTP/1.1",CRLF,"Host: ", authHost, CRLF, "Content-Length: 0", CRLF, "Connection: close",HEADEREND); ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, c->base_server, "mod_tafilter1: in the init 2 filter function") ; s_ctx* sctx = f->ctx = apr_pcalloc(r->pool, sizeof(s_ctx)); if ((status = apr_sockaddr_info_get(&sockaddr, authHost, APR_INET, 8080, 0, r->pool)) != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, c->base_server,"tafiltert1:problem creating socket address" ) ; return logError(status, "creating socket address", r); } if ((status = apr_socket_create(&(sctx->sock), sockaddr->family, SOCK_STREAM, APR_PROTO_TCP, r->pool)) != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, c->base_server,"tafiltert1:problem creating socket" ) ; return logError(status, "creating socket", r); } // apr_socket_opt_set( s, APR_SO_NONBLOCK, 1 ); if ((status = apr_socket_timeout_set(sctx->sock, timeout)) != APR_SUCCESS) { return logError(status, "setting socket timeout", r); } if ((status = apr_socket_connect(sctx->sock, sockaddr)) != APR_SUCCESS) { return logError(status, "connecting", r); } apr_size_t item_size = strlen(authRequest); vec[0].iov_base = authRequest; vec[0].iov_len = item_size; status = apr_socket_sendv(sctx->sock, vec, 1, &len); if (status != APR_SUCCESS) { return logError(status, "sending header data", r); } return OK ; } static apr_status_t ta_out_filter(ap_filter_t *f,apr_bucket_brigade *bb){ request_rec *r = f->r; //apr_socket_t *sock; //apr_sockaddr_t *sockaddr; apr_status_t status; //apr_interval_time_t timeout = 5000000; //char *authRequest; conn_rec *c = f->c; apr_size_t len; apr_bucket* b; struct iovec vec[1]; ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, c->base_server, "mod_tafilter1: in the output filter function") ; s_ctx* sctx = (s_ctx*) f->ctx; if (sctx == NULL) { ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, c->base_server, "mod_tafilter1: in the init filter function") ; ta_filter_init(f) ; //sctx = f->ctx ; } for (b = APR_BRIGADE_FIRST(bb); b != APR_BRIGADE_SENTINEL(bb); b = APR_BUCKET_NEXT(b)) { ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, c->base_server, "tafiltert1: %s (%s-%s): %" APR_SIZE_T_FMT " bytes", f->frec->name, (APR_BUCKET_IS_METADATA(b)) ? "metadata" : "data", b->type->name, b->length) ; if (APR_BUCKET_IS_EOS(b)) { char * end = apr_pstrcat(r->pool,NULL); vec[0].iov_base = end; vec[0].iov_len = sizeof(end); status = apr_socket_sendv(sctx->sock, vec, 1, &len); // if (status != APR_SUCCESS) { // logError(status, "sending eof", r); // } apr_socket_close(sctx->sock); } if (!(APR_BUCKET_IS_METADATA(b))) { const char *buff; apr_size_t nbytes; if (apr_bucket_read(b, &buff, &nbytes, APR_BLOCK_READ) == APR_SUCCESS) { vec[0].iov_base = &buff; vec[0].iov_len = nbytes; status = apr_socket_sendv(sctx->sock, vec, 1, &len); // if (status != APR_SUCCESS) { // logError(status, "sending data", r); //} } } else { ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, c->base_server, "tafilter1: %s (%s-%s): %s", f->frec->name, (APR_BUCKET_IS_METADATA(b)) ? "metadata" : "data", b->type->name, "error reading data"); } } return ap_pass_brigade(f->next, bb) ; } static int myta_pre_conn(conn_rec *c, void *csd) { ap_add_output_filter("MY_TA_OUT", NULL, NULL, c); return OK; } static void myta_register_hooks(apr_pool_t *p) { /* * We know that SSL is CONNECTION + 5 */ ap_register_output_filter("MY_TA_OUT", ta_out_filter,ta_filter_init, AP_FTYPE_CONNECTION + 3) ; //ap_register_output_filter("MY_TA_OUT", ta_out_filter,ta_filter_init, AP_FTYPE_RESOURCE) ; ap_hook_pre_connection(myta_pre_conn, NULL, NULL, APR_HOOK_MIDDLE); } module AP_MODULE_DECLARE_DATA tafilter1_module = { STANDARD20_MODULE_STUFF, NULL, NULL, NULL, NULL, NULL, myta_register_hooks }; --------------------------------------------------------------------- The official User-To-User support forum of the Apache HTTP Server Project. See <URL:http://httpd.apache.org/userslist.html> for more info. To unsubscribe, e-mail: users-unsubscribe@xxxxxxxxxxxxxxxx " from the digest: users-digest-unsubscribe@xxxxxxxxxxxxxxxx For additional commands, e-mail: users-help@xxxxxxxxxxxxxxxx