int len;
int rc = COUNTER_FLAG_SKIP;
- // DEBUG_CAL("getCounterFlag\n");
-
- ASSERT(cond != NULL, "Null condition found\n");
+ /* check */
+ if (cond == NULL) {
+ ERROR("Null condition found");
+ return 0;
+ }
+ if (name == NULL) {
+ ERROR("Null condition found");
+ return 0;
+ }
+ /* parse the flag */
len = strlen(cond);
loc = strstr(cond, name);
loc = skipWhiteSpace(loc, &len);
if (isEndOfString(loc)) {
- return -1;
+ goto error; //return -1;
}
/* operation, "<" ">=" only */
- if ((len >= 2) && (loc[0] == 'l') && (loc[1] == 't')) {
- /* <, lt */
- // DEBUG("COUNTER_FLAG_LT");
+ if ((len >= 2) && (loc[0] == 'l') && (loc[1] == 't')) { // <, lt
rc = COUNTER_FLAG_LT;
loc +=2;
len -=2;
- } else if ((len >= 2) && (loc[0] == '>') && (loc[1] == '=')) {
- /* >= */
- // DEBUG("COUNTER_FLAG_GTE");
- rc = COUNTER_FLAG_GTE;
+ } else if ((len >= 2) && (loc[0] == 'l') && (loc[1] == 'e')) { // <=, le
+ rc = COUNTER_FLAG_LE;
+ loc +=2;
+ len -=2;
+ } else if ((len >= 2) && (loc[0] == 'g') && (loc[1] == 't')) { // >, gt
+ rc = COUNTER_FLAG_GT;
+ loc +=2;
+ len -=2;
+ } else if ((len >= 2) && (loc[0] == 'g') && (loc[1] == 'e')) { // >, gt
+ rc = COUNTER_FLAG_GE;
+ loc +=2;
+ len -=2;
+ } else if ((len >= 2) && (loc[0] == '<') && (loc[1] == ' ')) { // <, lt
+ rc = COUNTER_FLAG_LT;
+ loc +=2;
+ len -=2;
+ } else if ((len >= 2) && (loc[0] == '<') && (loc[1] == '=')) { // <=, le
+ rc = COUNTER_FLAG_LE;
+ loc +=2;
+ len -=2;
+ } else if ((len >= 2) && (loc[0] == '>') && (loc[1] == ' ')) { // >, gt
+ rc = COUNTER_FLAG_GT;
+ loc +=2;
+ len -=2;
+ } else if ((len >= 2) && (loc[0] == '>') && (loc[1] == '=')) { // >=
+ rc = COUNTER_FLAG_GE;
loc +=2;
len -=2;
} else {
ERROR("unknown operand [%s]", &loc[0]);
- return -1; // unknown operand
+ goto error; //return -1;
}
loc = skipWhiteSpace(loc, &len);
if (isEndOfString(loc)) {
- return -1;
+ goto error; //return -1;
}
// TODO check the end, this code only support if counter is the last
param_len = loc2 - loc;
if (0 == param_len) {
/* we haven't moved along the string - no valid parameter found */
- return -1;
+ goto error; //return -1;
}
/* DEBUG_FSM("[%d][%s][%s]\n",len, loc, loc2); */
*flag = xmalloc(param_len + 1);
if (*flag == NULL) {
- return -1;
+ goto error; //return -1;
}
memset(*flag, 0, param_len + 1);
memcpy(*flag, loc, param_len);
DEBUG_FSM("getCounterFlag %s #=> %d %s\n", cond, rc, *flag);
return rc;
+
+ error:
+ ERROR("getCounterFlag(\"%s\",\"%s\") fail", cond, name);
+ return -1;
}
ptr->digestFlag = getDigestFlag(cond, &ptr->digest, &ptr->digestSize);
// 0:don't care, 1:<, 2:>=
ptr->counter_flag = getCounterFlag(cond, "digest_count", &ptr->counter_name);
+ if (ptr->counter_flag < 0) {
+ ERROR("getCounterFlag() fail (%s => %s [%s])", source, target, cond);
+ }
// 0:don't care, 1:<, 2:>=
ptr->fatal_counter_flag = getCounterFlag(cond, "fatal_count", &ptr->fatal_counter_name);
+ if (ptr->fatal_counter_flag < 0) {
+ ERROR("getCounterFlag() fail (%s => %s [%s])", source, target, cond);
+ }
// 0:don't care 1: ==last 2: != last
ptr->last_flag = getLastFlag(cond);
memcpy(ptr->cond, cond, FSM_BUF_SIZE);
/**
* get counter(int) value from property
- * if property is missing or invalid, it returns 1;
+ * property
+ * name=num
+ *
+ * return
+ * -1 : ERROR
+ * 1 : missing, invalid (e.g. minus)
+ * num
*/
int getCountFromProperty(OPENPTS_CONTEXT *ctx, char * name) {
int count = 0; // TODO get from prop
OPENPTS_PROPERTY *prop;
+ /* check */
+ if (ctx == NULL) {
+ ERROR("ctx == NULL");
+ return -1;
+ }
+ if (name == NULL) {
+ ERROR("name == NULL");
+ return -1;
+ }
+
+ /* lookup */
prop = getProperty(ctx, name);
if (prop != NULL) {
/* Hit use this properties */
count = atoi(prop->value);
DEBUG_FSM("getCountFromProperty - prop %s = %d\n", name, count);
if (count < 0) {
+ DEBUG("getCountFromProperty - prop %s is %d < 0. set count to 1\n", count, name);
count = 1;
}
} else {
/* Miss -> 1 */
// TODO
- // DEBUG("getCountFromProperty - prop %s is missing. set count to 1\n", name);
+ DEBUG("getCountFromProperty - prop %s is missing. set count to 1\n", name);
count = 1; // TODO
}
return count;
/* count < name */
int fatal_count = getCountFromProperty(ctx, trans->fatal_counter_name);
- if (ctx->count < fatal_count) {
+ if (fatal_count < 0) {
+ ERROR("getCountFromProperty() fail");
+ } else if (ctx->count < fatal_count) {
DEBUG_FSM("FATAL COUNTER %d < %d - HIT\n", ctx->count, fatal_count);
fatal_counter_check = 1; // HIT
} else {
DEBUG_FSM("FATAL COUNTER %d < %d - MISS\n", ctx->count, fatal_count);
fatal_counter_check = -1; // MISS
}
- } else if (trans->fatal_counter_flag == COUNTER_FLAG_GTE) {
+ } else if (trans->fatal_counter_flag == COUNTER_FLAG_GE) {
/* count >= name */
int fatal_count = getCountFromProperty(ctx, trans->fatal_counter_name);
// TODO at this moment we ignore >= condition,
- if (ctx->count >= fatal_count) {
+ if (fatal_count < 0) {
+ ERROR("getCountFromProperty() fail");
+ } else if (ctx->count >= fatal_count) {
DEBUG_FSM("FATAL COUNTER %d >= %d - HIT\n", ctx->count, fatal_count);
fatal_counter_check = 1; // HIT
} else {
if (trans->counter_flag != COUNTER_FLAG_SKIP) {
int thisCount = 1 + trans->event_num;
int maxCount = getCountFromProperty(ctx, trans->counter_name);
- if (trans->counter_flag == COUNTER_FLAG_GTE &&
+ if (maxCount < 0) {
+ ERROR("getCountFromProperty() fail, trans->counter_flag=%d", trans->counter_flag);
+ } else if (trans->counter_flag == COUNTER_FLAG_GE &&
thisCount >= maxCount) {
DEBUG_FSM("DIGEST COUNTER %d >= %d ('%s') - digest is transparent\n",
thisCount, maxCount, trans->counter_name);