aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2010-04-01 03:27:04 +0200
committerHolger Hans Peter Freyther <zecke@selfish.org>2010-04-05 22:02:54 +0200
commitf2f1591ce7fde28d67da30c1998eaa631c2d5897 (patch)
treefb6d05a168270aff00f1a7080c042ab904399b62
parentf36a11a35d18903f29842f51ad0ce7ef63e2f71e (diff)
[mgcp] Export header parsing via mgcp internal
This will be used by the NAT code to implement custom protocol handling on top of that.
-rw-r--r--openbsc/include/openbsc/mgcp_internal.h9
-rw-r--r--openbsc/src/mgcp/mgcp_protocol.c26
2 files changed, 21 insertions, 14 deletions
diff --git a/openbsc/include/openbsc/mgcp_internal.h b/openbsc/include/openbsc/mgcp_internal.h
index 10d0ca6ae..7ce1732f9 100644
--- a/openbsc/include/openbsc/mgcp_internal.h
+++ b/openbsc/include/openbsc/mgcp_internal.h
@@ -61,4 +61,13 @@ struct mgcp_endpoint {
#define ENDPOINT_NUMBER(endp) abs(endp - endp->cfg->endpoints)
+struct mgcp_msg_ptr {
+ unsigned int start;
+ unsigned int length;
+};
+
+int mgcp_analyze_header(struct mgcp_config *cfg, struct msgb *msg,
+ struct mgcp_msg_ptr *ptr, int size,
+ const char **transaction_id, struct mgcp_endpoint **endp);
+
#endif
diff --git a/openbsc/src/mgcp/mgcp_protocol.c b/openbsc/src/mgcp/mgcp_protocol.c
index 6d9adfcae..ba1d6d8aa 100644
--- a/openbsc/src/mgcp/mgcp_protocol.c
+++ b/openbsc/src/mgcp/mgcp_protocol.c
@@ -80,11 +80,6 @@ enum mgcp_connection_mode {
}
-struct mgcp_msg_ptr {
- unsigned int start;
- unsigned int length;
-};
-
struct mgcp_request {
char *name;
struct msgb *(*handle_request) (struct mgcp_config *cfg, struct msgb *msg);
@@ -277,9 +272,9 @@ static struct mgcp_endpoint *find_endpoint(struct mgcp_config *cfg, const char *
return &cfg->endpoints[gw];
}
-static int analyze_header(struct mgcp_config *cfg, struct msgb *msg,
- struct mgcp_msg_ptr *ptr, int size,
- const char **transaction_id, struct mgcp_endpoint **endp)
+int mgcp_analyze_header(struct mgcp_config *cfg, struct msgb *msg,
+ struct mgcp_msg_ptr *ptr, int size,
+ const char **transaction_id, struct mgcp_endpoint **endp)
{
int found;
@@ -315,8 +310,11 @@ static int analyze_header(struct mgcp_config *cfg, struct msgb *msg,
}
*transaction_id = (const char *)&msg->l3h[ptr[0].start];
- *endp = find_endpoint(cfg, (const char *)&msg->l3h[ptr[1].start]);
- return *endp == NULL;
+ if (endp) {
+ *endp = find_endpoint(cfg, (const char *)&msg->l3h[ptr[1].start]);
+ return *endp == NULL;
+ }
+ return 0;
}
static int verify_call_id(const struct mgcp_endpoint *endp,
@@ -350,7 +348,7 @@ static struct msgb *handle_audit_endpoint(struct mgcp_config *cfg, struct msgb *
const char *trans_id;
struct mgcp_endpoint *endp;
- found = analyze_header(cfg, msg, data_ptrs, ARRAY_SIZE(data_ptrs), &trans_id, &endp);
+ found = mgcp_analyze_header(cfg, msg, data_ptrs, ARRAY_SIZE(data_ptrs), &trans_id, &endp);
if (found != 0)
response = 500;
else
@@ -383,7 +381,7 @@ static struct msgb *handle_create_con(struct mgcp_config *cfg, struct msgb *msg)
int error_code = 500;
int port;
- found = analyze_header(cfg, msg, data_ptrs, ARRAY_SIZE(data_ptrs), &trans_id, &endp);
+ found = mgcp_analyze_header(cfg, msg, data_ptrs, ARRAY_SIZE(data_ptrs), &trans_id, &endp);
if (found != 0)
return create_response(500, "CRCX", trans_id);
@@ -482,7 +480,7 @@ static struct msgb *handle_modify_con(struct mgcp_config *cfg, struct msgb *msg)
struct mgcp_endpoint *endp;
int error_code = 500;
- found = analyze_header(cfg, msg, data_ptrs, ARRAY_SIZE(data_ptrs), &trans_id, &endp);
+ found = mgcp_analyze_header(cfg, msg, data_ptrs, ARRAY_SIZE(data_ptrs), &trans_id, &endp);
if (found != 0)
return create_response(error_code, "MDCX", trans_id);
@@ -595,7 +593,7 @@ static struct msgb *handle_delete_con(struct mgcp_config *cfg, struct msgb *msg)
struct mgcp_endpoint *endp;
int error_code = 500;
- found = analyze_header(cfg, msg, data_ptrs, ARRAY_SIZE(data_ptrs), &trans_id, &endp);
+ found = mgcp_analyze_header(cfg, msg, data_ptrs, ARRAY_SIZE(data_ptrs), &trans_id, &endp);
if (found != 0)
return create_response(error_code, "DLCX", trans_id);