%{ #include #include "Util.h" #include "Attribute.h" #include "TV.h" #define YYSTYPE char* #define YYPARSE_PARAM avmap extern int yylex (); int yyerror (char* error); const int N = 10; const char* attributes[] = { "username", "qop", "realm", "algorithm", "nc", "nonce", "opaque", "uri", "cnonce", "response" }; AttributeSet attributeSet (attributes, attributes+N); const char* id; char *hstring, *qstring; %} %token COMMA %token EQUAL %token DIGEST %token ID %token QSTRING %token HSTRING %% MESSAGE: DIGEST AVLIST { } | { }; AVLIST: AVLIST COMMA AVPAIR { } | AVPAIR { }; AVPAIR: I EQUAL H { /* cout << " id = " << id << endl; cout << " hstring = " << hstring << endl; */ (*((NameTVMap*)avmap))[id] = new TV (TV::HSTR, hstring); } | I EQUAL Q { /* cout << " id = " << id << endl; cout << " qstring = " << qstring << endl; */ (*((NameTVMap*)avmap))[id] = new TV (TV::QSTR, qstring); } ; /* pankaj - verify whether this is required!! */ H: HSTRING { // copy the entire string cout << "parser => hstring=" << $1 << endl; cout << "parser => strlen(hstring)=" << strlen($1) << endl; hstring=new char[strlen($1)+1]; strncpy(hstring,$1,strlen($1)); cout << "parser => hstring=" << hstring << endl; cout << "parser => strlen(hstring)=" << strlen(hstring) << endl; }; /* pankaj - verify whether this is required!! */ Q: QSTRING { // remove the quotes and copy the rest of the string cout << "parser => qstring=" << $1 << endl; cout << "parser => strlen(qstring)=" << strlen($1) << endl; qstring=new char[strlen($1)-1]; strncpy(qstring,$1+1,strlen($1)-2); cout << "parser => qstring=" << qstring << endl; cout << "parser => strlen(qstring)=" << strlen(qstring) << endl; } | { }; I: ID { /* pankaj - convert to lower before lookup */ id = *(attributeSet.find($1)); }; %% int yyerror (char* error) { PRINT ("error in parsing :-("); return -1; } /* int main (void) { yyparse(); } */