#pragma module HDR_PARSE "HDR_PARSE-1-X" /* **++ ** FACILITY: yahNEWS project ** ** MODULE DESCRIPTION: ** ** This module contains a RFC 822/821 header parser, and contains a routines to ** extract a selected number of the headers fields. ** ** AUTHORS: ** ** Ruslan R. Laishev ** ** CREATION DATE: 1-APR-2001 ** ** DESIGN ISSUES: ** ** This module use an parser table declared externaly (see HDR_PARSE_TBL.MAR), to ** performs a scanning and an extraction of selected number of fields. ** An information about found fields is strored in the array, in form: pointer,length. ** ** ** MODIFICATION HISTORY: ** ** {@tbs@}... **-- */ /* ** ** INCLUDE FILES ** */ #include #include #include #include #include #include #include /* ** ** LIB$TPARSE stuff ** */ extern char ufd_state, ufd_key; /* ** An array to store of the found fields */ ile2 hdr_itmlst[4]; /* **++ ** FUNCTIONAL DESCRIPTION: ** ** An action routine called from LIB$TPARSE routine, if a field token is matched. ** Store a length and a pointer to a found field. ** ** FORMAL PARAMETERS: ** ** tparse_block: A pointer to the TPARSE block ** ** RETURN VALUE: ** ** VMS condition code ** ** SIDE EFFECTS: ** ** Modify a string pointer and length in the TPARSE block. ** ** **-- */ int hdr_parse_cpy ( struct tpadef *tparse_block ) { int len = 0; printf("\n%.*s",tparse_block->tpa$l_tokencnt,tparse_block->tpa$l_tokenptr); hdr_itmlst[tparse_block->tpa$l_param].ile2$w_length = tparse_block->tpa$l_tokencnt; hdr_itmlst[tparse_block->tpa$l_param].ile2$ps_bufaddr = tparse_block->tpa$l_tokenptr; hdr_itmlst[tparse_block->tpa$l_param].ile2$w_code = tparse_block->tpa$l_param; return SS$_NORMAL; } /* **++ ** FUNCTIONAL DESCRIPTION: ** ** A routine to perform a parsing and extraction of the selected fields from a mail RFC822/821 ** headers. ** ** FORMAL PARAMETERS: ** ** ptr: a pointer to string to be parsed ** len: a length of the string ** itmlst: a ile2 elements to store a pointers and lengths of the found fields ** ** RETURN VALUE: ** ** VMS condition code ** ** SIDE EFFECTS: ** ** This routine is not tread safe! ** **-- */ int hdr_parse ( char *ptr, int len, ile2 *itmlst[] ) { int status; struct tpadef tparse_block = {TPA$K_COUNT0, TPA$M_BLANKS}; /* ** Prepare a TPARSE block */ tparse_block.tpa$l_stringcnt = len; tparse_block.tpa$l_stringptr = ptr; /* ** Call parser */ status = lib$table_parse( &tparse_block,&ufd_state,&ufd_key); /* ** Copy a local storage, and return status */ memcpy(itmlst,hdr_itmlst,sizeof(hdr_itmlst)); return status; }