/*
 * Important: The below generated source_foo.o and deps_foo.o variable
 * assignments are parsed not only by make, but also by the rather simple
 * parser in scripts/mod/sumversion.c.
 */
static void parse_dep_file(void *map, size_t len)
{
	char *m = map;
	char *end = m + len;
	char *p;
	char s[PATH_MAX];
	int first;

	p = strchr(m, ':');
	if (!p) {
		fprintf(stderr, "fixdep: parse error\n");
		exit(1);
	}
	memcpy(s, m, p-m); s[p-m] = 0;
	m = p+1;

	clear_config();

	first = 1;
	while (m < end) {
		while (m < end && (*m == ' ' || *m == '\\' || *m == '\n'))
			m++;
		p = m;
		while (p < end && *p != ' ') p++;
		if (p == end) {
			do p--; while (!isalnum(*p));
			p++;
		}
		memcpy(s, m, p-m); s[p-m] = 0;
		if (strrcmp(s, "include/generated/autoconf.h") &&
		    strrcmp(s, "arch/um/include/uml-config.h") &&
		    strrcmp(s, "include/linux/kconfig.h") &&
		    strrcmp(s, ".ver")) {
			/*
			 * Do not list the source file as dependency, so that
			 * kbuild is not confused if a .c file is rewritten
			 * into .S or vice versa. Storing it in source_* is
			 * needed for modpost to compute srcversions.
			 */
			if (first) {
				printf("source_%s := %s\n\n", target, s);
				printf("deps_%s := \\\n", target);
			} else
				printf("  %s \\\n", s);
			do_config_file(s);
		}
		first = 0;
		m = p + 1;
	}
	printf("\n%s: $(deps_%s)\n\n", target, target);
	printf("$(deps_%s):\n", target);
}
예제 #2
0
int
mdns_serve(struct mdns_ctx *ctx, mdns_stop_func stop, void *p_cookie)
{
        int r;
        struct mdns_svc *svc;
        struct mdns_hdr qhdr = {0};
        struct rr_entry *question;

        if (setsockopt(ctx->sock, SOL_SOCKET, SO_RCVTIMEO, (const void *) &os_deadline, sizeof(os_deadline)) < 0)
                return (MDNS_NETERR);
        if (setsockopt(ctx->sock, SOL_SOCKET, SO_SNDTIMEO, (const void *) &os_deadline, sizeof(os_deadline)) < 0)
                return (MDNS_NETERR);

        for (; stop(p_cookie) == false;) {
                r = mdns_recv(ctx, &qhdr, &question);
                if (r == MDNS_NETERR)
                        continue;
                if (qhdr.num_qn == 0)
                        goto again;

                for (svc = ctx->services; svc; svc = svc->next) {
                        if (!strrcmp(question->name, svc->name) && question->type == svc->type) {
                                svc->callback(svc->p_cookie, r, question);
                                goto again;
                        }
                }
again:
                mdns_free(question);
        }
        return (0);
}
예제 #3
0
void parse_dep_file(void *map, size_t len)
{
	char *m = map;
	char *end = m + len;
	char *p;
	char s[PATH_MAX];

	p = strchr(m, ':');
	if (!p) {
		fprintf(stderr, "fixdep: parse error\n");
		exit(1);
	}
	memcpy(s, m, p-m); s[p-m] = 0;
	printf("deps_%s := \\\n", target);
	m = p+1;

	clear_config();

	while (m < end) {
		while (m < end && (*m == ' ' || *m == '\\' || *m == '\n'))
			m++;
		p = m;
		while (p < end && *p != ' ') p++;
		if (p == end) {
			do p--; while (!isalnum(*p));
			p++;
		}
		memcpy(s, m, p-m); s[p-m] = 0;
		if (strrcmp(s, "include/linux/autoconf.h") &&
		    strrcmp(s, "arch/um/include/uml-config.h") &&
		    strrcmp(s, ".ver")) {
			printf("  %s \\\n", s);
			do_config_file(s);
		}
		m = p + 1;
	}
	printf("\n%s: $(deps_%s)\n\n", target, target);
	printf("$(deps_%s):\n", target);
}
예제 #4
0
int
mdns_listen(const struct mdns_ctx *ctx, const char *name, enum rr_type type, unsigned int interval,
    mdns_stop_func stop, mdns_callback callback, void *p_cookie)
{
        int r;
        time_t t1, t2;
        struct mdns_hdr hdr = {0};
        struct rr_entry qn = {0};

        hdr.num_qn  = 1;
        qn.name     = (char *)name;
        qn.type     = type;
        qn.rr_class = RR_IN;

        if (setsockopt(ctx->sock, SOL_SOCKET, SO_RCVTIMEO, (const void *) &os_deadline, sizeof(os_deadline)) < 0)
                return (MDNS_NETERR);
        if (setsockopt(ctx->sock, SOL_SOCKET, SO_SNDTIMEO, (const void *) &os_deadline, sizeof(os_deadline)) < 0)
                return (MDNS_NETERR);

        if ((r = mdns_send(ctx, &hdr, &qn)) < 0) // send a first probe request
                callback(p_cookie, r, NULL);
        for (t1 = t2 = time(NULL); stop(p_cookie) == false; t2 = time(NULL)) {
                struct mdns_hdr ahdr = {0};
                struct rr_entry *entries;

                if (difftime(t2, t1) >= (double) interval) {
                        if ((r = mdns_send(ctx, &hdr, &qn)) < 0) {
                                callback(p_cookie, r, NULL);
                                continue;
                        }
                        t1 = t2;
                }
                r = mdns_recv(ctx, &ahdr, &entries);
                if (r == MDNS_NETERR && os_wouldblock())
                        continue;

                if (ahdr.num_ans_rr + ahdr.num_add_rr == 0)
                        continue;

                for (struct rr_entry *entry = entries; entry; entry = entry->next) {
                        if (!strrcmp(entry->name, name)) {
                                callback(p_cookie, r, entries);
                                break;
                        }
                }
                mdns_free(entries);
        }
        return (0);
}
예제 #5
0
int
isKeyWordUpdate(char *token, STATE *state)
{
  int flag = 0;
  int i = 0;

  while (keywords[i].keyword) {
    if (!strrcmp(token, keywords[i].keyword)) {
      token[strlen(token) - strlen(keywords[i].keyword)] = '\0';
      *state = keywords[i].state;
      CScount += keywords[i].CSContribution;
      flag = 1;
      break;
    }
  i++;
  }
  return flag;
}
예제 #6
0
int
strrcasecmp(const char *s, const char *sub)
{
	char	*s_cpy = xstrdup(s);
	char	*sub_cpy = xstrdup(sub);
	char	*p;
	int	 ret;

	for (p = s_cpy; *p != '\0'; p++)
		*p = tolower((int)*p);

	for (p = sub_cpy; *p != '\0'; p++)
		*p = tolower((int)*p);

	ret = strrcmp(s_cpy, sub_cpy);

	xfree(s_cpy);
	xfree(sub_cpy);

	return (ret);
}
예제 #7
0
int
main(int argc, char* argv[])
{
  useconds_t usecs;
  char* command = argv[0];
  char* cusecs = argv[1];

  if (1 == argc) { usage(command); return 1; }

  usecs = atoi(cusecs);

  if (0 == usecs) { usage(command); return 1; }

  if (0 == strrcmp(command, "msleep"))
  {
    usecs *= 1000;
  }

  usleep(usecs);

  return 0;
}
예제 #8
0
int
mdns_listen(const struct mdns_ctx *ctx, const char *const names[],
            unsigned int nb_names, enum rr_type type, unsigned int interval,
            mdns_stop_func stop, mdns_callback callback, void *p_cookie)
{
        int r;
        time_t t1, t2;
        struct mdns_hdr hdr = {0};
        struct rr_entry *qns = malloc(nb_names * sizeof(struct rr_entry));
        if (qns == NULL)
            return (MDNS_STDERR);
        memset(qns, 0, nb_names * sizeof(struct rr_entry));

        hdr.num_qn = nb_names;
        for (unsigned int i = 0; i < nb_names; ++i)
        {
                qns[i].name     = (char *)names[i];
                qns[i].type     = type;
                qns[i].rr_class = RR_IN;
                if (i + 1 < nb_names)
                    qns[i].next = &qns[i+1];
        }

        if (setsockopt(ctx->sock, SOL_SOCKET, SO_RCVTIMEO, (const void *) &os_deadline, sizeof(os_deadline)) < 0)
        {
            free(qns);
            return (MDNS_NETERR);
        }
        if (setsockopt(ctx->sock, SOL_SOCKET, SO_SNDTIMEO, (const void *) &os_deadline, sizeof(os_deadline)) < 0)
        {
            free(qns);
            return (MDNS_NETERR);
        }

        if ((r = mdns_entries_send(ctx, &hdr, qns)) < 0) // send a first probe request
                callback(p_cookie, r, NULL);
        for (t1 = t2 = time(NULL); stop(p_cookie) == false; t2 = time(NULL)) {
                struct mdns_hdr ahdr = {0};
                struct rr_entry *entries;

                if (difftime(t2, t1) >= (double) interval) {
                        if ((r = mdns_entries_send(ctx, &hdr, qns)) < 0) {
                                callback(p_cookie, r, NULL);
                                continue;
                        }
                        t1 = t2;
                }
                r = mdns_recv(ctx, &ahdr, &entries);
                if (r == MDNS_NETERR && os_wouldblock())
                {
                        mdns_free(entries);
                        continue;
                }

                if (ahdr.num_ans_rr + ahdr.num_add_rr == 0)
                {
                        mdns_free(entries);
                        continue;
                }

                for (struct rr_entry *entry = entries; entry; entry = entry->next) {
                        for (unsigned int i = 0; i < nb_names; ++i) {
                                if (!strrcmp(entry->name, names[i])) {
                                        callback(p_cookie, r, entries);
                                        break;
                                }
                        }
                }
                mdns_free(entries);
        }
        free(qns);
        return (0);
}
예제 #9
0
/*
 * Important: The below generated source_foo.o and deps_foo.o variable
 * assignments are parsed not only by make, but also by the rather simple
 * parser in scripts/mod/sumversion.c.
 */
