00001
00002
00003
00004
00005
00006
00007 #include "rlp.h"
00008
00009
00010
00011
00012
00013
00014
00015
00016 Rlp_Action_t *
00017 Rlp_AllocActionStruct ()
00018 {
00019 Rlp_Action_t *result = (Rlp_Action_t *) malloc (sizeof (Rlp_Action_t));
00020 result->type = Rlp_ActionUnassigned_c;
00021 result->dest = NIL (char);
00022 result->queue = NIL (char);
00023 result->classIndex = 0;
00024
00025 result->uscript = NIL (char);
00026
00027 result->ucodeName = NIL (char);
00028 result->ucodeFunction = NULL;
00029 result->ucodeFunctionState = NULL;
00030
00031 result->argument = NIL (char);
00032
00033 return result;
00034 }
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 Rlp_Action_t *
00050 Rlp_CreateActionFromRawText (char *rawFormula)
00051 {
00052 Rlp_Action_t *result = Rlp_AllocActionStruct ();
00053 char *attribute;
00054 char *value;
00055
00056 while (*rawFormula == ' ')
00057 {
00058 rawFormula++;
00059 }
00060
00061
00062
00063
00064
00065 if (util_strequalN (rawFormula, "tcl-ext:", strlen ("tcl-ext:")) ||
00066 util_strequalN (rawFormula, "c-ext:", strlen ("c-ext:")))
00067 {
00068 char *dupString;
00069 if (util_strequalN (rawFormula, "tcl-ext:", strlen ("tcl-ext:")))
00070 {
00071 result->type = Rlp_ActionUscript_c;
00072 dupString = result->uscript =
00073 strdup (rawFormula + strlen ("tcl-ext:"));
00074 }
00075 else
00076 {
00077 result->type = Rlp_ActionUcode_c;
00078 dupString = result->ucodeName =
00079 strdup (rawFormula + strlen ("c-ext:"));
00080 }
00081
00082 char *semicolonPtr;
00083 char *colonPtr;
00084 if (!(colonPtr = strchr (dupString, ':')))
00085 {
00086
00087
00088 assert (NIL (char) != (semicolonPtr = strchr (dupString, ';')));
00089 *semicolonPtr = '\0';
00090 }
00091 else
00092 {
00093
00094
00095 *colonPtr = '\0';
00096
00097 char *argument = strdup (colonPtr + 1);
00098
00099 assert (argument[strlen (argument) - 2] == ';');
00100 argument[strlen (argument) - 1] = '\0';
00101 result->argument = argument;
00102 }
00103 return result;
00104 }
00105
00106
00107
00108
00109
00110
00111 bool haveQueue = false;
00112 bool haveClass = false;
00113 array_t *attributesArray = Rlp_L7StringParse (rawFormula);
00114 int i;
00115 for (i = 0; i < array_n (attributesArray); i++)
00116 {
00117 Rlp_RuleComponent_t *aComponent = array_fetch (Rlp_RuleComponent_t *,
00118 attributesArray, i);
00119 attribute = aComponent->rawAttribute;
00120 value = aComponent->rawValue;
00121
00122 if (util_strequal (attribute, "drop"))
00123 {
00124 result->type = Rlp_ActionDrop_c;
00125 }
00126 else if (util_strequal (attribute, "queue"))
00127 {
00128 result->type = Rlp_ActionQueue_c;
00129 result->queue = strdup (value);
00130 haveQueue = true;
00131 }
00132 else if (util_strequal (attribute, "class"))
00133 {
00134 sscanf (value, "%d", &result->classIndex);
00135 haveClass = true;
00136 }
00137 else if (util_strequal (attribute, "route"))
00138 {
00139 result->type = Rlp_ActionRoute_c;
00140 char tmp[100];
00141 sscanf (value, "%s", tmp);
00142 result->dest = strdup (tmp);
00143 }
00144 else if (util_strequal (attribute, "tcl"))
00145 {
00146 printf ("PANIC: shold have picked up tcl earlier in code\n");
00147 assert (0);
00148 }
00149 else
00150 {
00151 printf ("PANIC: Don't support construct %s in action\n", attribute);
00152 assert (0);
00153 }
00154 }
00155 return result;
00156 }
00157
00158
00159
00160
00161 void
00162 Rlp_ActionPrint (Rlp_Action_t * action)
00163 {
00164 printf ("drop = %s; dest = %s ; queue = %s; class = %d\n",
00165 (action->type == Rlp_ActionDrop_c) ? "true" : "false", action->dest,
00166 action->queue, action->classIndex);
00167 }