Jan Janak пре 23 година
родитељ
комит
b9242cb1fc

+ 0 - 161
parser/digest/digest_keys.h

@@ -31,176 +31,15 @@
 #ifndef DIGEST_KEYS_H
 #define DIGEST_KEYS_H
 
-
 #define _user_ 0x72657375   /* "user" */
-#define _useR_ 0x52657375   /* "useR" */
-#define _usEr_ 0x72457375   /* "usEr" */
-#define _usER_ 0x52457375   /* "usER" */
-#define _uSer_ 0x72655375   /* "uSer" */
-#define _uSeR_ 0x52655375   /* "uSeR" */
-#define _uSEr_ 0x72455375   /* "uSEr" */
-#define _uSER_ 0x52455375   /* "uSER" */
-#define _User_ 0x72657355   /* "User" */
-#define _UseR_ 0x52657355   /* "UseR" */
-#define _UsEr_ 0x72457355   /* "UsEr" */
-#define _UsER_ 0x52457355   /* "UsER" */
-#define _USer_ 0x72655355   /* "USer" */
-#define _USeR_ 0x52655355   /* "USeR" */
-#define _USEr_ 0x72455355   /* "USEr" */
-#define _USER_ 0x52455355   /* "USER" */
-
 #define _name_ 0x656d616e   /* "name" */
-#define _namE_ 0x456d616e   /* "namE" */
-#define _naMe_ 0x654d616e   /* "naMe" */
-#define _naME_ 0x454d616e   /* "naME" */
-#define _nAme_ 0x656d416e   /* "nAme" */
-#define _nAmE_ 0x456d416e   /* "nAmE" */
-#define _nAMe_ 0x654d416e   /* "nAMe" */
-#define _nAME_ 0x454d416e   /* "nAME" */
-#define _Name_ 0x656d614e   /* "Name" */
-#define _NamE_ 0x456d614e   /* "NamE" */
-#define _NaMe_ 0x654d614e   /* "NaMe" */
-#define _NaME_ 0x454d614e   /* "NaME" */
-#define _NAme_ 0x656d414e   /* "NAme" */
-#define _NAmE_ 0x456d414e   /* "NAmE" */
-#define _NAMe_ 0x654d414e   /* "NAMe" */
-#define _NAME_ 0x454d414e   /* "NAME" */
-
 #define _real_ 0x6c616572   /* "real" */
-#define _reaL_ 0x4c616572   /* "reaL" */
-#define _reAl_ 0x6c416572   /* "reAl" */
-#define _reAL_ 0x4c416572   /* "reAL" */
-#define _rEal_ 0x6c614572   /* "rEal" */
-#define _rEaL_ 0x4c614572   /* "rEaL" */
-#define _rEAl_ 0x6c414572   /* "rEAl" */
-#define _rEAL_ 0x4c414572   /* "rEAL" */
-#define _Real_ 0x6c616552   /* "Real" */
-#define _ReaL_ 0x4c616552   /* "ReaL" */
-#define _ReAl_ 0x6c416552   /* "ReAl" */
-#define _ReAL_ 0x4c416552   /* "ReAL" */
-#define _REal_ 0x6c614552   /* "REal" */
-#define _REaL_ 0x4c614552   /* "REaL" */
-#define _REAl_ 0x6c414552   /* "REAl" */
-#define _REAL_ 0x4c414552   /* "REAL" */
-
 #define _nonc_ 0x636e6f6e   /* "nonc" */
-#define _nonC_ 0x436e6f6e   /* "nonC" */
-#define _noNc_ 0x634e6f6e   /* "noNc" */
-#define _noNC_ 0x434e6f6e   /* "noNC" */
-#define _nOnc_ 0x636e4f6e   /* "nOnc" */
-#define _nOnC_ 0x436e4f6e   /* "nOnC" */
-#define _nONc_ 0x634e4f6e   /* "nONc" */
-#define _nONC_ 0x434e4f6e   /* "nONC" */
-#define _Nonc_ 0x636e6f4e   /* "Nonc" */
-#define _NonC_ 0x436e6f4e   /* "NonC" */
-#define _NoNc_ 0x634e6f4e   /* "NoNc" */
-#define _NoNC_ 0x434e6f4e   /* "NoNC" */
-#define _NOnc_ 0x636e4f4e   /* "NOnc" */
-#define _NOnC_ 0x436e4f4e   /* "NOnC" */
-#define _NONc_ 0x634e4f4e   /* "NONc" */
-#define _NONC_ 0x434e4f4e   /* "NONC" */
-
 #define _resp_ 0x70736572   /* "resp" */
