parse_nameaddr.c

Go to the documentation of this file.
00001 /* 
00002  * $Id$
00003  *
00004  * Copyright (C) 2001-2003 FhG Fokus
00005  *
00006  * This file is part of ser, a free SIP server.
00007  *
00008  * ser 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  * ser 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  * History
00023  * --------
00024  * 2003-03-24 Created by janakj
00025  * 2003-04-26 ZSW (jiri)
00026  */
00027 
00034 #include <string.h>
00035 #include "../dprint.h"
00036 #include "parse_nameaddr.h"
00037 #include "parser_f.h"
00038 #include "../ut.h"
00039 
00040 
00045 int parse_nameaddr(str* _s, name_addr_t* _a)
00046 {
00047         char* uri_end;
00048 
00049         if (!_s || !_a) {
00050                 return -1;
00051         }
00052 
00053         _a->name.s = _s->s;
00054 
00055         _a->uri.s = find_not_quoted(_s, '<'); 
00056         if (_a->uri.s) {
00057                 _a->name.len = _a->uri.s - _a->name.s;
00058                 _a->uri.s++; /* We will skip < character */
00059         } else {
00060                 return -3;
00061         }
00062         
00063         _a->uri.len = _s->len - _a->name.len - 1;
00064         uri_end = find_not_quoted(&_a->uri, '>');
00065         
00066         if (!uri_end) {
00067                 return -4;
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 
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 }