📄 sipparser.h
字号:
#ifndef __SIPPARSER_H__#define __SIPPARSER_H__/********************************************************************* $Id: SIPParser.h,v 1.3 1999/08/31 02:22:05 cullen Exp $ ********************************************************************* This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. In addition to the terms and conditions set forth in the GNU Lesser General Public License, as a condition of using this library you are required to grant to all users of this library or any implementation utilizing or derived from this library a reciprocal, no cost, worldwide, perpetual, non-exclusive, non-transferable, unrestricted license to your claims of all patents and patent applications throughout the world that are infringed by the library or any implementation utilizing or derived from this library. In the event you redistribute this library or any implementation utilizing or derived from this library, you must prominently display the foregoing terms and conditions with the library or the implementation utilizing or derived from this library. In the event of a conflict of terms between the foregoing license grant and the terms set forth in the GNU Lesser General Public License, the foregoing terms and conditions shall be deemed to govern. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not; write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. Copyright 1999 Vovida Networks, Inc. All Rights Reserved. ********************************************************************* $Log: SIPParser.h,v $ Revision 1.3 1999/08/31 02:22:05 cullen updated header **********************************************************************/#include <string>#include <vector>#include "mstring.h"#include "MpCommon.h"#include "MpItems.h"namespace msip{ typedef MpHeader *pMpHeader; typedef std::vector<pMpHeader> HdrArray; ///SIP Messages Interpreter class MsgParser { ///Start Line MpStartLine mp_StartLine; ///Headers HdrArray mp_HdrArray; ///Line separator std::mstring mp_Separator; ///Double Line separator std::mstring mp_DblSep; ///Message content structure struct Content { MpContentType* m_type; std::mstring m_content; }; typedef vector<Content> ContentArray; ///Message content array ContentArray mp_Content; private: ///Auto-detect line separator, It may be "\n" or "\r" or "\r\n" or "\n\r"; static std::mstring detectLineSep(const std::mstring & str); ///Find a header by one of possible names static std::mstring findHeader(const std::mstring & str, const std::mstring & name, const std::mstring & separator); ///Add a header void addHeader(const pMpHeader header); ///Decode the content string void decodeContent(const std::mstring &content); ///Make the content string void encodeContent(std::mstring *content); public: ///Default Constructor MsgParser() : mp_Separator("\r\n"), mp_DblSep("\r\n\r\n") {} ///Destructor (non-virtual) ~MsgParser(); ///Check, whether the message is ready, Returns the total length of a message static std::string::size_type findMessageEnd(const std::mstring & str); ///Set Line Separator void setLineSep(const std::mstring & sep) { mp_Separator = sep; mp_DblSep = sep + sep; } ///Erase void erase(); ///Erase bool empty() const { return mp_StartLine.empty();/* || mp_HdrArray.empty();*/ } ///Parse the message MpSyntasError Exception void decode(const std::mstring & str, std::string::size_type len, bool chk_syntax_flag=true); ///Build the message MpSyntasError Exception std::mstring encode(bool chk_syntax_flag=true) /*const*/; ///Check syntax void checkSyntax(); ///Start Line access MpStartLine & startLine() { return mp_StartLine; } ///Start Line const access const MpStartLine & startLine() const { return mp_StartLine; } ///Headers Access by Name and Index MpHeader & header(const char * name, unsigned index=0); ///Headers Access by Name and index=0 MpHeader & operator [] (const char * name) { return header(name, 0); } ///Headers Access by index MpHeader & operator [] (unsigned index); ///Ins new header. Use for add a new Via-header before the first existed one MpHeader & insertHeader(const char * name, unsigned index=0); ///Returns a number of headers by name "name" unsigned count(const char * name=0) const; ///Returns a number of parts of the content unsigned countContents() const { return mp_Content.size(); } ///Get message content type MpContentType & contentType(unsigned index=0); ///Get message content type const MpContentType & contentType(unsigned index=0) const; ///Get message content const std::mstring & getContent(unsigned index=0) const; ///Set message content void setContent(const std::string & content, unsigned index=0); ///Remove content void removeContent(unsigned index=0); ///Assign all the headers and content MsgParser & operator = (const MsgParser &mp); ///Find the header by name "name" MpHeader * find(const char * name, unsigned index=0); ///Dump all the headers void dump(std::mstring * str); private: ///Use copy constructor is prohibited MsgParser(const MsgParser &); }; }#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -