⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 parser.h

📁 mgcp协议源代码和测试程序,还有一个编译器
💻 H
字号:
/******************************************************************************
  Copyright(C) 2005,2006 Frank ZHANG

  All Rights Reserved.
    
  This program 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.

  This program 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.
 
 ******************************************************************************
*      Authors                   :  Frank ZHANG (openmgcp@gmail.com)
*      Description               :  
*
*
*      Date of creation          :  04/10/2005
*
*
*      History                   :
*      2005/04/10 Frank ZHANG    : - Creation
******************************************************************************/
#ifndef __PARSER_H__
#define __PARSER_H__

#include "list.h"

#ifdef __cplusplus
extern "C" {#endif
/*Context push and pop macro*/
#define CtxSave(savectx, curctx) \
  TCtx ctx##savectx; \
  ctx##savectx.pCur = curctx->pCur 

#define CtxRestore(ctx, savedctx) \
  (ctx->pCur = ctx##savedctx.pCur)

/**************************************************************
 * Ctx is very important when decode/encode abnf messages, it is
 * used to store the pointers of message content and allocated 
 * memories when decode
 *   _______________________________
 *  |_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|
 *  ^                ^              ^
 *  |                |              | 
 * pHead            pCur          pTail
 ***************************************************************/
 typedef struct Ctx_tag {
  char *pHead;              /* Data header to be decoded or buffer 
                             * header to be encoded */
                                  
  char *pTail;              /* Data tail to be decoded or buffer tail
                               to be encoded */
                                    
  char *pCur;               /* Current data pointer to be decoded or
                               curren position of buffer when encoded */

  TSList MemList;           /* Single list to store the allocated memory
                               pointer when decode abnf message */
}TCtx;

/*Decode/Encode function pointer for Token Rule*/
typedef int (*DecodeFunc)(TCtx *ctx);
typedef int (*EncodeFunc)(TCtx *ctx);


/* Damamic array, RuleList type */
typedef struct List_tag {
  int iNum;
  void *pNode;
} TList;

/* Option repetiton structure */
typedef struct Opt_tag {
  int flag;
  void *pRuleData;
} TOpt;


void CtxInitial(TCtx *ctx, char *pData, int iLen);
void CtxFree(TCtx *ctx);
void* AbnfAlloc(TCtx *ctx, size_t size);
void* AbnfReAlloc(TCtx *ctx, void *pData, size_t size);
void AbnfDetachMem(TCtx *ctx, void *pData);
char* AbnfStrnClone(TCtx *ctx, char *Head, char *Tail);
void* ListNewNode(TCtx *ctx, TList *list, size_t size);
void ListRemoveLast(TList *list);
int ParseString(TCtx *ctx, int iRepmin, int iRepmax, char *string);
int ParseChar(TCtx *ctx, int iRepmin, int iRepmax, unsigned char ValBegin, unsigned char ValEnd);
int ParseToken(TCtx *ctx, int iRepmin, int iRepmax, DecodeFunc decfunc);
int ParseStrRule(TCtx *ctx, char **ppdata, int iRepmin, int iRepmax, DecodeFunc decfunc);
int EncodeString(TCtx *ctx, int iRep, char *string);
int EncodeChar(TCtx *ctx, int iRep, unsigned char ucValue);
int EncodeToken(TCtx *ctx, int iRep, EncodeFunc encfunc);


#ifdef __cplusplus}#endif

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -