char *test_bassignblk(void)
{
	bstring b = bfromcstr("");
	mu_assert(bassignblk(b, test, strlen(test)) == BSTR_OK, "Failed to bassignblk.");
	mu_assert(strcmp((const char *)b->data, test) == 0, "Wrong string compare after bassignblk().");
	mu_assert(b->slen == (int)strlen(test), "wrong string length after bassignblk().");
	
	mu_assert(bassignblk(b, test, strlen(test) / 2) == BSTR_OK, "Failed to bassignblk.");
	mu_assert(strncmp((const char *)b->data, test, strlen(test) / 2) == 0, "Wrong string compare after bassignblk().");
	mu_assert(b->slen == (int)strlen(test) / 2, "wrong string length after bassignblk().");
	
	mu_assert(bdestroy(b) == BSTR_OK, "Failed to bdestroy() afetr bassignblk().");
	return NULL;
}
Beispiel #2
0
/* {{{ _php_bbcode_callback_handler
   Common code for content and parameter handlers */
static int _php_bbcode_callback_handler(int cb_type, bstring content, bstring param, zval *func_name)
{
	zval *retval = NULL;
	zval ***zargs = NULL;
	char *callable = NULL;
	int i, res;
	bstring target;
	char *cb_name = "";
	TSRMLS_FETCH();

	switch (cb_type) {
		case PHP_BBCODE_CONTENT_CB:
			target = content;
			break;

		case PHP_BBCODE_PARAM_CB:
			target = param;
			break;
	}

	zargs = (zval ***) emalloc(sizeof(zval **) * 2);
	zargs[0] = emalloc(sizeof(zval *));
	MAKE_STD_ZVAL(*zargs[0]);
	ZVAL_STRINGL(*zargs[0], bdata(content), blength(content), 1);
	zargs[1] = emalloc(sizeof(zval *));
	MAKE_STD_ZVAL(*zargs[1]);
	ZVAL_STRINGL(*zargs[1], bdata(param), blength(param), 1);

	res = call_user_function_ex(EG(function_table), NULL, func_name, &retval, 2, zargs, 1, NULL TSRMLS_CC);
	
	if (res != SUCCESS) {
		if (!zend_is_callable(func_name, 0, &callable TSRMLS_CC)) {
			php_error_docref(NULL TSRMLS_CC, E_WARNING, "function `%s' is not callable", callable);
		} else {
			php_error_docref(NULL TSRMLS_CC, E_WARNING, "callback function %s() failed", callable);
		}
		efree(callable);
	} else if (&retval != NULL) {
		convert_to_string_ex(&retval);
		if (Z_STRLEN_P(retval)) {
			bassignblk(target, Z_STRVAL_P(retval), Z_STRLEN_P(retval));
		} else {
			bdelete(target, 0, blength(target));
		}
		zval_ptr_dtor(&retval);
	}

	/* Free zargs */
	for (i = 0; i < 2; i++) {
		zval_ptr_dtor(zargs[i]);
		efree(zargs[i]);
	}
	efree(zargs);

	return 0;
}
Beispiel #3
0
char *test_bassignblk() {
    char * blk = malloc(1000);
    memset(blk, 1, 1000);

    bstring bstr = bfromcstr("");
    bassignblk(bstr, blk, 10);
    mu_assert(blength(bstr) == 10, "bassignblk failed");

    bdestroy(bstr);
    free(blk);
    return NULL;
}
Beispiel #4
0
int http_parse_input(char *src, int len, int is_cookie) {
  bstring name = bfromcstr("");
  bstring value = bfromcstr("");
  int start_pos=0, eq_pos=0, end_pos=0;
  int i, ret = 0;

  char stop = (is_cookie) ? ';' : '&';

  for (i=0; i <= len; i++) {
    if (i == len || src[i] == stop) {  end_pos = i; }
    else if (!eq_pos && src[i] == '=') {  eq_pos = i; }

    if (eq_pos && end_pos && start_pos != eq_pos) {

      bassigncstr(name, "");
      bassigncstr(value, "");

      if (is_cookie) {
        bassigncstr(name,"COOKIE_");
        bcatblk(name,src+start_pos,eq_pos-start_pos);
      } else {
        bassigncstr(name,"CAP_");
        bcatblk(name,src+start_pos,eq_pos-start_pos);
      }

      /*bunescape(name);*/

      if ((eq_pos + 1) == end_pos || (end_pos - eq_pos) <= 1) {
	syslog(LOG_DEBUG, "%s = nil", name->data);
      } else {
        bassignblk(value, src+eq_pos+1, end_pos-eq_pos-1);
        /*bunescape(value);*/
	syslog(LOG_DEBUG, "%s = %s", name->data, value->data);
	setenv((char *)name->data, (char *)value->data, 1);
      }
      start_pos = end_pos + 1;
      if (start_pos < len)
        while (src[start_pos] == ' ' && i < len)
          i++, start_pos++;

      end_pos = eq_pos = 0;
    }
  }

  ret = 1;
  bdestroy(name);
  bdestroy(value);
  return ret;
}