Ver código fonte

- Really commited the allow parser now

Jan Janak 21 anos atrás
pai
commit
6def693e0d
2 arquivos alterados com 134 adições e 0 exclusões
  1. 83 0
      parser/parse_allow.c
  2. 51 0
      parser/parse_allow.h

+ 83 - 0
parser/parse_allow.c

@@ -0,0 +1,83 @@
+/*
+ * $Id$
+ *
+ * Copyright (c) 2004 Juha Heinanen
+ *
+ * This file is part of ser, a free SIP server.
+ *
+ * ser 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
+ *
+ * For a license to use the ser software under conditions
+ * other than those described here, or to purchase support for this
+ * software, please contact iptel.org by e-mail at the following addresses:
+ *    [email protected]
+ *
+ * ser 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
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include "../dprint.h"
+#include "../mem/mem.h"
+#include "parse_allow.h"
+#include "parse_methods.h"
+#include "msg_parser.h"
+
+ 
+/*
+ * This method is used to parse Allow header.
+ *
+ * params: msg : sip msg
+ * returns 0 on success,
+ *        -1 on failure.
+ */
+int parse_allow_header(struct hdr_field* _hf)
+{
+	unsigned int* methods;
+	
+	if (!_hf) {
+		LOG(L_ERR, "parse_allow_header: Invalid parameter value\n");
+		return -1;
+	}
+	
+	     /* maybe the header is already parsed! */
+ 	if (_hf->parsed) {
+ 		return 0;
+	}
+
+	     /* bad luck! :-( - we have to parse it */
+	methods = pkg_malloc(sizeof(unsigned int));
+ 	if (methods == 0) {
+ 		LOG(L_ERR, "ERROR:parse_allow_header: Out of pkg_memory\n");
+ 		return -1;
+ 	}
+
+	if (!parse_methods(&(_hf->body), methods)) {
+ 		LOG(L_ERR, "ERROR:parse_allow_header: Bad allow header\n"); 
+ 		pkg_free(methods);
+		return -1;
+ 	}
+
+ 	_hf->parsed = methods;
+ 	return 0;
+}
+
+
+/*
+ * Release memory
+ */
+void free_allow(unsigned int** _methods)
+{
+	if (_methods && *_methods) pkg_free(*_methods);
+	*_methods = 0;
+}

+ 51 - 0
parser/parse_allow.h

@@ -0,0 +1,51 @@
+/*
+ * $Id$
+ *
+ * Copyright (c) 2004 Juha Heinanen
+ *
+ * This file is part of ser, a free SIP server.
+ *
+ * ser 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
+ *
+ * For a license to use the ser software under conditions
+ * other than those described here, or to purchase support for this
+ * software, please contact iptel.org by e-mail at the following addresses:
+ *    [email protected]
+ *
+ * ser 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
+ */
+ 
+#ifndef PARSE_ALLOW_H
+#define PARSE_ALLOW_H
+ 
+#include "hf.h"
+
+ 
+/* 
+ * casting macro for accessing RPID body 
+ */
+#define get_allow_methods(p_msg) (unsigned int)(p_msg)->allow->parsed)
+
+
+/*
+ * Parse Allow HF body
+ */
+int parse_allow(struct hdr_field* _h);
+
+
+/*
+ * Release memory
+ */
+void free_allow(unsigned int** _methods);
+
+#endif /* PARSE_ALLOW_H */