浏览代码

- Retry-After parser missing files (from older commit)

Andrei Pelinescu-Onciul 18 年之前
父节点
当前提交
1c3889068b
共有 3 个文件被更改,包括 210 次插入0 次删除
  1. 74 0
      parser/case_retr.h
  2. 95 0
      parser/parse_retry_after.c
  3. 41 0
      parser/parse_retry_after.h

+ 74 - 0
parser/case_retr.h

@@ -0,0 +1,74 @@
+/* 
+ * $Id$ 
+ *
+ * Expires Header Field Name Parsing Macros
+ *
+ * Copyright (C) 2007 iptelorg GmbH
+ *
+ * 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
+ *
+ * History:
+ * ---------
+ *  2007-07-27  created by andrei
+ */
+
+
+#ifndef CASE_RETR_H
+#define CASE_RETR_H
+
+#include "../comp_defs.h"
+#include "keys.h"
+
+#define RETR_TER_CASE				\
+	switch(LOWER_DWORD(val)){	\
+		case _ter1_:				\
+			hdr->type = HDR_RETRY_AFTER_T;	\
+			hdr->name.len = 11;				\
+			return (p + 4);					\
+		\
+		case _ter2_:                     \
+			hdr->type = HDR_RETRY_AFTER_T;	\
+			p += 4;							\
+			goto dc_end;					\
+	}
+
+
+
+#define RETR_Y_AF_CASE				\
+	if (LOWER_DWORD(val)==_y_af_){	\
+		p+=4;						\
+		val=READ(p);				\
+		RETR_TER_CASE;				\
+		goto other;					\
+	}
+
+
+
+
+#define retr_CASE		\
+	p+=4;			\
+	val=READ(p);	\
+	RETR_Y_AF_CASE;	\
+	goto other;
+
+
+#endif /* CASE_RETR_H */

+ 95 - 0
parser/parse_retry_after.c

@@ -0,0 +1,95 @@
+/* 
+ * $Id$ 
+ *
+ * Copyright (C) 2007 iptelorg GmbH
+ *
+ * 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
+ * 
+ * History:
+ * --------
+ *  2007-07-27  created by andrei
+ */
+
+
+#include "../comp_defs.h"
+#include "parse_retry_after.h"
+#include "parser_f.h"  /* eat_space_end and so on */
+#include "parse_def.h"
+#include "../dprint.h"
+#include "../mem/mem.h"
+
+/* Parse the Retry-after header field */
+char* parse_retry_after(char *buf, char* end, unsigned* after, int* err)
+{
+	char *t;
+	int i;
+	unsigned val;
+	
+	val=0;
+	t=buf;
+	
+	t=eat_lws_end(t, end);
+	if (t>=end) goto error;
+	for (i=0; t<end; i++,t++){
+		if ((*t >= '0') && (*t <= '9')){
+			val=val*10+(*t-'0');
+		}else{
+			switch(*t){
+				/* for now we don't care about retry-after params or comment*/
+				case ' ':
+				case '\t':
+				case ';':
+				case '\r':
+				case '\n':
+					goto found;
+				default:
+					/* invalid char */
+					goto error;
+			}
+		}
+	}
+	goto error_nocrlf; /* end reached without encountering cr or lf */
+found:
+	if (i>10 || i==0) /* too many  or too few digits */
+		goto error;
+	*after=val;
+	/* find the end of header */
+	for (; t<end; t++){
+		if (*t=='\n'){
+			if (((t+1)<end) && (*(t+1)=='\r'))
+				t++;
+			if (((t+1)<end) && (*(t+1)==' ' || *(t+1)=='\t')){
+				t++;
+				continue; /* line folding ... */
+			}
+			*err=0;
+			return t+1;
+		}
+	}
+error_nocrlf:
+	LOG(L_ERR, "ERROR: parse_retry_after: strange EoHF\n");
+	goto error;
+error:
+	LOG(L_ERR, "ERROR: parse_retry_after: bad Retry-After header \n");
+	*err=1;
+	return t;
+}

+ 41 - 0
parser/parse_retry_after.h

@@ -0,0 +1,41 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2007 iptelorg GmbH
+ *
+ * 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_retry_after_h
+#define _parse_retry_after_h
+
+#include "../str.h"
+
+
+/* Parse Retry-After header field */
+char* parse_retry_after(char *buf, char* end, unsigned* after, int* err);
+
+
+
+
+#endif