void DeleteElementFieldTokenWrapped(struct _nbNetPDLElementBase *NetPDLElementBase) { struct _nbNetPDLElementFieldTokenWrapped *NetPDLElement= (struct _nbNetPDLElementFieldTokenWrapped *) NetPDLElementBase; DELETE_PTR(NetPDLElement->BeginTokenString); DELETE_PTR(NetPDLElement->EndTokenString); DELETE_PTR(NetPDLElement->BeginRegularExpression); if (NetPDLElement->BeginPCRECompiledRegExp) pcre_free(NetPDLElement->BeginPCRECompiledRegExp); DELETE_PTR(NetPDLElement->EndRegularExpression); if (NetPDLElement->EndPCRECompiledRegExp) pcre_free(NetPDLElement->EndPCRECompiledRegExp); DELETE_PTR(NetPDLElement->BeginOffsetExprString); if (NetPDLElement->BeginOffsetExprTree) FreeExpression(NetPDLElement->BeginOffsetExprTree); DELETE_PTR(NetPDLElement->EndOffsetExprString); if (NetPDLElement->EndOffsetExprTree) FreeExpression(NetPDLElement->EndOffsetExprTree); DELETE_PTR(NetPDLElement->EndDiscardExprString); if (NetPDLElement->EndDiscardExprTree) FreeExpression(NetPDLElement->EndDiscardExprTree); }
void FreeExpression(Expression *e) { if (!e) { return; } switch (e->op) { case OR: case AND: FreeExpression(e->val.andor.lhs); FreeExpression(e->val.andor.rhs); break; case NOT: FreeExpression(e->val.not.arg); break; case EVAL: FreeStringExpression(e->val.eval.name); break; default: FatalError("Unknown logic expression type encountered in" "FreeExpression: %d", e->op); } free(e); }
void DeleteElementCfieldXML(struct _nbNetPDLElementBase *NetPDLElementBase) { struct _nbNetPDLElementCfieldXML *NetPDLElement= (struct _nbNetPDLElementCfieldXML *) NetPDLElementBase; FreeExpression(NetPDLElement->SizeExprTree); DELETE_PTR(NetPDLElement->SizeExprString); }
bool IsDefinedClass(const EvalContext *ctx, const char *context, const char *ns) { ParseResult res; if (!context) { return true; } res = ParseExpression(context, 0, strlen(context)); if (!res.result) { Log(LOG_LEVEL_ERR, "Unable to parse class expression '%s'", context); return false; } else { EvalTokenAsClassContext etacc = { .ctx = ctx, .ns = ns }; ExpressionValue r = EvalExpression(res.result, &EvalTokenAsClass, &EvalVarRef, &etacc); FreeExpression(res.result); /* r is EvalResult which could be ERROR */ return r == true; } }
static ParseResult ParseAndExpression(const char *expr, int start, int end) { ParseResult lhs, rhs; Expression *res; lhs = ParseNotExpression(expr, start, end); if (!lhs.result) { return lhs; } if (lhs.position == end || (expr[lhs.position] != '.' && expr[lhs.position] != '&')) { return lhs; } rhs = ParseAndExpression(expr, lhs.position + 1, end); if (!rhs.result) { FreeExpression(lhs.result); return rhs; } res = xcalloc(1, sizeof(Expression)); res->op = AND; res->val.andor.lhs = lhs.result; res->val.andor.rhs = rhs.result; return (ParseResult) { res, rhs.position }; }
bool IsDefinedClass(const EvalContext *ctx, const char *context, const char *ns) { ParseResult res; if (!context) { return true; } res = ParseExpression(context, 0, strlen(context)); if (!res.result) { char *errexpr = HighlightExpressionError(context, res.position); CfOut(OUTPUT_LEVEL_ERROR, "", "Unable to parse class expression: %s", errexpr); free(errexpr); return false; } else { ExpressionValue r = EvalExpression(ctx, res.result, &EvalTokenAsClass, &EvalVarRef, (void *)ns); FreeExpression(res.result); CfDebug("Evaluate(%s) -> %d\n", context, r); /* r is EvalResult which could be ERROR */ return r == true; } }
void DeleteElementFieldmatch(struct _nbNetPDLElementBase *NetPDLElementBase) { struct _nbNetPDLElementFieldmatch *NetPDLElement= (struct _nbNetPDLElementFieldmatch *) NetPDLElementBase; FreeExpression(NetPDLElement->MatchExprTree); DELETE_PTR(NetPDLElement->MatchExprString); }
void DeleteElementCfieldTLV(struct _nbNetPDLElementBase *NetPDLElementBase) { struct _nbNetPDLElementCfieldTLV *NetPDLElement= (struct _nbNetPDLElementCfieldTLV *) NetPDLElementBase; FreeExpression(NetPDLElement->ValueExprTree); DELETE_PTR(NetPDLElement->ValueExprString); }
void DeleteElementFieldVariable(struct _nbNetPDLElementBase *NetPDLElementBase) { struct _nbNetPDLElementFieldVariable *NetPDLElement= (struct _nbNetPDLElementFieldVariable *) NetPDLElementBase; FreeExpression(NetPDLElement->ExprTree); FREE_PTR(NetPDLElement->ExprString); }
static bool EvalWithTokenFromList(EvalContext *ctx, const char *expr, StringSet *token_set) { ParseResult res = ParseExpression(expr, 0, strlen(expr)); if (!res.result) { char *errexpr = HighlightExpressionError(expr, res.position); CfOut(OUTPUT_LEVEL_ERROR, "", "Syntax error in expression: %s", errexpr); free(errexpr); return false; /* FIXME: return error */ } else { ExpressionValue r = EvalExpression(ctx, res.result, &EvalTokenFromList, &EvalVarRef, token_set); FreeExpression(res.result); /* r is EvalResult which could be ERROR */ return r == true; } }
void DeleteElementNextProto(struct _nbNetPDLElementBase *NetPDLElementBase) { struct _nbNetPDLElementNextProto *NetPDLElement= (struct _nbNetPDLElementNextProto *) NetPDLElementBase; FreeExpression(NetPDLElement->ExprTree); FREE_PTR(NetPDLElement->ExprString); free(NetPDLElement); }
void DeleteElementExitWhen(struct _nbNetPDLElementBase *NetPDLElementBase) { struct _nbNetPDLElementExitWhen *NetPDLElement= (struct _nbNetPDLElementExitWhen *) NetPDLElementBase; FreeExpression(NetPDLElement->ExitExprTree); DELETE_PTR(NetPDLElement->ExitExprString); free(NetPDLElement); }
static ParseResult ParsePrimary(const char *expr, int start, int end) { if (start < end && expr[start] == '(') { ParseResult res = ParseExpression(expr, start + 1, end); if (res.result) { /* Check there is a matching ')' at the end */ if (res.position < end && expr[res.position] == ')') { return (ParseResult) { res.result, res.position + 1 }; } else { /* Didn't find a matching bracket. Give up */ FreeExpression(res.result); return (ParseResult) { NULL, res.position }; } } else { return res; } } else { StringParseResult strres = ParseStringExpression(expr, start, end); if (strres.result) { Expression *res = xcalloc(1, sizeof(Expression)); res->op = EVAL; res->val.eval.name = strres.result; return (ParseResult) { res, strres.position }; } else { return (ParseResult) { NULL, strres.position }; } } }
void DeleteElementShowCodeText(struct _nbNetPDLElementBase *NetPDLElementBase) { struct _nbNetPDLElementText *NetPDLElement= (struct _nbNetPDLElementText *) NetPDLElementBase; FREE_PTR(NetPDLElement->Value); FREE_PTR(NetPDLElement->ExprString); if (NetPDLElement->ExprTree) FreeExpression(NetPDLElement->ExprTree); free(NetPDLElement); }
static bool ValidClassName(const char *str) { ParseResult res = ParseExpression(str, 0, strlen(str)); if (res.result) { FreeExpression(res.result); } return res.result && res.position == strlen(str); }
void DeleteElementAssignVariable(struct _nbNetPDLElementBase *NetPDLElementBase) { struct _nbNetPDLElementAssignVariable *NetPDLElement= (struct _nbNetPDLElementAssignVariable *) NetPDLElementBase; FREE_PTR(NetPDLElement->VariableName); FreeExpression(NetPDLElement->ExprTree); FREE_PTR(NetPDLElement->ExprString); free(NetPDLElement); }
void DeleteElementLookupKeyData(struct _nbNetPDLElementBase *NetPDLElementBase) { struct _nbNetPDLElementLookupKeyData *NetPDLElement= (struct _nbNetPDLElementLookupKeyData *) NetPDLElementBase; DELETE_PTR(NetPDLElement->Mask); FreeExpression(NetPDLElement->ExprTree); DELETE_PTR(NetPDLElement->ExprString); free(NetPDLElement); }
bool RegularExpression::Set(const char* strPattern) { FreeExpression(); int iResult = regcomp(&m_CompiledExpression, strPattern, REG_EXTENDED); if (iResult != 0) return false; m_bExpressionSet = true; return true; }
void DeleteElementExecuteX(struct _nbNetPDLElementBase *NetPDLElementBase) { struct _nbNetPDLElementExecuteX *NetPDLElement= (struct _nbNetPDLElementExecuteX *) NetPDLElementBase; if (NetPDLElement->WhenExprTree) { FreeExpression(NetPDLElement->WhenExprTree); DELETE_PTR(NetPDLElement->WhenExprString); } free(NetPDLElement); }
void DeleteElementAssignLookupTable(struct _nbNetPDLElementBase *NetPDLElementBase) { struct _nbNetPDLElementAssignLookupTable *NetPDLElement= (struct _nbNetPDLElementAssignLookupTable *) NetPDLElementBase; DELETE_PTR(NetPDLElement->TableName); DELETE_PTR(NetPDLElement->FieldName); FreeExpression(NetPDLElement->ExprTree); DELETE_PTR(NetPDLElement->ExprString); free(NetPDLElement); }
void FreeOp( AIOp_t *op ) { if ( !op ) { return; } if ( isBinaryOp( op->opType ) ) { AIBinaryOp_t *b = ( AIBinaryOp_t * ) op; FreeExpression( b->exp1 ); FreeExpression( b->exp2 ); } else if ( isUnaryOp( op->opType ) ) { AIUnaryOp_t *u = ( AIUnaryOp_t * ) op; FreeExpression( u->exp ); } BG_Free( op ); }
ParseResult ParseExpression(const char *expr, int start, int end) { ParseResult lhs, rhs; Expression *res; int position; lhs = ParseAndExpression(expr, start, end); if (!lhs.result) { return lhs; } /* End of left-hand side expression */ position = lhs.position; if (position == end || expr[position] != '|') { return lhs; } /* Skip second '|' in 'lhs||rhs' */ if (position + 1 < end && expr[position + 1] == '|') { position++; } rhs = ParseExpression(expr, position + 1, end); if (!rhs.result) { FreeExpression(lhs.result); return rhs; } res = xcalloc(1, sizeof(Expression)); res->op = OR; res->val.andor.lhs = lhs.result; res->val.andor.rhs = rhs.result; return (ParseResult) { res, rhs.position }; }
static AIExpType_t *ReadConditionExpression( pc_token_list **list, AIOpType_t op2 ) { AIExpType_t *t; AIOpType_t op; if ( !*list ) { Log::Warn( "Unexpected end of file" ); return nullptr; } t = Primary( list ); if ( !t ) { return nullptr; } op = opTypeFromToken( &(*list)->token ); while ( isBinaryOp( op ) && opCompare( op, op2 ) >= 0 ) { AIExpType_t *t1; pc_token_list *prev = *list; AIOp_t *exp = newOp( *list ); *list = (*list)->next; t1 = ReadConditionExpression( list, op ); if ( !t1 ) { Log::Warn( "Missing right operand for %s on line %d", opTypeToString( op ), prev->token.line ); FreeExpression( t ); FreeOp( exp ); return nullptr; } t = makeExpression( exp, t, t1 ); op = opTypeFromToken( &(*list)->token ); } return t; }
/* To be used from parser only (uses yyerror) */ void ValidateClassSyntax(const char *str) { ParseResult res = ParseExpression(str, 0, strlen(str)); if (DEBUG) { EmitExpression(res.result, 0); putc('\n', stderr); } if (res.result) { FreeExpression(res.result); } if (!res.result || res.position != strlen(str)) { EmitParserError(str, res.position); } }
static bool EvalWithTokenFromList(const char *expr, StringSet *token_set) { ParseResult res = ParseExpression(expr, 0, strlen(expr)); if (!res.result) { Log(LOG_LEVEL_ERR, "Syntax error in expression '%s'", expr); return false; /* FIXME: return error */ } else { ExpressionValue r = EvalExpression(res.result, &EvalTokenFromList, &EvalVarRef, token_set); FreeExpression(res.result); /* r is EvalResult which could be ERROR */ return r == true; } }
RegularExpression::~RegularExpression() { FreeExpression(); }
// freeing behavior tree nodes void FreeConditionNode( AIConditionNode_t *node ) { FreeNode( node->child ); FreeExpression( node->exp ); BG_Free( node ); }