-#define _resP_ 0x50736572   /* "resP" */
-#define _reSp_ 0x70536572   /* "reSp" */
-#define _reSP_ 0x50536572   /* "reSP" */
-#define _rEsp_ 0x70734572   /* "rEsp" */
-#define _rEsP_ 0x50734572   /* "rEsP" */
-#define _rESp_ 0x70534572   /* "rESp" */
-#define _rESP_ 0x50534572   /* "rESP" */
-#define _Resp_ 0x70736552   /* "Resp" */
-#define _ResP_ 0x50736552   /* "ResP" */
-#define _ReSp_ 0x70536552   /* "ReSp" */
-#define _ReSP_ 0x50536552   /* "ReSP" */
-#define _REsp_ 0x70734552   /* "REsp" */
-#define _REsP_ 0x50734552   /* "REsP" */
-#define _RESp_ 0x70534552   /* "RESp" */
-#define _RESP_ 0x50534552   /* "RESP" */
-
 #define _onse_ 0x65736e6f   /* "onse" */
-#define _onsE_ 0x45736e6f   /* "onsE" */
-#define _onSe_ 0x65536e6f   /* "onSe" */
-#define _onSE_ 0x45536e6f   /* "onSE" */
-#define _oNse_ 0x65734e6f   /* "oNse" */
-#define _oNsE_ 0x45734e6f   /* "oNsE" */
-#define _oNSe_ 0x65534e6f   /* "oNSe" */
-#define _oNSE_ 0x45534e6f   /* "oNSE" */
-#define _Onse_ 0x65736e4f   /* "Onse" */
-#define _OnsE_ 0x45736e4f   /* "OnsE" */
-#define _OnSe_ 0x65536e4f   /* "OnSe" */
-#define _OnSE_ 0x45536e4f   /* "OnSE" */
-#define _ONse_ 0x65734e4f   /* "ONse" */
-#define _ONsE_ 0x45734e4f   /* "ONsE" */
-#define _ONSe_ 0x65534e4f   /* "ONSe" */
-#define _ONSE_ 0x45534e4f   /* "ONSE" */
-
 #define _cnon_ 0x6e6f6e63   /* "cnon" */
-#define _cnoN_ 0x4e6f6e63   /* "cnoN" */
-#define _cnOn_ 0x6e4f6e63   /* "cnOn" */
-#define _cnON_ 0x4e4f6e63   /* "cnON" */
-#define _cNon_ 0x6e6f4e63   /* "cNon" */
-#define _cNoN_ 0x4e6f4e63   /* "cNoN" */
-#define _cNOn_ 0x6e4f4e63   /* "cNOn" */
-#define _cNON_ 0x4e4f4e63   /* "cNON" */
-#define _Cnon_ 0x6e6f6e43   /* "Cnon" */
-#define _CnoN_ 0x4e6f6e43   /* "CnoN" */
-#define _CnOn_ 0x6e4f6e43   /* "CnOn" */
-#define _CnON_ 0x4e4f6e43   /* "CnON" */
-#define _CNon_ 0x6e6f4e43   /* "CNon" */
-#define _CNoN_ 0x4e6f4e43   /* "CNoN" */
-#define _CNOn_ 0x6e4f4e43   /* "CNOn" */
-#define _CNON_ 0x4e4f4e43   /* "CNON" */
-
 #define _opaq_ 0x7161706f   /* "opaq" */
