📄 rvmegacoauthparse.c
字号:
/******************************************************************************
Filename: rvmegacoauth.c
Description: megaco authentication header parser
*******************************************************************************
Copyright (c) 2000 RADVision Inc.
*******************************************************************************
NOTICE:
This document contains information that is proprietary to RADVision Inc.
No part of this publication may be reproduced in any form whatsoever without
written prior approval by RADVision Inc.
RADVision Inc. reserves the right to revise this publication and make changes
without obligation to notify any person of such revisions or changes.
******************************************************************************/
#include "rvmegacoauth.h"
#define SYNTAX_ERROR
/*
AnaGram Parsing Engine
Copyright (c) 1993-2000, Parsifal Software.
All Rights Reserved.
Serial number 2P20945U
Registered to:
James Adragna
RADVISION, INC.
*/
#ifndef RVMEGACOAUTH_H_983899186
#include "rvmegacoauthparse.h"
#endif
#ifndef RVMEGACOAUTH_H_983899186
#error Mismatched header file
#endif
#include <ctype.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define RULE_CONTEXT (&((PCB).cs[(PCB).ssx]))
#define ERROR_CONTEXT ((PCB).cs[(PCB).error_frame_ssx])
#define CONTEXT ((PCB).cs[(PCB).ssx])
#ifndef PCB_TYPE
#define PCB_TYPE megacoauth_pcb_type
#endif
#define PCB (*pcb_pointer)
#define PCB_DECL PCB_TYPE *pcb_pointer
#define PCB_POINTER pcb_pointer
/* Line 110, Z:/rv/megaco/common/parser/rvmegacoauth.syn */
/*
{function:
{name: rvMegacoAuthenticationHeaderConstructParse}
{class: RvMegacoAuthenticationHeader}
{include: rvmegacoauth.h}
{description:
{p: Constructs an authentication header object from raw message text.}
}
{proto: RvMegacoAuthenticationHeader *rvMegacoAuthenticationHeaderConstructParse(
RvMegacoAuthenticationHeader *x, const char **text, RvAlloc *alloc);}
{params:
{param: {n:x} {d:The authentication header object.}}
{param: {n:text} {d:Pointer to raw message pointer. Raw message pointer
is advanced past the authentication header on successful parse.}}
{param: {n:alloc} {d:The allocator to use.}}
}
{returns: A pointer to the constructed object, or NULL if construction failed.}
{notes:
{note: see RFC2402}
}
}
*/
RvMegacoAuthenticationHeader *rvMegacoAuthenticationHeaderConstructParse(
RvMegacoAuthenticationHeader *x, const char **text, RvAlloc *alloc)
{
megacoauth_pcb_type pcb;
pcb.pointer = *text;
pcb.authenticationHeader = x;
pcb.alloc = alloc;
rvStringConstructAndReserve(&pcb.authenticationData, 64, alloc);
megacoauth(&pcb);
rvStringDestruct(&pcb.authenticationData);
if(pcb.exit_flag == AG_SUCCESS_CODE)
{
*text = pcb.pointer - 1;
return x;
}
return NULL;
}
#ifndef CONVERT_CASE
static const char agCaseTable[31] = {
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20
};
static int agConvertCase(int c) {
if (c >= 'a' && c <= 'z') return c ^= 0x20;
if (c >= 0xe0 && c < 0xff) c ^= agCaseTable[c-0xe0];
return c;
}
#define CONVERT_CASE(c) agConvertCase(c)
#endif
#ifndef TAB_SPACING
#define TAB_SPACING 8
#endif
static void ag_rp_1(PCB_DECL, unsigned int idx, unsigned int n) {
/* Line 43, Z:/rv/megaco/common/parser/rvmegacoauth.syn */
rvMegacoAuthenticationHeaderConstructString(PCB.authenticationHeader, idx, n, &PCB.authenticationData, PCB.alloc);
}
#define ag_rp_2(PCB_POINTER, x) (x)
#define ag_rp_3(PCB_POINTER, x) (x)
static unsigned int ag_rp_4(PCB_DECL, unsigned int d7, unsigned int d6, unsigned int d5, unsigned int d4, unsigned int d3, unsigned int d2, unsigned int d1, unsigned int d0) {
/* Line 63, Z:/rv/megaco/common/parser/rvmegacoauth.syn */
return d7 << 28 | d6 << 24 | d5 << 20 | d4 << 16 | d3 << 12 | d2 << 8 | d1 << 4 | d0;
}
#define ag_rp_5(PCB_POINTER, d) (d - '0')
#define ag_rp_6(PCB_POINTER, d) (9 + (d & 15))
#define ag_rp_7(PCB_POINTER, c) (rvStringPushBack(&PCB.authenticationData, (char)c))
#define ag_rp_8(PCB_POINTER, c) (rvStringPushBack(&PCB.authenticationData, (char)c))
#define READ_COUNTS
#define WRITE_COUNTS
#undef V
#define V(i,t) (*(t *) (&(PCB).vs[(PCB).ssx + i]))
#undef VS
#define VS(i) (PCB).vs[(PCB).ssx + i]
#ifndef GET_CONTEXT
#define GET_CONTEXT CONTEXT = (PCB).input_context
#endif
typedef enum {
ag_action_1,
ag_action_2,
ag_action_3,
ag_action_4,
ag_action_5,
ag_action_6,
ag_action_7,
ag_action_8,
ag_action_9,
ag_action_10,
ag_action_11,
ag_action_12
} ag_parser_action;
#ifndef NULL_VALUE_INITIALIZER
#define NULL_VALUE_INITIALIZER = { 0 }
#endif
static megacoauth_vs_type const ag_null_value NULL_VALUE_INITIALIZER;
static const unsigned char ag_rpx[] = {
0, 1, 0, 0, 0, 2, 3, 4, 5, 6, 7, 8
};
static const unsigned char ag_key_itt[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1,
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0
};
static const unsigned short ag_key_pt[] = {
0, 11, 0, 12,0
};
static const unsigned char ag_key_ch[] = {
0, 84,255, 85,255, 65,255
};
static const unsigned char ag_key_act[] = {
0,7,4,6,4,2,4
};
static const unsigned char ag_key_parm[] = {
0, 0, 0, 2, 0, 0, 0
};
static const unsigned char ag_key_jmp[] = {
0, 0, 0, 1, 0, 3, 0
};
static const unsigned char ag_key_index[] = {
5, 0, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
static const unsigned char ag_key_ends[] = {
72,69,78,84,73,67,65,84,73,79,78,0,
};
#define AG_TCV(x) (((int)(x) >= 0 && (int)(x) <= 255) ? ag_tcv[(x)] : 0)
static const unsigned char ag_tcv[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 28, 33, 0, 0, 33, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 28, 35, 29, 37,
35, 35, 35, 35, 35, 35, 35, 35, 37, 35, 35, 35, 15, 36, 36, 36, 36, 36,
36, 36, 36, 36, 6, 26, 37, 34, 37, 35, 35, 19, 19, 19, 19, 19, 19, 35,
35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 16, 35,
35, 37, 35, 37, 35, 35, 35, 19, 19, 19, 19, 19, 19, 35, 35, 35, 35, 35,
35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 16, 35, 35, 37, 35, 37,
35, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0
};
#ifndef SYNTAX_ERROR
#define SYNTAX_ERROR fprintf(stderr,"%s, line %d, column %d\n", \
(PCB).error_message, (PCB).line, (PCB).column)
#endif
#ifndef FIRST_LINE
#define FIRST_LINE 1
#endif
#ifndef FIRST_COLUMN
#define FIRST_COLUMN 1
#endif
#ifndef PARSER_STACK_OVERFLOW
#define PARSER_STACK_OVERFLOW {fprintf(stderr, \
"\nParser stack overflow, line %d, column %d\n",\
(PCB).line, (PCB).column);}
#endif
#ifndef REDUCTION_TOKEN_ERROR
#define REDUCTION_TOKEN_ERROR {fprintf(stderr, \
"\nReduction token error, line %d, column %d\n", \
(PCB).line, (PCB).column);}
#endif
#ifndef INPUT_CODE
#define INPUT_CODE(T) (T)
#endif
typedef enum
{ag_accept_key, ag_set_key, ag_jmp_key, ag_end_key, ag_no_match_key,
ag_cf_accept_key, ag_cf_set_key, ag_cf_end_key} key_words;
static void ag_get_key_word(PCB_DECL, int ag_k) {
int ag_save = (int) ((PCB).la_ptr - (PCB).pointer);
const unsigned char *ag_p;
int ag_ch;
while (1) {
switch (ag_key_act[ag_k]) {
case ag_cf_end_key: {
const unsigned char *sp = ag_key_ends + ag_key_jmp[ag_k];
do {
if ((ag_ch = *sp++) == 0) {
int ag_k1 = ag_key_parm[ag_k];
int ag_k2 = ag_key_pt[ag_k1];
if (ag_key_itt[ag_k2 + CONVERT_CASE(*(PCB).la_ptr)]) goto ag_fail;
(PCB).token_number = (megacoauth_token_type) ag_key_pt[ag_k1 + 1];
return;
}
} while (CONVERT_CASE(*(PCB).la_ptr++) == ag_ch);
goto ag_fail;
}
case ag_end_key: {
const unsigned char *sp = ag_key_ends + ag_key_jmp[ag_k];
do {
if ((ag_ch = *sp++) == 0) {
(PCB).token_number = (megacoauth_token_type) ag_key_parm[ag_k];
return;
}
} while (CONVERT_CASE(*(PCB).la_ptr++) == ag_ch);
}
case ag_no_match_key:
ag_fail:
(PCB).la_ptr = (PCB).pointer + ag_save;
return;
case ag_cf_set_key: {
int ag_k1 = ag_key_parm[ag_k];
int ag_k2 = ag_key_pt[ag_k1];
ag_k = ag_key_jmp[ag_k];
if (ag_key_itt[ag_k2 + CONVERT_CASE(*(PCB).la_ptr)]) break;
ag_save = (int) ((PCB).la_ptr - (PCB).pointer);
(PCB).token_number = (megacoauth_token_type) ag_key_pt[ag_k1+1];
break;
}
case ag_set_key:
ag_save = (int) ((PCB).la_ptr - (PCB).pointer);
(PCB).token_number = (megacoauth_token_type) ag_key_parm[ag_k];
case ag_jmp_key:
ag_k = ag_key_jmp[ag_k];
break;
case ag_accept_key:
(PCB).token_number = (megacoauth_token_type) ag_key_parm[ag_k];
return;
case ag_cf_accept_key: {
int ag_k1 = ag_key_parm[ag_k];
int ag_k2 = ag_key_pt[ag_k1];
if (ag_key_itt[ag_k2 + CONVERT_CASE(*(PCB).la_ptr)])
(PCB).la_ptr = (PCB).pointer + ag_save;
else (PCB).token_number = (megacoauth_token_type) ag_key_pt[ag_k1+1];
return;
}
}
ag_ch = CONVERT_CASE(*(PCB).la_ptr++);
ag_p = &ag_key_ch[ag_k];
while (*ag_p < ag_ch) ag_p++;
if (*ag_p != ag_ch) {
(PCB).la_ptr = (PCB).pointer + ag_save;
return;
}
ag_k = (int) (ag_p - ag_key_ch);
}
}
#ifndef AG_NEWLINE
#define AG_NEWLINE 10
#endif
#ifndef AG_RETURN
#define AG_RETURN 13
#endif
#ifndef AG_FORMFEED
#define AG_FORMFEED 12
#endif
#ifndef AG_TABCHAR
#define AG_TABCHAR 9
#endif
static void ag_track(PCB_DECL) {
int ag_k = (int) ((PCB).la_ptr - (PCB).pointer);
while (ag_k--) {
switch (*(PCB).pointer++) {
case AG_NEWLINE:
(PCB).column = 1, (PCB).line++;
case AG_RETURN:
case AG_FORMFEED:
break;
case AG_TABCHAR:
(PCB).column += (TAB_SPACING) - ((PCB).column - 1) % (TAB_SPACING);
break;
default:
(PCB).column++;
}
}
}
static void ag_prot(PCB_DECL) {
int ag_k;
ag_k = 128 - ++(PCB).btsx;
if (ag_k <= (PCB).ssx) {
(PCB).exit_flag = AG_STACK_ERROR_CODE;
PARSER_STACK_OVERFLOW;
return;
}
(PCB).bts[(PCB).btsx] = (PCB).sn;
(PCB).bts[ag_k] = (PCB).ssx;
(PCB).vs[ag_k] = (PCB).vs[(PCB).ssx];
(PCB).ss[ag_k] = (PCB).ss[(PCB).ssx];
}
static void ag_undo(PCB_DECL) {
if ((PCB).drt == -1) return;
while ((PCB).btsx) {
int ag_k = 128 - (PCB).btsx;
(PCB).sn = (PCB).bts[(PCB).btsx--];
(PCB).ssx = (PCB).bts[ag_k];
(PCB).vs[(PCB).ssx] = (PCB).vs[ag_k];
(PCB).ss[(PCB).ssx] = (PCB).ss[ag_k];
}
(PCB).token_number = (megacoauth_token_type) (PCB).drt;
(PCB).ssx = (PCB).dssx;
(PCB).sn = (PCB).dsn;
(PCB).drt = -1;
}
static const unsigned char ag_tstt[] = {
33,28,26,12,11,0,1,2,22,23,24,25,
37,36,35,34,33,29,28,26,19,16,15,6,0,30,31,32,
33,28,26,0,22,23,
12,11,0,3,13,
37,36,35,34,29,28,26,19,16,15,6,0,30,
33,0,
34,33,28,26,0,2,4,22,23,24,25,
34,0,
15,0,5,14,
33,28,26,15,0,2,22,23,24,25,
16,0,
6,0,
36,19,15,0,17,
15,0,7,14,
36,19,15,0,17,
6,0,
36,19,15,0,17,
15,0,8,
36,19,15,0,17,
16,0,
36,33,28,26,19,15,0,9,22,23,24,
36,19,15,0,17,
36,19,15,0,
33,28,26,0,22,23,
36,35,19,16,15,0,
36,19,15,0,17,
36,19,15,0,17,
36,19,15,0,17,
};
static unsigned const char ag_astt[163] = {
1,1,1,5,5,7,0,1,1,1,1,1,1,1,1,1,8,1,1,1,1,1,1,1,7,1,1,1,9,9,1,5,3,3,1,1,7,
1,1,9,9,9,9,9,9,9,9,9,9,9,5,3,3,7,5,1,1,1,7,1,1,1,1,1,1,1,7,1,7,1,2,1,1,1,
5,7,3,1,1,1,3,1,7,1,7,2,2,2,7,1,1,7,1,2,2,2,2,7,1,1,7,2,2,2,7,1,1,7,1,2,2,
2,7,1,1,7,10,1,1,1,10,10,7,1,1,1,1,2,2,2,7,1,2,2,2,7,9,9,1,5,3,3,2,2,2,2,2,
7,2,2,2,7,1,2,2,2,7,1,2,2,2,7,2
};
static const unsigned char ag_pstt[] = {
2,2,1,17,17,0,0,3,2,2,2,3,
4,4,4,4,5,4,4,4,4,4,4,4,1,4,4,5,
15,15,1,18,15,15,
6,6,3,6,6,
25,25,25,25,25,25,25,25,25,25,25,27,25,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -