mirror of https://github.com/sipwise/sems.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
123 lines
2.9 KiB
123 lines
2.9 KiB
/*
|
|
* $Id$
|
|
*
|
|
* Copyright (C) 2002-2003 Fhg Fokus
|
|
*
|
|
* This file is part of sems, a free SIP media server.
|
|
*
|
|
* sems 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:
|
|
* info@iptel.org
|
|
*
|
|
* sems 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 "AmSipRequest.h"
|
|
|
|
string getHeader(const string& hdrs,const string& hdr_name)
|
|
{
|
|
size_t pos1;
|
|
size_t pos2;
|
|
size_t pos_s;
|
|
if (findHeader(hdrs,hdr_name, pos1, pos2, pos_s))
|
|
return hdrs.substr(pos1,pos2-pos1);
|
|
else
|
|
return "";
|
|
}
|
|
|
|
string getHeader(const string& hdrs,const string& hdr_name,
|
|
const string& compact_hdr_name)
|
|
{
|
|
string res = getHeader(hdrs, hdr_name);
|
|
if (!res.length())
|
|
return getHeader(hdrs, compact_hdr_name);
|
|
return res;
|
|
}
|
|
|
|
bool findHeader(const string& hdrs,const string& hdr_name,
|
|
size_t& pos1, size_t& pos2, size_t& hdr_start)
|
|
{
|
|
unsigned int p;
|
|
char* hdr = strdup(hdr_name.c_str());
|
|
const char* hdrs_c = hdrs.c_str();
|
|
char* hdr_c = hdr;
|
|
const char* hdrs_end = hdrs_c + hdrs.length();
|
|
const char* hdr_end = hdr_c + hdr_name.length();
|
|
|
|
while(hdr_c != hdr_end){
|
|
if('A' <= *hdr_c && *hdr_c <= 'Z')
|
|
*hdr_c -= 'A' - 'a';
|
|
hdr_c++;
|
|
}
|
|
|
|
while(hdrs_c != hdrs_end){
|
|
|
|
hdr_c = hdr;
|
|
|
|
while((hdrs_c != hdrs_end) && (hdr_c != hdr_end)){
|
|
|
|
char c = *hdrs_c;
|
|
if('A' <= *hdrs_c && *hdrs_c <= 'Z')
|
|
c -= 'A' - 'a';
|
|
|
|
if(c != *hdr_c)
|
|
break;
|
|
|
|
hdr_c++;
|
|
hdrs_c++;
|
|
}
|
|
|
|
if(hdr_c == hdr_end)
|
|
break;
|
|
|
|
while((hdrs_c != hdrs_end) && (*hdrs_c != '\n'))
|
|
hdrs_c++;
|
|
|
|
if(hdrs_c != hdrs_end)
|
|
hdrs_c++;
|
|
}
|
|
|
|
if(hdr_c == hdr_end){
|
|
hdr_start = hdrs_c - hdrs.c_str();;
|
|
|
|
while((hdrs_c != hdrs_end) && (*hdrs_c == ' '))
|
|
hdrs_c++;
|
|
|
|
if((hdrs_c != hdrs_end) && (*hdrs_c == ':')){
|
|
|
|
hdrs_c++;
|
|
while((hdrs_c != hdrs_end) && (*hdrs_c == ' '))
|
|
hdrs_c++;
|
|
|
|
p = hdrs_c - hdrs.c_str();
|
|
|
|
string::size_type p_end;
|
|
if((p_end = hdrs.find('\n',p)) != string::npos){
|
|
|
|
free(hdr);
|
|
// return hdrs.substr(p,p_end-p);
|
|
pos1 = p;
|
|
pos2 = p_end;
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
|
|
free(hdr);
|
|
// return "";
|
|
return false;
|
|
}
|
|
|