Esempio n. 1
0
uchar determineExprType(char *pred, int plen) {
    if (*pred == '\'') {
        if (plen < 3)                           return UETYPE_ERR;
        if (_strnchr(pred + 1, '\'', plen - 1)) return UETYPE_STRING;
        else                                    return UETYPE_ERR;
    }
    if (*pred == '"') {
        if (plen < 3)                           return UETYPE_ERR;
        if (_strnchr(pred + 1, '"', plen - 1))  return UETYPE_STRING;
        else                                    return UETYPE_ERR;
    }
    if (plen >= 64)                             return UETYPE_ERR;
    memcpy(Up_col_buf, pred, plen);
    Up_col_buf[plen] = '\0';
    if (is_int(Up_col_buf))                     return UETYPE_INT;
    if (is_float(Up_col_buf))                   return UETYPE_FLOAT;
    return UETYPE_ERR;
}
Esempio n. 2
0
bool parseJoinColsReply(redisClient *c,
                        char        *y,
                        int          len,
                        int         *numt,
                        int          tmatchs[],
                        int          j_tbls[],
                        int          j_cols[],
                        int        *qcols,
                        bool       *cstar) {
   if (!strcasecmp(y, "COUNT(*)")) {
        *cstar = 1;
        return 1;
    }
    if (*y == '*') {
        for (int i = 0; i < *numt; i++) {
            int tmatch = tmatchs[i];
            for (int j = 0; j < Tbl[server.dbid][tmatch].col_count; j++) {
                j_tbls[*qcols] = tmatch;
                j_cols[*qcols] = j;
                *qcols         = *qcols + 1;
            }
        }
        return 1;
    }

    char *nextp = _strnchr(y, '.', len);
    if (!nextp) {
        addReply(c, shared.indextargetinvalid);
        return 0;
    }

    char *tname  = y;
    int   tlen   = nextp - y;
    int   tmatch = find_table_n(tname, tlen);
    if (tmatch == -1) {
        addReply(c,shared.nonexistenttable);
        return 0;
    }

    char *cname  = nextp + 1;
    int   clen   = len - tlen - 1;
    int   cmatch = find_column_n(tmatch, cname, clen);
    if (cmatch == -1) {
        addReply(c,shared.nonexistentcolumn);
        return 0;
    }

    j_tbls[*qcols] = tmatch;
    j_cols[*qcols] = cmatch;
    *qcols         = *qcols + 1;
    return 1;
}
Esempio n. 3
0
File: mime.c Progetto: fsword/nyara
// m1, m2: request
// v1, v2: action
static bool _mime_match_seg(const char* m1_ptr, long m1_len, VALUE v1, VALUE v2) {
  const char* m2_ptr = _strnchr(m1_ptr, m1_len, '/');
  long m2_len;
  if (m2_ptr) {
    m2_ptr++;
    m2_len = m1_len - (m2_ptr - m1_ptr);
    m1_len = (m2_ptr - m1_ptr) - 1;
  } else {
    m2_len = 0;
  }

  const char* v1_ptr = RSTRING_PTR(v1);
  const char* v2_ptr = RSTRING_PTR(v2);
  const long  v1_len = RSTRING_LEN(v1);
  const long  v2_len = RSTRING_LEN(v2);

# define EQL_STAR(s, len) (len == 1 && s[0] == '*')
# define EQL(s1, len1, s2, len2) (len1 == len2 && strncmp(s1, s2, len1) == 0)

  if (EQL_STAR(m1_ptr, m1_len)) {
    if (m2_len == 0 || EQL_STAR(m2_ptr, m2_len)) {
      return true;
    } else if (EQL(m2_ptr, m2_len, v2_ptr, v2_len)) {
      return true;
    } else {
      return false;
    }
  }
  if (!EQL(v1_ptr, v1_len, m1_ptr, m1_len)) {
    return false;
  }
  if (m2_len == 0 || EQL_STAR(m2_ptr, m2_len)) {
    return true;
  }
  return EQL(m2_ptr, m2_len, v2_ptr, v2_len);

# undef EQL
# undef EQL_STAR
}
Esempio n. 4
0
// key and value are for output
// usually should be blank string
// decode into key and value
void nyara_decode_uri_kv(volatile VALUE key, volatile VALUE value, const char* kv_s, long kv_len) {
  const char* s = kv_s;
  long len = kv_len;
  if (!len) {
    rb_raise(rb_eArgError, "empty key=value segment");
  }

  // rule out the value part
  {
    // strnstr is not available on linux :(
    const char* value_s = _strnchr(s, len, '=');
    if (value_s) {
      value_s++;
      long value_len = s + len - value_s;
      long skipped = 0;
      for (;skipped < value_len; skipped++) {
        if (!isspace(value_s[skipped])) {
          break;
        }
      }
      long parsed = _decode_url_seg(value, value_s + skipped, value_len - skipped, '&');
      if (parsed != value_len - skipped) {
        rb_raise(rb_eArgError, "separator & in param segment");
      }
      len = value_s - s - 1;
    }
    // starts with '='
    if (value_s == s) {
      return;
    }
  }
  while (len > 0 && isspace(s[len - 1])) {
    len--;
  }
  _decode_url_seg(key, s, len, '=');
}
Esempio n. 5
0
char* 
cfe_env_get(unsigned char *nv_buf, char* name)
{
    int size;
    unsigned char *buffer;
    unsigned char *ptr;
    unsigned char *envval;
    unsigned int reclen;
    unsigned int rectype;
    int offset;
    int flg;
    
    size = NVRAM_SIZE;
    buffer = &_nvdata[0];

    ptr = buffer;
    offset = 0;

    /* Read the record type and length */
    if (_nvram_read(nv_buf, ptr,offset,1) != 1) {
	goto error;
    }
    
    while ((*ptr != ENV_TLV_TYPE_END)  && (size > 1)) {

	/* Adjust pointer for TLV type */
	rectype = *(ptr);
	offset++;
	size--;

	/* 
	 * Read the length.  It can be either 1 or 2 bytes
	 * depending on the code 
	 */
	if (rectype & ENV_LENGTH_8BITS) {
	    /* Read the record type and length - 8 bits */
	    if (_nvram_read(nv_buf, ptr,offset,1) != 1) {
		goto error;
	    }
	    reclen = *(ptr);
	    size--;
	    offset++;
	}
	else {
	    /* Read the record type and length - 16 bits, MSB first */
	    if (_nvram_read(nv_buf, ptr,offset,2) != 2) {
		goto error;
	    }
	    reclen = (((unsigned int) *(ptr)) << 8) + (unsigned int) *(ptr+1);
	    size -= 2;
	    offset += 2;
	}

	if (reclen > size)
	    break;	/* should not happen, bad NVRAM */

	switch (rectype) {
	    case ENV_TLV_TYPE_ENV:
		/* Read the TLV data */
		if (_nvram_read(nv_buf, ptr,offset,reclen) != reclen)
		    goto error;
		flg = *ptr++;
		envval = (unsigned char *) _strnchr(ptr,'=',(reclen-1));
		if (envval) {
		    *envval++ = '\0';
		    memcpy(_valuestr,envval,(reclen-1)-(envval-ptr));
		    _valuestr[(reclen-1)-(envval-ptr)] = '\0';
#if 0			
		    printk(KERN_INFO "NVRAM:%s=%s\n", ptr, _valuestr);
#endif
		    if(!strcmp(ptr, name)){
			return _valuestr;
		    }
		    if((strlen(ptr) > 1) && !strcmp(&ptr[1], name))
			return _valuestr;
		}
		break;
		
	    default: 
		/* Unknown TLV type, skip it. */
		break;
	    }

	/*
	 * Advance to next TLV 
	 */
		
	size -= (int)reclen;
	offset += reclen;

	/* Read the next record type */
	ptr = buffer;
	if (_nvram_read(nv_buf, ptr,offset,1) != 1)
	    goto error;
	}

error:
    return NULL;

}
Esempio n. 6
0
bool parseExprReply(redisClient *c,
                    char         e,
                    int          tmatch,
                    int          cmatch,
                    uchar        ctype,
                    char        *val,
                    uint32       vlen,
                    ue_t        *ue) {
    char  *cname = val;
    while (isblank(*cname)) cname++;       /* cant fail "e" already found */
    char  *espot = _strnchr(val, e, vlen); /* cant fail - "e" already found */
    if (((espot - val) == (vlen - 1)) ||
        ((e == STRCAT) && ((espot - val) == (vlen - 2)))) {
        addReply(c, shared.update_expr);
        return 0;
    }
    char  *cend     = espot - 1;
    while (isblank(*cend)) cend--;
    int    uec1match = find_column_n(tmatch, cname, cend - cname + 1);
    if (uec1match == -1) {
        addReply(c, shared.update_expr_col);
        return 0;
    }
    if (uec1match != cmatch) {
        addReply(c, shared.update_expr_col_other);
        return 0;
    }
    char *pred = espot + 1;
    if (e == STRCAT) pred++;
    while (isblank(*pred)) {        /* find predicate (after blanks) */
        pred++;
        if ((pred - val) == vlen) {
            addReply(c, shared.update_expr);
            return 0;
        }
    }
    char *pend = val + vlen -1;     /* start from END */
    while (isblank(*pend)) pend--;  /* find end of predicate */
    int   plen  = pend - pred + 1;
    uchar uetype = determineExprType(pred, plen);

    if (uetype == UETYPE_ERR) {
        addReply(c, shared.update_expr_col);
        return 0;
    }

    /* RULES FOR UPDATE EXPRESSIONS */
    if (uetype == UETYPE_STRING && ctype != COL_TYPE_STRING) {
        addReply(c, shared.update_expr_math_str);
        return 0;
    }
    if (e == MODULO && ctype != COL_TYPE_INT) {
        addReply(c, shared.update_expr_mod);
        return 0;
    }
    if (e == STRCAT && (ctype != COL_TYPE_STRING || uetype != UETYPE_STRING)) {
        addReply(c, shared.update_expr_cat);
        return 0;
    }
    if (ctype == COL_TYPE_STRING && e != STRCAT) {
        addReply(c, shared.update_expr_str);
        return 0;
    }

    if (uetype == UETYPE_STRING) { /* ignore string delimiters */
        pred++;
        plen -= 2;
        if (plen == 0) {
            addReply(c, shared.update_expr_empty_str);
            return 0;
        }
    }

    ue->c1match = uec1match;
    ue->type    = uetype;
    ue->pred    = pred;
    ue->plen    = plen;
    ue->op      = e;
    return 1;
}