The srv_echo.c is an example service implementation, which does not modifies the content
#include "common.h"
#include "c-icap.h"
#include "service.h"
#include "header.h"
#include "body.h"
#include "simple_api.h"
#include "debug.h"
int echo_check_preview_handler(char *preview_data, int preview_data_len,
void echo_close_service();
void echo_release_request_data(void *data);
int echo_io(char *wbuf, int *wlen, char *rbuf, int *rlen, int iseof,
"echo",
"Echo demo service",
ICAP_RESPMOD | ICAP_REQMOD,
echo_init_service,
NULL,
echo_close_service,
echo_init_request_data,
echo_release_request_data,
echo_check_preview_handler,
echo_end_of_data_handler,
echo_io,
NULL,
NULL
};
struct echo_req_data {
ci_ring_buf_t *body;
int eof;
};
{
ci_debug_printf(5, "Initialization of echo module......\n");
return CI_OK;
}
void echo_close_service()
{
ci_debug_printf(5,"Service shutdown!\n");
}
{
struct echo_req_data *echo_data;
echo_data = malloc(sizeof(struct echo_req_data));
if (!echo_data) {
ci_debug_printf(1, "Memory allocation failed inside echo_init_request_data!\n");
return NULL;
}
echo_data->body = ci_ring_buf_new(4096);
else
echo_data->body = NULL;
echo_data->eof = 0;
return echo_data;
}
void echo_release_request_data(void *data)
{
struct echo_req_data *echo_data = (struct echo_req_data *)data;
if (echo_data->body)
ci_ring_buf_destroy(echo_data->body);
free(echo_data);
}
static int whattodo = 0;
int echo_check_preview_handler(char *preview_data, int preview_data_len,
{
ci_off_t content_len;
struct echo_req_data *echo_data = ci_service_data(req);
ci_debug_printf(9, "We expect to read :%" PRINTF_OFF_T " body data\n",
(CAST_OFF_T) content_len);
return CI_MOD_ALLOW204;
if (!preview_data_len)
return CI_MOD_CONTINUE;
if (whattodo == 0) {
whattodo = 1;
ci_debug_printf(8, "Echo service will process the request\n");
if (preview_data_len) {
ci_ring_buf_write(echo_data->body, preview_data, preview_data_len);
}
return CI_MOD_CONTINUE;
} else {
whattodo = 0;
ci_debug_printf(8, "Allow 204...\n");
return CI_MOD_ALLOW204;
}
}
{
struct echo_req_data *echo_data = ci_service_data(req);
echo_data->eof = 1;
return CI_MOD_DONE;
}
int echo_io(char *wbuf, int *wlen, char *rbuf, int *rlen, int iseof,
{
int ret;
struct echo_req_data *echo_data = ci_service_data(req);
ret = CI_OK;
if (rlen && rbuf) {
*rlen = ci_ring_buf_write(echo_data->body, rbuf, *rlen);
if (*rlen < 0)
ret = CI_ERROR;
}
if (wbuf && wlen) {
*wlen = ci_ring_buf_read(echo_data->body, wbuf, *wlen);
if (*wlen == 0 && echo_data->eof == 1)
*wlen = CI_EOF;
}
return ret;
}