[SR-Dev] git:janakj/kcore: Parser helper functions not present in sip-router.
Jan Janak
jan at iptel.org
Fri Mar 6 15:23:03 CET 2009
Module: sip-router
Branch: janakj/kcore
Commit: 66b8eec6fd1123e10b805d11d8d78cfb50c7a33e
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=66b8eec6fd1123e10b805d11d8d78cfb50c7a33e
Author: Jan Janak <jan at iptel.org>
Committer: Jan Janak <jan at iptel.org>
Date: Thu Mar 5 23:57:38 2009 +0100
Parser helper functions not present in sip-router.
That include parse_to_uri and parse_from_uri. Also adding errinfo.[ch]
which is required by the parser helpers.
---
lib/kcore/errinfo.c | 75 ++++++++++++++++++++++++++++++++++++++++++++
lib/kcore/errinfo.h | 59 ++++++++++++++++++++++++++++++++++
lib/kcore/parser_helpers.c | 65 ++++++++++++++++++++++++++++++++++++++
lib/kcore/parser_helpers.h | 11 ++++++
4 files changed, 210 insertions(+), 0 deletions(-)
diff --git a/lib/kcore/errinfo.c b/lib/kcore/errinfo.c
new file mode 100644
index 0000000..799549f
--- /dev/null
+++ b/lib/kcore/errinfo.c
@@ -0,0 +1,75 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2006 Voice Sistem SRL
+ *
+ * This file is part of Kamailio, a free SIP server.
+ *
+ * Kamailio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version
+ *
+ * Kamailio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/*!
+ * \file errinfo.c
+ * \brief Kamailio Error info functions
+ */
+
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "../../dprint.h"
+#include "errinfo.h"
+
+/*! global error info */
+err_info_t _oser_err_info;
+
+/*! \brief Get global error state
+ */
+err_info_t* get_err_info(void) { return &_oser_err_info; }
+
+/*! \brief Initialize global error state
+ */
+void init_err_info(void)
+{
+ memset(&_oser_err_info, 0, sizeof(err_info_t));
+}
+
+/*! \brief Set suggested error info message
+ */
+void set_err_info(int ec, int el, char *info)
+{
+ LM_DBG("ec: %d, el: %d, ei: '%s'\n", ec, el,
+ (info)?info:"");
+ _oser_err_info.eclass = ec;
+ _oser_err_info.level = el;
+ if(info)
+ {
+ _oser_err_info.info.s = info;
+ _oser_err_info.info.len = strlen(info);
+ }
+}
+
+/*! \brief Set suggested error reply
+ */
+void set_err_reply(int rc, char *rr)
+{
+ _oser_err_info.rcode = rc;
+ if(rr)
+ {
+ _oser_err_info.rreason.s = rr;
+ _oser_err_info.rreason.len = strlen(rr);
+ }
+}
+
diff --git a/lib/kcore/errinfo.h b/lib/kcore/errinfo.h
new file mode 100644
index 0000000..fb4bf6b
--- /dev/null
+++ b/lib/kcore/errinfo.h
@@ -0,0 +1,59 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2006 Voice Sistem SRL
+ *
+ * This file is part of Kamailio, a free SIP server.
+ *
+ * Kamailio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version
+ *
+ * Kamailio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/*!
+ * \file errinfo.h
+ * \brief Error handling
+ */
+
+
+#ifndef _errinfo_h_
+#define _errinfo_h_
+
+#include "../../str.h"
+
+/*! \name ErrorClasses error clases */
+#define OSER_EC_PARSER 1 /*!< parse error */
+#define OSER_EC_PMEMORY 2 /*!< private memory error */
+#define OSER_EC_SMEMORY 3 /*!< share memory error */
+
+#define OSER_EL_CRITIC 1
+#define OSER_EL_HIGH 2
+#define OSER_EL_MEDIUM 3 /*!< severity level normal - used by parsing errors */
+#define OSER_EL_NORMAL 4
+#define OSER_EL_LOW 5
+
+typedef struct err_info_
+{
+ int eclass; /*!< error class */
+ int level; /*!< severity level (lower is higher) */
+ str info; /*!< error details */
+ int rcode; /*!< recommended reply code */
+ str rreason; /*!< recommended reply reason phrase */
+} err_info_t;
+
+void init_err_info(void);
+void set_err_info(int ec, int el, char *info);
+void set_err_reply(int rc, char *rr);
+err_info_t* get_err_info(void);
+
+#endif
diff --git a/lib/kcore/parser_helpers.c b/lib/kcore/parser_helpers.c
new file mode 100644
index 0000000..15c48c6
--- /dev/null
+++ b/lib/kcore/parser_helpers.c
@@ -0,0 +1,65 @@
+#include "parser_helpers.h"
+#include "errinfo.h"
+#include "../../parser/parse_to.h"
+#include "../../parser/parse_from.h"
+#include "../../dprint.h"
+
+#include <string.h>
+
+struct sip_uri *parse_to_uri(struct sip_msg *msg)
+{
+ struct to_body *tb = NULL;
+
+ if(msg==NULL || msg->to==NULL || msg->to->parsed==NULL)
+ return NULL;
+
+ tb = get_to(msg);
+
+ if(tb->parsed_uri.user.s!=NULL || tb->parsed_uri.host.s!=NULL)
+ return &tb->parsed_uri;
+
+ if (parse_uri(tb->uri.s, tb->uri.len , &tb->parsed_uri)<0)
+ {
+ LM_ERR("failed to parse To uri\n");
+ memset(&tb->parsed_uri, 0, sizeof(struct sip_uri));
+ set_err_info(OSER_EC_PARSER, OSER_EL_MEDIUM, "error parsing To uri");
+ set_err_reply(400, "bad To uri");
+ return NULL;
+ }
+
+ return &tb->parsed_uri;
+}
+
+
+struct sip_uri *parse_from_uri(struct sip_msg *msg)
+{
+ struct to_body *tb = NULL;
+
+ if(msg==NULL)
+ return NULL;
+
+ if(parse_from_header(msg)<0)
+ {
+ LM_ERR("cannot parse FROM header\n");
+ return NULL;
+ }
+
+ if(msg->from==NULL || get_from(msg)==NULL)
+ return NULL;
+
+ tb = get_from(msg);
+
+ if(tb->parsed_uri.user.s!=NULL || tb->parsed_uri.host.s!=NULL)
+ return &tb->parsed_uri;
+
+ if (parse_uri(tb->uri.s, tb->uri.len , &tb->parsed_uri)<0)
+ {
+ LM_ERR("failed to parse From uri\n");
+ memset(&tb->parsed_uri, 0, sizeof(struct sip_uri));
+ set_err_info(OSER_EC_PARSER, OSER_EL_MEDIUM, "error parsing From uri");
+ set_err_reply(400, "bad From uri");
+ return NULL;
+ }
+ return &tb->parsed_uri;
+}
+
diff --git a/lib/kcore/parser_helpers.h b/lib/kcore/parser_helpers.h
new file mode 100644
index 0000000..58e8764
--- /dev/null
+++ b/lib/kcore/parser_helpers.h
@@ -0,0 +1,11 @@
+#ifndef _PARSER_HELPERS_H
+#define _PARSER_HELPERS_H
+
+#include "../../parser/msg_parser.h"
+#include "../../parser/parse_uri.h"
+
+struct sip_uri* parse_to_uri(struct sip_msg* msg);
+
+struct sip_uri* parse_from_uri(struct sip_msg* msg);
+
+#endif /* _PARSER_HELPERS_H */
More information about the sr-dev
mailing list