-#define _opaQ_ 0x5161706f   /* "opaQ" */
-#define _opAq_ 0x7141706f   /* "opAq" */
-#define _opAQ_ 0x5141706f   /* "opAQ" */
-#define _oPaq_ 0x7161506f   /* "oPaq" */
-#define _oPaQ_ 0x5161506f   /* "oPaQ" */
-#define _oPAq_ 0x7141506f   /* "oPAq" */
-#define _oPAQ_ 0x5141506f   /* "oPAQ" */
-#define _Opaq_ 0x7161704f   /* "Opaq" */
-#define _OpaQ_ 0x5161704f   /* "OpaQ" */
-#define _OpAq_ 0x7141704f   /* "OpAq" */
-#define _OpAQ_ 0x5141704f   /* "OpAQ" */
-#define _OPaq_ 0x7161504f   /* "OPaq" */
-#define _OPaQ_ 0x5161504f   /* "OPaQ" */
-#define _OPAq_ 0x7141504f   /* "OPAq" */
-#define _OPAQ_ 0x5141504f   /* "OPAQ" */
-
 #define _algo_ 0x6f676c61   /* "algo" */
-#define _algO_ 0x4f676c61   /* "algO" */
-#define _alGo_ 0x6f476c61   /* "alGo" */
-#define _alGO_ 0x4f476c61   /* "alGO" */
-#define _aLgo_ 0x6f674c61   /* "aLgo" */
-#define _aLgO_ 0x4f674c61   /* "aLgO" */
-#define _aLGo_ 0x6f474c61   /* "aLGo" */
-#define _aLGO_ 0x4f474c61   /* "aLGO" */
-#define _Algo_ 0x6f676c41   /* "Algo" */
-#define _AlgO_ 0x4f676c41   /* "AlgO" */
-#define _AlGo_ 0x6f476c41   /* "AlGo" */
-#define _AlGO_ 0x4f476c41   /* "AlGO" */
-#define _ALgo_ 0x6f674c41   /* "ALgo" */
-#define _ALgO_ 0x4f674c41   /* "ALgO" */
-#define _ALGo_ 0x6f474c41   /* "ALGo" */
-#define _ALGO_ 0x4f474c41   /* "ALGO" */
-
 #define _rith_ 0x68746972   /* "rith" */
-#define _ritH_ 0x48746972   /* "ritH" */
-#define _riTh_ 0x68546972   /* "riTh" */
-#define _riTH_ 0x48546972   /* "riTH" */
-#define _rIth_ 0x68744972   /* "rIth" */
-#define _rItH_ 0x48744972   /* "rItH" */
-#define _rITh_ 0x68544972   /* "rITh" */
-#define _rITH_ 0x48544972   /* "rITH" */
-#define _Rith_ 0x68746952   /* "Rith" */
-#define _RitH_ 0x48746952   /* "RitH" */
-#define _RiTh_ 0x68546952   /* "RiTh" */
-#define _RiTH_ 0x48546952   /* "RiTH" */
-#define _RIth_ 0x68744952   /* "RIth" */
-#define _RItH_ 0x48744952   /* "RItH" */
-#define _RITh_ 0x68544952   /* "RITh" */
-#define _RITH_ 0x48544952   /* "RITH" */
-
 
 #endif /* DIGEST_KEYS_H */

+ 0 - 9
parser/digest/digest_parser.c

@@ -362,12 +362,3 @@ void init_dig_cred(dig_cred_t* _c)
 	memset(_c, 0, sizeof(dig_cred_t));
 }
 
-
-/*
- * Initialize digest_parser
- */
- 
-void init_digest_parser(void)
-{
-        init_digest_htable();
-}

+ 0 - 6
parser/digest/digest_parser.h

@@ -85,12 +85,6 @@ typedef struct dig_cred {
 } dig_cred_t;
 
 
-/*
- * Initialize digest parser
- */
-void init_digest_parser(void);
-
-
 /*
  * Initialize a digest credentials structure
  */

+ 27 - 179
parser/digest/param_parser.c

@@ -27,94 +27,22 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-
-
 #include "param_parser.h"
 #include "digest_keys.h"
 #include "../../trim.h"
 #include "../../ut.h"
 
