00001
00002
00003
00004
00005
00006
00007 #include "rlp.h"
00008
00009
00010
00011
00012
00013
00014
00015 static int push (array_t * rule, char *attribute, char *value);
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 array_t *
00029 Rlp_L7StringParse (char *l7Rule)
00030 {
00031 char *linePtr = l7Rule;
00032 char *tmpPtr;
00033 char tmpbuf[10000];
00034 char *field;
00035 char *attribute, *value;
00036 int rlpDebug = false;
00037
00038 array_t *aRule = array_alloc (Rlp_RuleComponent_t *, 0);
00039
00040 while (true)
00041 {
00042 bool nocolon = false;
00043
00044 tmpPtr = linePtr;
00045 while (true)
00046 {
00047 tmpPtr = strchr (tmpPtr, ';');
00048 if (tmpPtr == NULL)
00049 {
00050 goto finished;
00051 }
00052 if (tmpPtr[-1] == '\\')
00053 {
00054 tmpPtr++;
00055 }
00056 else
00057 {
00058 break;
00059 }
00060 }
00061
00062 RLP_STRNCPY_TERMINATE (tmpbuf, linePtr, (tmpPtr - linePtr));
00063 linePtr = tmpPtr + 1;
00064
00065 tmpPtr = strdup (tmpbuf);
00066 char *tmpPtr2 = tmpPtr;
00067 RLP_SKIP_SPACE (tmpPtr);
00068 field = strdup (tmpPtr);
00069 free (tmpPtr2);
00070
00071 tmpPtr = field;
00072 while (true)
00073 {
00074 tmpPtr = strchr (tmpPtr, ':');
00075 if (tmpPtr == NULL)
00076 {
00077 nocolon = true;
00078 break;
00079 }
00080 if (tmpPtr[-1] == '\\')
00081 {
00082 tmpPtr++;
00083 }
00084 else
00085 {
00086 break;
00087 }
00088 }
00089 if (nocolon)
00090 {
00091 attribute = strdup (field);
00092 value = "NIL";
00093 }
00094 else
00095 {
00096 RLP_STRNCPY_TERMINATE (tmpbuf, field, (tmpPtr - field));
00097 attribute = strdup (tmpbuf);
00098 value = strdup (tmpPtr + 1);
00099 RLP_SKIP_SPACE (value);
00100 }
00101 if (rlpDebug)
00102 {
00103 printf ("Attribute: %s ; Value : %s\n", attribute, value);
00104 }
00105
00106 push (aRule, attribute, value);
00107 }
00108 finished:return aRule;
00109 }
00110
00111
00112
00113
00114 static int
00115 push (array_t * rule, char *attribute, char *value)
00116 {
00117 Rlp_RuleComponent_t *aComponent =
00118 (Rlp_RuleComponent_t *) malloc (sizeof (Rlp_RuleComponent_t));
00119 aComponent->rawAttribute = attribute;
00120 aComponent->rawValue = value;
00121
00122 array_insert_last (Rlp_RuleComponent_t *, rule, aComponent);
00123
00124 return 1;
00125 }