2 * $Id: parse_expires.c,v 1.6 2004/08/24 09:01:25 janakj Exp $
4 * Expires header field body parser
6 * Copyright (C) 2001-2003 FhG Fokus
8 * This file is part of ser, a free SIP server.
10 * ser is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version
15 * For a license to use the ser software under conditions
16 * other than those described here, or to purchase support for this
17 * software, please contact iptel.org by e-mail at the following addresses:
20 * ser is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 * 2003-04-26 ZSW (jiri)
35 #include "parse_expires.h"
36 #include <stdio.h> /* printf */
37 #include "../mem/mem.h" /* pkg_malloc, pkg_free */
38 #include "../dprint.h"
39 #include "../trim.h" /* trim_leading */
40 #include <string.h> /* memset */
44 static inline int expires_parser(char* _s, int _l, exp_body_t* _e)
55 LOG(L_ERR, "expires_parser(): Empty body\n");
62 for(i = 0; i < tmp.len; i++) {
63 if ((tmp.s[i] >= '0') && (tmp.s[i] <= '9')) {
65 _e->val += tmp.s[i] - '0';
77 /* Exit normally here, we want to be backwards compatible with
78 * RFC2543 entities that can put absolute time here
81 LOG(L_ERR, "expires_parser(): Invalid character\n");
97 * Parse expires header field body
99 int parse_expires(struct hdr_field* _h)
104 return 0; /* Already parsed */
107 e = (exp_body_t*)pkg_malloc(sizeof(exp_body_t));
109 LOG(L_ERR, "parse_expires(): No memory left\n");
113 memset(e, 0, sizeof(exp_body_t));
115 if (expires_parser(_h->body.s, _h->body.len, e) < 0) {
116 LOG(L_ERR, "parse_expires(): Error while parsing\n");
121 _h->parsed = (void*)e;
127 * Free all memory associated with exp_body_t
129 void free_expires(exp_body_t** _e)
137 * Print exp_body_t content, for debugging only
139 void print_expires(exp_body_t* _e)
141 printf("===Expires===\n");
142 printf("text: \'%.*s\'\n", _e->text.len, ZSW(_e->text.s));
143 printf("val : %d\n", _e->val);
144 printf("===/Expires===\n");