Пример #1
0
/**
 * Test that sbuf_add_unum() successfully adds numbers.
 */
static void test_sbuf_add_unum(void)
{
	char nbuf[50];

	sbuf_reset(0);
	sprintf(nbuf, "%lu", ULONG_MAX);
	CU_ASSERT_EQUAL(0, sbuf_add_unum(ULONG_MAX, 0));
	CU_ASSERT_STRING_EQUAL(sbuf, nbuf);
	CU_ASSERT_EQUAL(offset, strlen(nbuf));

	sbuf_reset(0);
	sprintf(nbuf, "%lu", ULONG_MAX >> 1);
	CU_ASSERT_EQUAL(0, sbuf_add_unum(ULONG_MAX >> 1, 0));
	CU_ASSERT_STRING_EQUAL(sbuf, nbuf);
	CU_ASSERT_EQUAL(offset, strlen(nbuf));

	sbuf_reset(0);
	CU_ASSERT_EQUAL(0, sbuf_add_unum(1, 0));
	CU_ASSERT_STRING_EQUAL(sbuf, "1");
	CU_ASSERT_EQUAL(offset, 1);

	sbuf_reset(0);
	CU_ASSERT_EQUAL(0, sbuf_add_unum(0, 0));
	CU_ASSERT_STRING_EQUAL(sbuf, "0");
	CU_ASSERT_EQUAL(offset, 1);
}
Пример #2
0
/**
 * Test that sbuf_add_snum() successfully adds numbers.
 */
static void test_sbuf_add_snum(void)
{
	char nbuf[50];

	sbuf_reset(0);
	sprintf(nbuf, "%ld", LONG_MAX);
	CU_ASSERT_EQUAL(0, sbuf_add_snum(LONG_MAX, 0));
	CU_ASSERT_STRING_EQUAL(sbuf, nbuf);
	CU_ASSERT_EQUAL(offset, strlen(nbuf));

	sbuf_reset(0);
	sprintf(nbuf, "%ld", -LONG_MAX);
	CU_ASSERT_EQUAL(0, sbuf_add_snum(-LONG_MAX, 0));
	CU_ASSERT_STRING_EQUAL(sbuf, nbuf);
	CU_ASSERT_EQUAL(offset, strlen(nbuf));

	sbuf_reset(0);
	CU_ASSERT_EQUAL(0, sbuf_add_snum(-1, 0));
	CU_ASSERT_STRING_EQUAL(sbuf, "-1");
	CU_ASSERT_EQUAL(offset, 2);

	sbuf_reset(0);
	CU_ASSERT_EQUAL(0, sbuf_add_snum(0, 0));
	CU_ASSERT_STRING_EQUAL(sbuf, "0");
	CU_ASSERT_EQUAL(offset, 1);
}
Пример #3
0
/**
 * Test that sbuf_add_snum() returns 1 if there's
 * insufficient space in the buffer for the number.
 */
static void sbuf_add_snum_num_too_long(void)
{
	sbuf_reset(0);
	offset = SBUFSIZ - 3;
	CU_ASSERT_EQUAL(1, sbuf_add_snum(LONG_MAX, 0));

	sbuf_reset(0);
	offset = SBUFSIZ - 3;
	CU_ASSERT_EQUAL(1, sbuf_add_snum(-LONG_MAX, 0));
}
Пример #4
0
/**
 * Test that sbuf_add_param_str() returns 1 if either of its
 * parameters is NULL.
 */
static void sbuf_add_param_str_null_params(void)
{
	sbuf_reset(0);
	CU_ASSERT_EQUAL(1, sbuf_add_param_str(NULL, "test"));
	CU_ASSERT_EQUAL(offset, 0);

	sbuf_reset(0);
	CU_ASSERT_EQUAL(1, sbuf_add_param_str("test", NULL));
	CU_ASSERT_EQUAL(offset, 0);

	sbuf_reset(0);
	CU_ASSERT_EQUAL(1, sbuf_add_param_str(NULL, NULL));
	CU_ASSERT_EQUAL(offset, 0);
}
Пример #5
0
/**
 * Test that sbuf_add_str() only adds a semicolon if s
 * is an empty string, and the requisite format was specified.
 */
static void sbuf_add_str_scolon(void)
{
	sbuf_reset(0);
	CU_ASSERT_EQUAL(0, sbuf_add_str("", SBUF_SCOLON, 0));
	CU_ASSERT_EQUAL(offset, 1);
	CU_ASSERT_STRING_EQUAL(";", sbuf);
}
Пример #6
0
/**
 * Test that sbuf_add_str() only adds a rparen if s
 * is an empty string, and the requisite format was specified.
 */
static void sbuf_add_str_rparen(void)
{
	sbuf_reset(0);
	CU_ASSERT_EQUAL(0, sbuf_add_str("", SBUF_RPAREN, 0));
	CU_ASSERT_EQUAL(offset, 1);
	CU_ASSERT_STRING_EQUAL(")", sbuf);
}
Пример #7
0
/**
 * Test that sbuf_add_str() only adds a comma if s
 * is an empty string, and the requisite format was specified.
 */
static void sbuf_add_str_comma(void)
{
	sbuf_reset(0);
	CU_ASSERT_EQUAL(0, sbuf_add_str("", SBUF_COMMA, 0));
	CU_ASSERT_EQUAL(offset, 1);
	CU_ASSERT_STRING_EQUAL(",", sbuf);
}
Пример #8
0
/**
 * Test that sbuf_add_str() only adds quotes if s
 * is an empty string, and the requisite format was specified.
 */
static void sbuf_add_str_quotes(void)
{
	sbuf_reset(0);
	CU_ASSERT_EQUAL(0, sbuf_add_str("", SBUF_QUOTE, 0));
	CU_ASSERT_EQUAL(offset, 2);
	CU_ASSERT_STRING_EQUAL("''", sbuf);
}
Пример #9
0
/**
 * Test that sbuf_add_str() adds the specified string.
 */
static void sbuf_add_str_adds_string_no_formatting(void)
{
	sbuf_reset(0);
	CU_ASSERT_EQUAL(0, sbuf_add_str("xxx", 0, 0));
	CU_ASSERT_EQUAL(offset, 3);
	CU_ASSERT_STRING_EQUAL(sbuf, "xxx");
}
Пример #10
0
/**
 * Test that sbuf_add_param_num() works as expected.
 */
static void test_sbuf_add_param_num(void)
{
	sbuf_reset(0);
	CU_ASSERT_EQUAL(0, sbuf_add_param_num("test", 100));
	CU_ASSERT_STRING_EQUAL(sbuf, "test=100");
	CU_ASSERT_EQUAL(offset, 8);
}
Пример #11
0
void
pkg_reset(struct pkg *pkg, pkg_t type)
{
	int i;

	if (pkg == NULL)
		return;

	ucl_object_unref(pkg->fields);
	pkg->fields = ucl_object_typed_new(UCL_OBJECT);
	pkg->flags &= ~PKG_LOAD_CATEGORIES;
	pkg->flags &= ~PKG_LOAD_LICENSES;
	pkg->flags &= ~PKG_LOAD_ANNOTATIONS;

	for (i = 0; i < PKG_NUM_SCRIPTS; i++)
		sbuf_reset(pkg->scripts[i]);
	pkg_list_free(pkg, PKG_DEPS);
	pkg_list_free(pkg, PKG_RDEPS);
	pkg_list_free(pkg, PKG_FILES);
	pkg_list_free(pkg, PKG_DIRS);
	pkg_list_free(pkg, PKG_OPTIONS);
	pkg_list_free(pkg, PKG_USERS);
	pkg_list_free(pkg, PKG_GROUPS);
	pkg_list_free(pkg, PKG_SHLIBS_REQUIRED);
	pkg_list_free(pkg, PKG_SHLIBS_PROVIDED);

	pkg->type = type;
}
Пример #12
0
/*
 * Complete data
 */
static int
iptv_http_complete
  ( http_client_t *hc )
{
  iptv_mux_t *im = hc->hc_aux;
  char *url;
  url_t u;
  int r;

  if (im->im_m3u_header) {
    im->im_m3u_header = 0;
    sbuf_append(&im->mm_iptv_buffer, "", 1);
    url = iptv_http_m3u((char *)im->mm_iptv_buffer.sb_data);
    sbuf_reset(&im->mm_iptv_buffer, IPTV_BUF_SIZE);
    if (url == NULL) {
      tvherror("iptv", "m3u contents parsing failed");
      return 0;
    }
    urlinit(&u);
    if (!urlparse(url, &u)) {
      hc->hc_keepalive = 0;
      r = http_client_simple_reconnect(hc, &u);
      if (r < 0)
        tvherror("iptv", "cannot reopen http client: %d'", r);
    } else {
      tvherror("iptv", "m3u url invalid '%s'", url);
    }
    urlreset(&u);
    free(url);
    return 0;
  }
  return 0;
}
Пример #13
0
/**
 * Test that sbuf_add_str() only adds a trailing space if s
 * is an empty string, and the requisite format was specified.
 */
static void sbuf_add_str_tspace(void)
{
	sbuf_reset(0);
	CU_ASSERT_EQUAL(0, sbuf_add_str("", SBUF_TSPACE, 0));
	CU_ASSERT_EQUAL(offset, 1);
	CU_ASSERT_STRING_EQUAL(" ", sbuf);
}
Пример #14
0
/**
 * Test that sbuf_add_str() only adds a equals if s
 * is an empty string, and the requisite format was specified.
 */
static void sbuf_add_str_equals(void)
{
	sbuf_reset(0);
	CU_ASSERT_EQUAL(0, sbuf_add_str("", SBUF_EQUALS, 0));
	CU_ASSERT_EQUAL(offset, 1);
	CU_ASSERT_STRING_EQUAL("=", sbuf);
}
Пример #15
0
/**
 * Test that sbuf_add_param_str() works as expected.
 */
static void test_sbuf_add_param_str(void)
{
	sbuf_reset(0);
	CU_ASSERT_EQUAL(0, sbuf_add_param_str("test", "value"));
	CU_ASSERT_STRING_EQUAL(sbuf, "test='value'");
	CU_ASSERT_EQUAL(offset, 12);
}
Пример #16
0
static void
_end_element(struct type_5_parser_context *ctx, const xmlChar *xn)
{
	error_if(NULL == ctx, error, "Param Error");
	error_if(NULL == xn, error, "Param Error");

	const char *name       = (const char *)xn;
	const char *characters = (const char *)trim(sbuf_ptr(ctx->buffer));

//	trace("name: %s (%d) chars: (%s)", name, ctx->in_valid_package, characters);

	if (0 == strcasecmp("LogicalChannelNumber", name) && ctx->in_valid_package) {
//		trace("LogicalChannelNumber: %s", characters);
		ctx->current_channel->order = (unsigned) atoi(characters);
		list_push(ctx->channels, ctx->current_channel);
		ctx->current_channel = _channel_order_alloc();
	}
	else if (0 == strcasecmp("PackageName", name)) {
		if (NULL != strcasestr(ctx->tvpackages, characters)) {
			ctx->in_valid_package = true;
//			trace("changing valid to true");
		} else {
			ctx->in_valid_package = false;
//			trace("changing valid to false");
		}
	}

error:
	sbuf_reset(ctx->buffer);
	return;
}
Пример #17
0
int
pkg_script_run(struct pkg *pkg, pkg_script_t type)
{
	struct pkg_script *script = NULL;
	pkg_script_t stype;
	struct sbuf *script_cmd = sbuf_new_auto();
	size_t i;

	struct {
		const char *arg;
		const pkg_script_t b;
		const pkg_script_t a;
	} const map[] = {
		/* a implies b with argument arg */
		{"PRE-INSTALL",    PKG_SCRIPT_INSTALL,   PKG_SCRIPT_PRE_INSTALL},
		{"POST-INSTALL",   PKG_SCRIPT_INSTALL,   PKG_SCRIPT_POST_INSTALL},
		{"PRE-UPGRADE",    PKG_SCRIPT_UPGRADE,   PKG_SCRIPT_PRE_UPGRADE},
		{"POST-UPGRADE",   PKG_SCRIPT_UPGRADE,   PKG_SCRIPT_POST_UPGRADE},
		{"DEINSTALL",      PKG_SCRIPT_DEINSTALL, PKG_SCRIPT_PRE_DEINSTALL},
		{"POST-DEINSTALL", PKG_SCRIPT_DEINSTALL, PKG_SCRIPT_POST_DEINSTALL},
	};

	for (i = 0; i < sizeof(map) / sizeof(map[0]); i++) {
		if (map[i].a == type)
			break;
	}

	if (map[i].a != type)
		return (ERROR_BAD_ARG("type"));

	while (pkg_scripts(pkg, &script) == EPKG_OK) {

		stype = pkg_script_type(script);

		if (stype == map[i].a || stype == map[i].b) {
			sbuf_reset(script_cmd);
			sbuf_printf(script_cmd, "PKG_PREFIX=%s\nset -- %s-%s",
				pkg_get(pkg, PKG_PREFIX), pkg_get(pkg, PKG_NAME),
				pkg_get(pkg, PKG_VERSION));

			if (stype == map[i].b) {
				/* add arg **/
				sbuf_cat(script_cmd, " ");
				sbuf_cat(script_cmd, map[i].arg);
			}

			sbuf_cat(script_cmd, "\n");
			sbuf_cat(script_cmd, pkg_script_data(script));
			sbuf_finish(script_cmd);
			system(sbuf_data(script_cmd));

		}
	}

	sbuf_delete(script_cmd);

	return (EPKG_OK);
}
Пример #18
0
/**
 * Test that sbuf_reset() should scrub the whole buffer.
 */
static void sbuf_reset_scrub_all(void)
{
	offset = 0;
	memset(sbuf, 'x', SBUFSIZ);
	sbuf_reset(1);
	CU_ASSERT_EQUAL(sbuf[SBUFSIZ-1], '\0');
	CU_ASSERT_EQUAL(sbuf[SBUFSIZ >> 1], '\0');
	CU_ASSERT_EQUAL(sbuf[0], '\0');
}
Пример #19
0
/**
 * Test that sbuf_add_str() only adds a leading space if s
 * is an empty string, and the requisite format was specified.
 */
static void sbuf_add_str_lspace(void)
{
	sbuf_reset(0);
	sbuf[offset++] = 'x';

	CU_ASSERT_EQUAL(0, sbuf_add_str("", SBUF_LSPACE, 0));
	CU_ASSERT_EQUAL(offset, 2);
	CU_ASSERT_STRING_EQUAL("x ", sbuf);
}
Пример #20
0
/**
 * Test that sbuf_add_str() adds quotes around the specified
 * string, a rparen and then a semicolon afterwards.
 */
static void sbuf_add_str_quote_rparen_and_scolon(void)
{
	unsigned int i = SBUF_QUOTE | SBUF_RPAREN | SBUF_SCOLON;

	sbuf_reset(0);
	CU_ASSERT_EQUAL(0, sbuf_add_str("x", i, 0));
	CU_ASSERT_EQUAL(offset, 5);
	CU_ASSERT_STRING_EQUAL("'x');", sbuf);
}
Пример #21
0
/**
 * Test that sbuf_add_str() adds a lparen and comma with the
 * specified string in-between.
 */
static void sbuf_add_str_lparen_and_comma(void)
{
	int i;

	sbuf_reset(0);
	i = sbuf_add_str("x", SBUF_LPAREN | SBUF_COMMA, 0);
	CU_ASSERT_EQUAL(i, 0);
	CU_ASSERT_EQUAL(offset, 3);
	CU_ASSERT_STRING_EQUAL("(x,", sbuf);
}
Пример #22
0
/**
 * Test that sbuf_add_str() adds quotes around the specified
 * string, and a comma afterwards.
 */
static void sbuf_add_str_quote_and_comma(void)
{
	int i;

	sbuf_reset(0);
	i = sbuf_add_str("x", SBUF_QUOTE | SBUF_COMMA, 0);
	CU_ASSERT_EQUAL(i, 0);
	CU_ASSERT_EQUAL(offset, 4);
	CU_ASSERT_STRING_EQUAL("'x',", sbuf);
}
Пример #23
0
/**
 * Test that sbuf_add_str() returns 1 if the string
 * in s is too long to fit in the buffer.
 */
static void sbuf_add_str_s_too_long(void)
{
	sbuf_reset(0);
	offset = SBUFSIZ - 7;
	CU_ASSERT_EQUAL(1, sbuf_add_str(".", 0, 0));
	CU_ASSERT_EQUAL(offset, SBUFSIZ - 7);

	offset = SBUFSIZ - 6;
	CU_ASSERT_EQUAL(1, sbuf_add_str(".", 0, 0));
	CU_ASSERT_EQUAL(offset, SBUFSIZ - 6);
}
Пример #24
0
/**
 * Test that sbuf_reset() should set offset to 0, and only
 * overwrite the first byte of the buffer with '\0'.
 */
static void sbuf_reset_no_scrub(void)
{
	sbuf[0] = 'x';
	sbuf[1] = 'x';
	offset = 1;

	sbuf_reset(0);
	CU_ASSERT_EQUAL(offset, 0);
	CU_ASSERT_EQUAL(sbuf[0], '\0');
	CU_ASSERT_EQUAL(sbuf[1], 'x');
}
Пример #25
0
/*
 * Complete data
 */
