parse_nameaddr.c

Go to the documentation of this file.
00001 /*
00002  * $Id: parse_nameaddr.c 4720 2008-08-23 10:56:15Z henningw $
00003  *
00004  * Copyright (C) 2001-2003 FhG Fokus
00005  *
00006  * This file is part of Kamailio, a free SIP server.
00007  *
00008  * Kamailio is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version
00012  *
00013  * Kamailio is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License 
00019  * along with this program; if not, write to the Free Software 
00020  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021  */
00022 
00023 /*!
00024  * \file
00025  * \brief Name-addr part parser
00026  * \ingroup parser
00027  */
00028 
00029 #include <string.h>
00030 #include "../dprint.h"
00031 #include "parse_nameaddr.h"
00032 #include "parser_f.h"
00033 #include "../ut.h"
00034 
00035 
00036 /*!
00037  * Parse name-addr part, the given string can be longer,
00038  * parsing will stop when closing
00039  * \return zero on success (if found), negative value on error
00040  */
00041 int parse_nameaddr(str* _s, name_addr_t* _a)
00042 {
00043    char* uri_end;
00044 
00045    if (!_s || !_a) {
00046       LM_ERR("invalid parameter value\n");
00047       return -1;
00048    }
00049 
00050    _a->name.s = _s->s;
00051 
00052    _a->uri.s = find_not_quoted(_s, '<'); 
00053    if (_a->uri.s) {
00054       _a->name.len = _a->uri.s - _a->name.s;
00055       _a->uri.s++; /* We will skip < character */
00056    } else {
00057       LM_ERR("no < found\n");
00058       return -3;
00059    }
00060    
00061    _a->uri.len = _s->len - _a->name.len - 1;
00062    uri_end = find_not_quoted(&_a->uri, '>');
00063    
00064    if (!uri_end) {
00065       LM_ERR("no > found\n");
00066       return -4;
00067    }
00068 
00069         /* Total length of the field including <> */
00070    _a->len = uri_end - _a->name.s + 1;
00071    
00072    _a->uri.len = uri_end - _a->uri.s;
00073    return 0;
00074 }
00075 
00076 
00077 /*!
00078  * Print a name-addr structure, just for debugging
00079  */
00080 void print_nameaddr(FILE* _o, name_addr_t* _a)
00081 {
00082    fprintf(_o, "---name-addr---\n");
00083    fprintf(_o, "name: '%.*s'\n", _a->name.len, ZSW(_a->name.s));
00084    fprintf(_o, "uri : '%.*s'\n", _a->uri.len, ZSW(_a->uri.s));
00085    fprintf(_o, "len : %d\n", _a->len);
00086    fprintf(_o, "---/name-addr---\n");
00087 }

Generated on Thu May 24 00:00:28 2012 for Kamailio - The Open Source SIP Server by  doxygen 1.5.6