Skip to content

Commit

Permalink
Trace api implementation in rest_client module
Browse files Browse the repository at this point in the history
	Rest messages can now be traced using siptrace module.
All GET and POST messages will be traced, both the requests and
the replies. Also the correlation id will be set with the value
of the callid(HEP protocol related) in order to be able to
correlate them with the SIP messages.
  • Loading branch information
ionutrazvanionita committed Sep 15, 2016
1 parent 3e2e00a commit 2291bf1
Show file tree
Hide file tree
Showing 4 changed files with 428 additions and 7 deletions.
1 change: 1 addition & 0 deletions modules/proto_hep/hep.h
Expand Up @@ -49,6 +49,7 @@
#define HEP_OPENSIPS_VENDOR_ID 0x0003

#define HEP_PROTO_TYPE_SIP 0x01
#define HEP_PROTO_TYPE_REST 0x055

enum hep_generic_chunks { HEP_PROTO_FAMILY=0x0001, HEP_PROTO_ID=0x0002,
HEP_IPV4_SRC=0x0003, HEP_IPV4_DST=0x0004, HEP_IPV6_SRC=0x0005,
Expand Down
20 changes: 18 additions & 2 deletions modules/rest_client/rest_client.c
Expand Up @@ -33,6 +33,7 @@
#include "../../mem/mem.h"
#include "../../mem/shm_mem.h"
#include "../../mod_fix.h"
#include "../siptrace/siptrace.h"

#include "rest_methods.h"

Expand All @@ -56,6 +57,13 @@ static int mod_init(void);
static int child_init(int rank);
static void mod_destroy(void);

/* Tracing api */
siptrace_api_t siptrace_api;
/* id with which rest module will be identified by siptrace */
trace_type_id_t rest_type_id;
/* rest module string identifier */
static const char* rest_id_s = "rest";

/*
* Fixup functions
*/
Expand Down Expand Up @@ -211,6 +219,12 @@ static int mod_init(void)

multi_handle = curl_multi_init();

/* try loading siptrace api */
if (load_siptrace_api(&siptrace_api) == 0) {
/* tracing module loaded */
rest_type_id = siptrace_api.register_type((char *)rest_id_s);
}

LM_INFO("Module initialized!\n");

return 0;
Expand Down Expand Up @@ -368,7 +382,8 @@ static int w_async_rest_get(struct sip_msg *msg, async_resume_module **resume_f,
memset(param, '\0', sizeof *param);

read_fd = start_async_http_req(msg, REST_CLIENT_GET, url.s, NULL, NULL,
&param->handle, &param->body, ctype_pv ? &param->ctype : NULL);
&param->handle, &param->body, ctype_pv ? &param->ctype : NULL,
&param->rest_tparam);

/* error occurred; no transfer done */
if (read_fd == ASYNC_NO_IO) {
Expand Down Expand Up @@ -438,7 +453,8 @@ static int w_async_rest_post(struct sip_msg *msg, async_resume_module **resume_f
memset(param, '\0', sizeof *param);

read_fd = start_async_http_req(msg, REST_CLIENT_POST, url.s, body.s, ctype.s,
&param->handle, &param->body, ctype_pv ? &param->ctype : NULL);
&param->handle, &param->body, ctype_pv ? &param->ctype : NULL,
&param->rest_tparam);

/* error occurred; no transfer done */
if (read_fd == ASYNC_NO_IO) {
Expand Down

0 comments on commit 2291bf1

Please sign in to comment.