static void parse_dep_file(void *map, size_t len)
{
	char *m = map;
	char *end = m + len;
	char *p;
	char s[PATH_MAX];
	int is_target;
	int saw_any_target = 0;
	int is_first_dep = 0;

	clear_config();

	while (m < end) {
		/* Skip any "white space" */
		while (m < end && (*m == ' ' || *m == '\\' || *m == '\n'))
			m++;
		/* Find next "white space" */
		p = m;
		while (p < end && *p != ' ' && *p != '\\' && *p != '\n')
			p++;
		/* Is the token we found a target name? */
		is_target = (*(p-1) == ':');
		/* Don't write any target names into the dependency file */
		if (is_target) {
			/* The /next/ file is the first dependency */
			is_first_dep = 1;
		} else {
			/* Save this token/filename */
			memcpy(s, m, p-m);
			s[p - m] = 0;

			/* Ignore certain dependencies */
			if (strrcmp(s, "include/generated/autoconf.h") &&
			    strrcmp(s, "arch/um/include/uml-config.h") &&
			    strrcmp(s, "include/linux/kconfig.h") &&
			    strrcmp(s, ".ver")) {
				/*
				 * Do not list the source file as dependency,
				 * so that kbuild is not confused if a .c file
				 * is rewritten into .S or vice versa. Storing
				 * it in source_* is needed for modpost to
				 * compute srcversions.
				 */
				if (is_first_dep) {
					/*
					 * If processing the concatenation of
					 * multiple dependency files, only
					 * process the first target name, which
					 * will be the original source name,
					 * and ignore any other target names,
					 * which will be intermediate temporary
					 * files.
					 */
					if (!saw_any_target) {
						saw_any_target = 1;
						printf("source_%s := %s\n\n",
							target, s);
						printf("deps_%s := \\\n",
							target);
					}
					is_first_dep = 0;
				} else
					printf("  %s \\\n", s);
				do_config_file(s);
			}
		}
		/*
		 * Start searching for next token immediately after the first
		 * "whitespace" character that follows this token.
		 */
		m = p + 1;
	}

	if (!saw_any_target) {
		fprintf(stderr, "fixdep: parse error; no targets found\n");
		exit(1);
	}

	printf("\n%s: $(deps_%s)\n\n", target, target);
	printf("$(deps_%s):\n", target);
}
예제 #10
0
파일: test.c 프로젝트: bmount/canvasback
int main(void)
{
  const char* method;
  size_t method_len;
  const char* path;
  size_t path_len;
  int minor_version;
  struct phr_header headers[4];
  size_t num_headers;
  
  tests(42);
  
#define PARSE(s, last_len, exp, comment)				\
  num_headers = sizeof(headers) / sizeof(headers[0]);			\
  ok(phr_parse_request(s, strlen(s), &method, &method_len, &path,	\
		       &path_len, &minor_version, headers,		\
		       &num_headers, last_len)				\
    == (exp == 0 ? strlen(s) : exp),					\
    comment)
  
  PARSE("GET / HTTP/1.0\r\n\r\n", 0, 0, "simple");
  ok(num_headers == 0, "# of headers");
  ok(strrcmp(method, method_len, "GET"), "method");
  ok(strrcmp(path, path_len, "/"), "path");
  ok(minor_version == 0, "minor version");
  
  PARSE("GET / HTTP/1.0\r\n\r", 0, -2, "partial");
  
  PARSE("GET /hoge HTTP/1.1\r\nHost: example.com\r\nCookie: \r\n\r\n", 0, 0,
	"parse headers");
  ok(num_headers == 2, "# of headers");
  ok(strrcmp(method, method_len, "GET"), "method");
  ok(strrcmp(path, path_len, "/hoge"), "path");
  ok(minor_version == 1, "minor version");
  ok(strrcmp(headers[0].name, headers[0].name_len, "Host"), "host");
  ok(strrcmp(headers[0].value, headers[0].value_len, "example.com"),
     "host value");
  ok(strrcmp(headers[1].name, headers[1].name_len, "Cookie"), "cookie");
  ok(strrcmp(headers[1].value, headers[1].value_len, ""), "cookie value");
  
  PARSE("GET / HTTP/1.0\r\nfoo: \r\nfoo: b\r\n  \tc\r\n\r\n", 0, 0,
	"parse multiline");
  ok(num_headers == 3, "# of headers");
  ok(strrcmp(method, method_len, "GET"), "method");
  ok(strrcmp(path, path_len, "/"), "path");
  ok(minor_version == 0, "minor version");
  ok(strrcmp(headers[0].name, headers[0].name_len, "foo"), "header #1 name");
  ok(strrcmp(headers[0].value, headers[0].value_len, ""), "header #1 value");
  ok(strrcmp(headers[1].name, headers[1].name_len, "foo"), "header #2 name");
  ok(strrcmp(headers[1].value, headers[1].value_len, "b"), "header #2 value");
  ok(headers[2].name == NULL, "header #3");
  ok(strrcmp(headers[2].value, headers[2].value_len, "  \tc"),
     "header #3 value");
  
  PARSE("GET", 0, -2, "incomplete 1");
  ok(method == NULL, "method not ready");
  PARSE("GET ", 0, -2, "incomplete 2");
  ok(strrcmp(method, method_len, "GET"), "method ready");
  PARSE("GET /", 0, -2, "incomplete 3");
  ok(path == NULL, "path not ready");
  PARSE("GET / ", 0, -2, "incomplete 4");
  ok(strrcmp(path, path_len, "/"), "path ready");
  PARSE("GET / H", 0, -2, "incomplete 5");
  PARSE("GET / HTTP/1.", 0, -2, "incomplete 6");
  PARSE("GET / HTTP/1.0", 0, -2, "incomplete 7");
  ok(minor_version == -1, "version not ready");
  PARSE("GET / HTTP/1.0\r", 0, -2, "incomplete 8");
  ok(minor_version == 0, "version is ready");
  
  PARSE("GET /hoge HTTP/1.0\r\n\r", strlen("GET /hoge HTTP/1.0\r\n\r") - 1,
	-2, "slowloris (incomplete)");
  PARSE("GET /hoge HTTP/1.0\r\n\r\n", strlen("GET /hoge HTTP/1.0\r\n\r\n") - 1,
	0, "slowloris (complete)");
  
#undef PARSE
  
  return 0;
}
예제 #11
0
파일: fixdep.c 프로젝트: jnow-87/backup
/* parse the supplied dependency file */
static void parse_dep_file(void *dmap, size_t len){
	char *m = dmap,
		 *end = m + len,
		 *tgt,
		 *prereq;
	int fd;
	unsigned int size;
	unsigned int confh_len = strlen(conf_header);
	char *fmap;


	/* clear hash table */
	hashtbl_clear();

	/* find target */
	while(m < end && (*m == ' ' || *m == '\\' || *m == '\n')) m++;

	tgt = m;

	while(m < end && *m != ':') m++;

	if(m < end)
		*m = 0;

	m++;

	/* print target */
	printf("%s:", tgt);

	/* handle prerequisites */
	while(m < end){
		// find next prerequisites
		while(m < end && (*m == ' ' || *m == '\\' || *m == '\n')) m++;

		prereq = m;

		while(m < end && *m != ' ' && *m != '\n' && *m != '\\') m++;

		// break if prerequisite is actually a target
		if(m > 0 && m[-1] == ':'){
			*m = 0;
			m++;

			printf("\n\n%s", prereq);
			break;
		}

		if(m < end)
			*m = 0;

		if(m >= end || tgt >= end  || prereq >= end)
			break;

		// parse prerequisite that are not the conf_header
		if(strrcmp(prereq, m - prereq, conf_header, confh_len)){
			printf(" \\\n  %s", prereq);

			if(file_map(prereq, &fd, (void*)&fmap, &size) != 0)
				return;

			parse_prereq(fmap, size);
			file_unmap(fd, fmap, size);
		}

		m++;
	}

	/* print the remainder of the dependency file,
	 * i.e. remaining targets */
	printf("\n%s", m);
}