-/*
- * Precalculated hash table size
- * WARNING: The size MUST be recalculated
- *          again if new parameter names
- *          should be parsed
- */
-#define HASH_TABLE_SIZE 859
-
-
-/*
- * Hash function
- */
-#define HASH_FUNC(val) ((val) % HASH_TABLE_SIZE)
-
-
-/*
- * This constant marks an empty hash table element
- */
-#define HASH_EMPTY 0x2d2d2d2d
-
-
-/*
- * Hash table entry
- */
-struct ht_entry {
-	unsigned int key;
-	unsigned int value;
-};
-
-
-static struct ht_entry hash_table[HASH_TABLE_SIZE];
-
-
-/*
- * Pointer to the hash table
- */
-/*
-static struct ht_entry *hash_table;
-*/
-
-
-/*
- * Declarations
- */
-static void set_entry (unsigned int key, unsigned int val);
-static inline int unify (int key);
-
-
-
-/*
- * Used to initialize hash table
- */
-static void set_entry(unsigned int key, unsigned int val)
-{
-	hash_table[HASH_FUNC(key)].key = key;
-	hash_table[HASH_FUNC(key)].value = val;
-}
-
-
-static inline int unify(int key)
-{
-	register struct ht_entry* en;
-
-	en = &hash_table[HASH_FUNC(key)];
-	if (en->key == key) {
-		return en->value;
-	} else {
-		return key;
-	}
-}
-
+#define LOWER_BYTE(b) ((b) | 0x20)
+#define LOWER_DWORD(d) ((d) | 0x20202020)
 
 /*
  * Parse short (less than 4 bytes) parameter names
  */
 #define PARSE_SHORT                                                   \