static int
iptv_http_complete
  ( http_client_t *hc )
{
  iptv_mux_t *im = hc->hc_aux;
  char *url, *url2, *s, *p;
  url_t u;
  int r;

  if (im->im_m3u_header) {
    im->im_m3u_header = 0;
    sbuf_append(&im->mm_iptv_buffer, "", 1);
    url = iptv_http_m3u((char *)im->mm_iptv_buffer.sb_data);
    sbuf_reset(&im->mm_iptv_buffer, IPTV_BUF_SIZE);
    if (url == NULL) {
      tvherror("iptv", "m3u contents parsing failed");
      return 0;
    }
    urlinit(&u);
    if (url[0] == '/') {
      s = strdupa(im->mm_iptv_url_raw);
      if ((p = strchr(s, '/')) != NULL)
        *p = '\0';
      if (!urlparse(s, &u))
        goto invalid;
      url2 = malloc(512);
      url2[0] = '\0';
      if ((p = http_arg_get(&hc->hc_args, "Host")) != NULL) {
        snprintf(url2, 512, "%s://%s%s",
                 hc->hc_ssl ? "https" : "http", p, url);
      } else if (im->mm_iptv_url_raw) {
        snprintf(url2, 512, "%s%s", s, url);
      }
      free(url);
      url = url2;
      urlinit(&u);
    }
    if (!urlparse(url, &u)) {
      hc->hc_keepalive = 0;
      r = http_client_simple_reconnect(hc, &u, HTTP_VERSION_1_1);
      if (r < 0)
        tvherror("iptv", "cannot reopen http client: %d'", r);
    } else {
invalid:
      tvherror("iptv", "m3u url invalid '%s'", url);
    }
    urlreset(&u);
    free(url);
    return 0;
  }
  return 0;
}
Пример #26
0
/**
 * Test that sbuf_reset() should scrub the buffer only up until
 * offset.
 */
static void sbuf_reset_scrub_till_offset(void)
{
	sbuf[0] = 'x';
	sbuf[1] = 'x';
	sbuf[2] = 'x';
	offset = 2;

	sbuf_reset(1);
	CU_ASSERT_EQUAL(offset, 0);
	CU_ASSERT_EQUAL(sbuf[0], '\0');
	CU_ASSERT_EQUAL(sbuf[1], '\0');
	CU_ASSERT_EQUAL(sbuf[2], 'x');
}
Пример #27
0
static int
urldecode(const char *src, struct sbuf **dest)
{
	size_t len;
	size_t i;
	char c;
	char hex[] = {'\0', '\0', '\0'};

	if (*dest == NULL)
		*dest = sbuf_new_auto();
	else
		sbuf_reset(*dest);

	len = strlen(src);
	for (i = 0; i < len; i++) {
		if (src[i] != '%') {
			sbuf_putc(*dest, src[i]);
		} else {
			if (i + 2 > len) {
				pkg_emit_error("unexpected end of string");
				return (EPKG_FATAL);
			}

			hex[0] = src[++i];
			hex[1] = src[++i];
			errno = 0;
			c = strtol(hex, NULL, 16);
			if (errno != 0) {
				pkg_emit_errno("strtol()", hex);
				return (EPKG_FATAL);
			}
			sbuf_putc(*dest, c);
		}
	}
	sbuf_finish(*dest);

	return (EPKG_OK);
}
Пример #28
0
/**
 * Test that sbuf_add_str() returns 1 if a NULL
 * argument for s is passed.
 */
static void sbuf_add_str_null_string(void)
{
	sbuf_reset(0);
	CU_ASSERT_EQUAL(1, sbuf_add_str(NULL, 0, 0));
	CU_ASSERT_EQUAL(offset, 0);
}
Пример #29
0
/**
 * Test that sbuf_add_param_num() returns 1 if param is NULL.
 */
static void sbuf_add_param_num_null_param(void)
{
	sbuf_reset(0);
	CU_ASSERT_EQUAL(1, sbuf_add_param_num(NULL, 1));
	CU_ASSERT_EQUAL(offset, 0);
}
Пример #30
0
/**
 * Test that sbuf_add_param_str() with a empty value
 * is basically a no-op.
 */
static void sbuf_add_param_str_empty_value(void)
{
	sbuf_reset(0);
	CU_ASSERT_EQUAL(1, sbuf_add_param_str("test", ""));
	CU_ASSERT_EQUAL(offset, 0);
}