Пример #1
0
static void
set_acl(struct shttpd_ctx *ctx, void *ptr, const char *s)
{
	struct llhead	*head = ptr;
	struct acl	*acl;
	char		flag;
	int		len, a, b, c, d, n, mask;

	ctx = NULL;

	FOR_EACH_WORD_IN_LIST(s, len) {

		mask = 32;

		if (sscanf(s, "%c%d.%d.%d.%d%n",&flag,&a,&b,&c,&d,&n) != 5) {
			elog(E_FATAL, NULL, "[%s]: subnet must be "
			    "[+|-]x.x.x.x[/x]", s);
		} else if (flag != '+' && flag != '-') {
			elog(E_FATAL, NULL, "flag must be + or -: [%s]", s);
		} else if (!isbyte(a)||!isbyte(b)||!isbyte(c)||!isbyte(d)) {
			elog(E_FATAL, NULL, "bad ip address: [%s]", s);
		} else	if ((acl = malloc(sizeof(*acl))) == NULL) {
			elog(E_FATAL, NULL, "%s", "cannot malloc subnet");
		} else if (sscanf(s + n, "/%d", &mask) == 0) {
			/* Do nothing, no mask specified */
		} else if (mask < 0 || mask > 32) {
			elog(E_FATAL, NULL, "bad subnet mask: %d [%s]", n, s);
		}

		acl->ip = (a << 24) | (b << 16) | (c << 8) | d;
		acl->mask = mask ? 0xffffffffU << (32 - mask) : 0;
		acl->flag = flag;
		LL_TAIL(head, &acl->link);
	}
Пример #2
0
int collect_data(struct llhead *plist, const void* data, size_t len) {
   struct data_chunk *chunk;

	if ((chunk = malloc(sizeof(*chunk))) != NULL) {
    if ((chunk->data	= malloc(len)) != NULL) {
      memcpy(chunk->data,data,len);
      chunk->size = len;
		  LL_TAIL(plist, &chunk->link);
      return len;
    }
    free(chunk);
	}
  return -1;
}