-	switch(*p) {                                                  \
+	switch(LOWER_BYTE(*p)) {                                      \
 	case 'u':                                                     \
-	case 'U':                                                     \
-		if ((*(p + 1) == 'r') || (*(p + 1) == 'R')) {         \
-			if ((*(p + 2) == 'i') || (*(p + 2) == 'I')) { \
+		if (LOWER_BYTE(*(p + 1)) == 'r') {                    \
+			if (LOWER_BYTE(*(p + 2)) == 'i') {            \
 				*_type = PAR_URI;                     \
                                 p += 3;                               \
 				goto end;                             \
@@ -123,9 +51,8 @@ static inline int unify(int key)
 		break;                                                \
                                                                       \
 	case 'q':                                                     \
-	case 'Q':                                                     \
-		if ((*(p + 1) == 'o') || (*(p + 1) == 'O')) {         \
-			if ((*(p + 2) == 'p') || (*(p + 2) == 'P')) { \
+		if (LOWER_BYTE(*(p + 1)) == 'o') {                    \
+			if (LOWER_BYTE(*(p + 2)) == 'p') {            \
 				*_type = PAR_QOP;                     \
                                 p += 3;                               \
 				goto end;                             \
@@ -134,8 +61,7 @@ static inline int unify(int key)
 		break;                                                \
                                                                       \
 	case 'n':                                                     \
-	case 'N':                                                     \
-		if ((*(p + 1) == 'c') || (*(p + 1) == 'C')) {         \
+		if (LOWER_BYTE(*(p + 1)) == 'c') {                    \
 			*_type = PAR_NC;                              \
                         p += 2;                                       \
 			goto end;                                     \
@@ -155,7 +81,7 @@ static inline int unify(int key)
 
 
 #define name_CASE                      \
-        switch(val) {                  \
+        switch(LOWER_DWORD(val)) {     \
         case _name_:                   \
 		*_type = PAR_USERNAME; \
                 p += 4;                \
@@ -166,16 +92,13 @@ static inline int unify(int key)
 #define user_CASE         \
         p += 4;           \
         val = READ(p);    \
-        name_CASE;        \
-                          \
-        val = unify(val); \
         name_CASE;        \
         goto other;
 
 
 #define real_CASE                         \
         p += 4;                           \
-        if ((*p == 'm') || (*p == 'M')) { \
+        if (LOWER_BYTE(*p) == 'm') {      \
 		*_type = PAR_REALM;       \
                 p++;                      \
 		goto end;                 \
@@ -184,7 +107,7 @@ static inline int unify(int key)
 
 #define nonc_CASE                         \
         p += 4;                           \
-        if ((*p == 'e') || (*p == 'E')) { \
+        if (LOWER_BYTE(*p) == 'e') {      \
 	        *_type = PAR_NONCE;       \
                 p++;                      \
 		goto end;                 \
@@ -192,7 +115,7 @@ static inline int unify(int key)
 
 
 #define onse_CASE                      \
-        switch(val) {                  \
+        switch(LOWER_DWORD(val)) {     \
         case _onse_:                   \
 		*_type = PAR_RESPONSE; \
                 p += 4;                \
@@ -203,18 +126,15 @@ static inline int unify(int key)
 #define resp_CASE         \
         p += 4;           \
         val = READ(p);    \
-        onse_CASE;        \
-                          \
-        val = unify(val); \
         onse_CASE;        \
         goto other;
 
 
 #define cnon_CASE                                 \
         p += 4;                                   \
-        if ((*p == 'c') || (*p == 'C')) {         \
+        if (LOWER_BYTE(*p) == 'c') {              \
 		p++;                              \
-		if ((*p == 'e') || (*p == 'E')) { \
+		if (LOWER_BYTE(*p) == 'e') {      \
 			*_type = PAR_CNONCE;      \
                         p++;                      \
 			goto end;                 \
@@ -225,9 +145,9 @@ static inline int unify(int key)
 
 #define opaq_CASE                                 \
         p += 4;                                   \
-        if ((*p == 'u') || (*p == 'U')) {         \
+        if (LOWER_BYTE(*p) == 'u') {              \
 		p++;                              \
-		if ((*p == 'e') || (*p == 'E')) { \
+		if (LOWER_BYTE(*p) == 'e') {      \
 			*_type = PAR_OPAQUE;      \
                         p++;                      \
 			goto end;                 \
@@ -237,10 +157,10 @@ static inline int unify(int key)
 
 
 #define rith_CASE                                 \
-        switch(val) {                             \
+        switch(LOWER_DWORD(val)) {                \
 	case _rith_:                              \
 		p += 4;                           \
-		if ((*p == 'm') || (*p == 'M')) { \
+		if (LOWER_BYTE(*p) == 'm') {      \
 			*_type = PAR_ALGORITHM;   \
                         p++;                      \
 			goto end;                 \
@@ -253,10 +173,7 @@ static inline int unify(int key)
         p += 4;           \
         val = READ(p);    \
         rith_CASE;        \
-                          \
-        val = unify(val); \
-        rith_CASE;        \
-        goto other;
+        goto other
 
 
 #define FIRST_QUATERNIONS       \
@@ -273,29 +190,24 @@ static inline int unify(int key)
 
 int parse_param_name(str* _s, dig_par_t* _type)
 {
-	register char* p;
-	register int val;
+        register char* p;
+        register int val;
 	char* end;
-
+	
 	end = _s->s + _s->len;
-
+	
 	p = _s->s;
 	val = READ(p);
-
+	
 	if (_s->len < 4) {
 		goto other;
 	}
-
-	switch(val) {
+	
+        switch(LOWER_DWORD(val)) {
 	FIRST_QUATERNIONS;
 	default:
 		PARSE_SHORT;
-
-		val = unify(val);
-		switch(val) {
-		FIRST_QUATERNIONS;
-		default: goto other;
-		}
+		goto other;
         }
 
  end:
@@ -319,67 +231,3 @@ int parse_param_name(str* _s, dig_par_t* _type)
 	}
 }
 
-
-/* Number of distinct keys */
-#define NUM_KEYS  160
-
-/* Number of distinct values */
-#define NUM_VALS 10
-
-
-/*
- * Create synonym-less (precalculated) hash table
- */
-void init_digest_htable(void)
-{
-	int i, j, k;
-
-	unsigned int init_val[NUM_VALS] = {
-		_user_, _name_, _real_, _nonc_,
-		_resp_, _onse_, _cnon_, _opaq_,
-		_algo_, _rith_
-	};
-
-	unsigned int key_nums[NUM_VALS] = {
-		16, 16, 16, 16, 16,
-		16, 16, 16, 16, 16
-	};
-	
-	unsigned int init_key[NUM_KEYS] = {
-		_user_, _useR_, _usEr_, _usER_, _uSer_, _uSeR_, _uSEr_, _uSER_, 
-		_User_, _UseR_, _UsEr_, _UsER_, _USer_, _USeR_, _USEr_, _USER_, 
-		_name_, _namE_, _naMe_, _naME_, _nAme_, _nAmE_, _nAMe_, _nAME_, 
-		_Name_, _NamE_, _NaMe_, _NaME_, _NAme_, _NAmE_, _NAMe_, _NAME_, 
-		_real_, _reaL_, _reAl_, _reAL_, _rEal_, _rEaL_, _rEAl_, _rEAL_, 
-		_Real_, _ReaL_, _ReAl_, _ReAL_, _REal_, _REaL_, _REAl_, _REAL_, 
-		_nonc_, _nonC_, _noNc_, _noNC_, _nOnc_, _nOnC_, _nONc_, _nONC_, 
-		_Nonc_, _NonC_, _NoNc_, _NoNC_, _NOnc_, _NOnC_, _NONc_, _NONC_, 
-		_resp_, _resP_, _reSp_, _reSP_, _rEsp_, _rEsP_, _rESp_, _rESP_, 
-		_Resp_, _ResP_, _ReSp_, _ReSP_, _REsp_, _REsP_, _RESp_, _RESP_, 
-		_onse_, _onsE_, _onSe_, _onSE_, _oNse_, _oNsE_, _oNSe_, _oNSE_, 
-		_Onse_, _OnsE_, _OnSe_, _OnSE_, _ONse_, _ONsE_, _ONSe_, _ONSE_, 
-		_cnon_, _cnoN_, _cnOn_, _cnON_, _cNon_, _cNoN_, _cNOn_, _cNON_, 
-		_Cnon_, _CnoN_, _CnOn_, _CnON_, _CNon_, _CNoN_, _CNOn_, _CNON_, 
-		_opaq_, _opaQ_, _opAq_, _opAQ_, _oPaq_, _oPaQ_, _oPAq_, _oPAQ_, 
-		_Opaq_, _OpaQ_, _OpAq_, _OpAQ_, _OPaq_, _OPaQ_, _OPAq_, _OPAQ_, 
-		_algo_, _algO_, _alGo_, _alGO_, _aLgo_, _aLgO_, _aLGo_, _aLGO_, 
-		_Algo_, _AlgO_, _AlGo_, _AlGO_, _ALgo_, _ALgO_, _ALGo_, _ALGO_, 
-		_rith_, _ritH_, _riTh_, _riTH_, _rIth_, _rItH_, _rITh_, _rITH_, 
-		_Rith_, _RitH_, _RiTh_, _RiTH_, _RIth_, _RItH_, _RITh_, _RITH_
-	};
-
-
-	     /* Mark all elements as empty */
-	for(i = 0; i < HASH_TABLE_SIZE; i++) {
-		set_entry(HASH_EMPTY, HASH_EMPTY);
-	}
-
-	k = 0;
-
-	     /* Initialize hash table content */
-	for(i = 0; i < NUM_VALS; i++) {
-		for(j = 0; j < key_nums[i]; j++) {
-			set_entry(init_key[k++], init_val[i]);
-		}
-	}
-}

+ 0 - 7
parser/digest/param_parser.h

@@ -57,11 +57,4 @@ typedef enum dig_par {
  */
 int parse_param_name(str* _s, dig_par_t* _type);
 
-
-/*
- * Initialize hash table
- */
-void init_digest_htable(void);
-
-
 #endif /* PARAM_PARSER_H */