• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ regexec函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中regexec函数的典型用法代码示例。如果您正苦于以下问题:C++ regexec函数的具体用法?C++ regexec怎么用?C++ regexec使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了regexec函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: pmaps

static void
pmaps(int pid, print_flags_t pflags, regex_t *regex, int fd_kflags, int fd_kcount)
{
	FILE *maps = NULL;
	int fd_p=-1;
	unsigned long start_addr, end_addr;
	char *line=0;
	size_t line_n=0;
	maps = fopen(proc_fn(pid, "maps"), "r");
	if (!maps) {
		fprintf(stderr,
			"ERROR: could not open /proc/%d/maps: %s\n",
			pid, strerror(errno));
		goto done;
	}
	fd_p = open(proc_fn(pid, "pagemap"), O_RDONLY);
	if (fd_p<0) {
		fprintf(stderr,
			"ERROR: could not open /proc/%d/pagemap: %s\n",
			pid, strerror(errno));
		goto done;
	}
	while (1) {
		int ret = getline(&line, &line_n, maps);
		if (ret == -1) {
			goto done;
		}
		if (pflags & STACK_ONLY) {
			if (strstr(line, "[stack]") == NULL)
				continue;
		} else if (pflags & HEAP_ONLY) {
			if (strstr(line, "[heap]") == NULL)
				continue;
		} else if (regex) {
			if (regexec(regex, line, 0, NULL, 0) != 0)
				continue;
		}
		if (sscanf(line, "%lx-%lx", &start_addr, &end_addr) != 2) {
			(void) fprintf(stderr,
			"ERROR: did not understand line from /proc/pid/maps. :(\n");
			goto done;
		}
		(void) printf("%s", line);
		unsigned long page_start = start_addr / pagesize;
		unsigned long page_end = end_addr / pagesize;
		x_lseek(fd_p, sizeof(uint64_t)*page_start, SEEK_SET);
		unsigned long nr_read = 0;
		unsigned long nr_read_total = 0;
		for (; page_start < page_end; page_start += BSIZE, nr_read_total += nr_read) {
			nr_read = min_ul(page_end-page_start, BSIZE);
			if (read(fd_p, pagemap, nr_read*sizeof(uint64_t))
					!= (ssize_t)(nr_read*sizeof(uint64_t))) {
				// Reading the /proc/pid/pagemap entry for
				// /proc/pid/maps [vsyscall] resulted in zero
				// byte reads. Let's just ignore such cases.
				continue;
			}
			populate(fd_kflags, pageflags, nr_read);
			populate(fd_kcount, pagecount, nr_read);
			for (unsigned i=0; i < nr_read; ++i) {
				if (PMAP_PRESENT&pagemap[i] && !(pflags & SWAPPED_ONLY)) {
					printf("    %#lx -> pfn:%#08llx count:%4llu flags:%s\n",
					       start_addr + (nr_read_total+i)*pagesize,
					       PMAP_PFN&pagemap[i],
					       (unsigned long long)pagecount[i],
					       flags2str(pageflags[i]));
				} else if (PMAP_SWAPPED&pagemap[i] && !(pflags & RESIDENT_ONLY)) {
					printf("   #%#lx -> swaptype:%#llx swapoff:%#08llx\n",
					       start_addr + (nr_read_total+i)*pagesize,
					       PMAP_SWAP_TYPE&pagemap[i],
					       (PMAP_SWAP_OFF&pagemap[i])>>5);
				} else if (!(pflags & (SWAPPED_ONLY|RESIDENT_ONLY))) {
					printf("   !%#lx\n",
					       start_addr + (nr_read_total+i)*pagesize);
				}
			}
		}
开发者ID:rantala,项目名称:pageutil,代码行数:77,代码来源:pmaps.c


示例2: checkCoordinates

int checkCoordinates(struct gpsCoordinates gpsData, struct repeater repeater){

        regex_t regex;
        int reti;



        reti = regcomp(&regex, "^[0-9][0-9][0-9][0-9][.][0-9][0-9][NZ]$", 0);
        if(reti){
                syslog(LOG_NOTICE,"[%s]Hyt GPS decode,could not compile regex latitude",repeater.callsign);
                return 0;
        }
        reti = regexec(&regex,gpsData.latitude,0,NULL,0);
        if(reti == REG_NOMATCH){
                syslog(LOG_NOTICE,"[%s]Corrupt latitude received",repeater.callsign);
                regfree(&regex);
                return 0;
        }
        regfree(&regex);

        reti = regcomp(&regex, "^[0-9][0-9][0-9][0-9][0-9][.][0-9][0-9][EW]$", 0);
        if(reti){
                syslog(LOG_NOTICE,"[%s]Hyt GPS decode,could not compile regex longitude",repeater.callsign);
                regfree(&regex);
                return 0;
        }
        reti = regexec(&regex,gpsData.longitude,0,NULL,0);
        if(reti == REG_NOMATCH){
                syslog(LOG_NOTICE,"[%s]Corrupt longitude received",repeater.callsign);
                regfree(&regex);
                return 0;
        }

        reti = regcomp(&regex, "^[0-9][0-9][0-9]$", 0);
        if(reti){
                syslog(LOG_NOTICE,"[%s]Hyt GPS decode,could not compile regex heading",repeater.callsign);
                regfree(&regex);
                return 0;
        }
        reti = regexec(&regex,gpsData.heading,0,NULL,0);
        if(reti == REG_NOMATCH){
                syslog(LOG_NOTICE,"[%s]Corrupt heading received",repeater.callsign);
                regfree(&regex);
                return 0;
        }

        reti = regcomp(&regex, "^[0-9.][0-9.][0-9.]$", 0);
        if(reti){
                syslog(LOG_NOTICE,"[%s]Hyt GPS decode,could not compile regex speed",repeater.callsign);
                regfree(&regex);
                return 0;
        }
        reti = regexec(&regex,gpsData.speed,0,NULL,0);
        if(reti == REG_NOMATCH){
                syslog(LOG_NOTICE,"[%s]Corrupt speed received",repeater.callsign);
                regfree(&regex);
                return 0;
        }

        regfree(&regex);
	return 1;
} 
开发者ID:kb1isz,项目名称:linDmrMaster,代码行数:62,代码来源:aprs.c


示例3: while

static char *find_matching(char *buf, size_t size, const char *dir,
                           const char *lib)
{
    char           pattern[PATH_MAX], path[PATH_MAX], *p;
    const char    *l;
    int            len, prfx, ok;
    DIR           *dp;
    struct dirent *de;
    regex_t        re;
    regmatch_t     rm;

    if (strchr(lib, '*') == NULL && strchr(lib, '?') == NULL) {
        if ((size_t)snprintf(buf, size, "%s/%s", dir, lib) >= size)
            return NULL;
        if (access(buf, R_OK) == 0)
            return buf;
        else
            return NULL;
    }

    if ((dp = opendir(dir)) == NULL)
        return NULL;

    p    = pattern;
    l    = lib;
    len  = size;
    prfx = -1;
    while (len > 1 && *l) {
        switch (*l) {
        case '?':
        case '*':
            if (len <= 3)
                goto fail;

            if (prfx < 0)
                prfx = (p - pattern);

            *p++ = '.';
            *p++ = *l++;
            len -= 2;
            break;

        case '.':
            if (len <= 3)
                goto fail;

            if (prfx < 0)
                prfx = (p - pattern);

            *p++ = '\\';
            *p++ = *l++;
            len -= 2;
            break;

        default:
            *p++ = *l++;
            len--;
        }
    }

    *p = '\0';

    mrp_debug("regex pattern to match: '%s'", pattern);

    if (regcomp(&re, pattern, REG_NOSUB) != 0)
        goto fail;

    while ((de = readdir(dp)) != NULL) {
        if (de->d_type == DT_REG) {
        check_match:
            if (prfx > 0 && strncmp(de->d_name, pattern, prfx) != 0)
                continue;

            if (regexec(&re, de->d_name, 1, &rm, 0) != 0)
                continue;

            ok = (size_t)snprintf(buf, size, "%s/%s", dir, de->d_name) < size;

            closedir(dp);
            regfree(&re);

            return ok ? buf : NULL;
        }
        else if (de->d_type == DT_LNK) {
            struct stat st;

            snprintf(path, sizeof(path), "%s/%s", dir, de->d_name);

            if (stat(path, &st) == 0 && S_ISREG(st.st_mode))
                goto check_match;
        }
    }

    closedir(dp);
    regfree(&re);

    return NULL;

 fail:
    if (dp != NULL)
//.........这里部分代码省略.........
开发者ID:01org,项目名称:winthorpe,代码行数:101,代码来源:festival-loader.c


示例4: rewrite_stylesheet_urls

char * rewrite_stylesheet_urls(const char *source, unsigned int size,
		int *osize, const char *base,
		struct save_complete_entry *list)
{
	char *res;
	const char *url;
	char *url2;
	char buf[20];
	unsigned int offset = 0;
	int url_len = 0;
	hlcache_handle *content;
	int m;
	unsigned int i;
	unsigned int imports = 0;
	regmatch_t match[11];
	url_func_result result;

	/* count number occurences of @import to (over)estimate result size */
	/* can't use strstr because source is not 0-terminated string */
	for (i = 0; 7 < size && i != size - 7; i++) {
		if (source[i] == '@' &&
				tolower(source[i + 1]) == 'i' &&
				tolower(source[i + 2]) == 'm' &&
				tolower(source[i + 3]) == 'p' &&
				tolower(source[i + 4]) == 'o' &&
				tolower(source[i + 5]) == 'r' &&
				tolower(source[i + 6]) == 't')
			imports++;
	}

	res = malloc(size + imports * 20);
	if (!res)
		return 0;
	*osize = 0;

	while (offset < size) {
		m = regexec(&save_complete_import_re, source + offset,
				11, match, 0);
		if (m)
			break;

		/*for (unsigned int i = 0; i != 11; i++) {
			if (match[i].rm_so == -1)
				continue;
			fprintf(stderr, "%i: '%.*s'\n", i,
					match[i].rm_eo - match[i].rm_so,
					source + offset + match[i].rm_so);
		}*/

		url = 0;
		if (match[2].rm_so != -1) {
			url = source + offset + match[2].rm_so;
			url_len = match[2].rm_eo - match[2].rm_so;
		} else if (match[4].rm_so != -1) {
			url = source + offset + match[4].rm_so;
			url_len = match[4].rm_eo - match[4].rm_so;
		} else if (match[6].rm_so != -1) {
			url = source + offset + match[6].rm_so;
			url_len = match[6].rm_eo - match[6].rm_so;
		} else if (match[8].rm_so != -1) {
			url = source + offset + match[8].rm_so;
			url_len = match[8].rm_eo - match[8].rm_so;
		} else if (match[10].rm_so != -1) {
			url = source + offset + match[10].rm_so;
			url_len = match[10].rm_eo - match[10].rm_so;
		}
		assert(url);

		url2 = strndup(url, url_len);
		if (!url2) {
			free(res);
			return 0;
		}
		result = url_join(url2, base, (char**)&url);
		free(url2);
		if (result == URL_FUNC_NOMEM) {
			free(res);
			return 0;
		}

		/* copy data before match */
		memcpy(res + *osize, source + offset, match[0].rm_so);
		*osize += match[0].rm_so;

		if (result == URL_FUNC_OK) {
			content = save_complete_list_find(url, list);
			if (content) {
				/* replace import */
				snprintf(buf, sizeof buf, "@import '%p'",
						content);
				memcpy(res + *osize, buf, strlen(buf));
				*osize += strlen(buf);
			} else {
				/* copy import */
				memcpy(res + *osize, source + offset + match[0].rm_so,
					match[0].rm_eo - match[0].rm_so);
				*osize += match[0].rm_eo - match[0].rm_so;
			}
		}
		else {
//.........这里部分代码省略.........
开发者ID:MarkieMark,项目名称:netsurf-git-svn,代码行数:101,代码来源:save_complete.c


示例5: pollJoystickEvents

// Polls for and processes events for all present joysticks
//
static void pollJoystickEvents(void)
{
#if defined(__linux__)
    int i;
    struct js_event e;
    ssize_t offset = 0;
    char buffer[16384];

    const ssize_t size = read(_glfw.linux_js.inotify, buffer, sizeof(buffer));

    while (size > offset)
    {
        regmatch_t match;
        const struct inotify_event* e = (struct inotify_event*) (buffer + offset);

        if (regexec(&_glfw.linux_js.regex, e->name, 1, &match, 0) == 0)
        {
            char path[20];
            snprintf(path, sizeof(path), "/dev/input/%s", e->name);
            openJoystickDevice(path);
        }

        offset += sizeof(struct inotify_event) + e->len;
    }

    for (i = 0;  i <= GLFW_JOYSTICK_LAST;  i++)
    {
        if (!_glfw.linux_js.js[i].present)
            continue;

        // Read all queued events (non-blocking)
        for (;;)
        {
            errno = 0;
            if (read(_glfw.linux_js.js[i].fd, &e, sizeof(e)) < 0)
            {
                if (errno == ENODEV)
                {
                    // The joystick was disconnected

                    free(_glfw.linux_js.js[i].axes);
                    free(_glfw.linux_js.js[i].buttons);
                    free(_glfw.linux_js.js[i].name);
                    free(_glfw.linux_js.js[i].path);

                    memset(&_glfw.linux_js.js[i], 0, sizeof(_glfw.linux_js.js[i]));
                }

                break;
            }

            // We don't care if it's an init event or not
            e.type &= ~JS_EVENT_INIT;

            switch (e.type)
            {
                case JS_EVENT_AXIS:
                    _glfw.linux_js.js[i].axes[e.number] =
                        (float) e.value / 32767.0f;
                    break;

                case JS_EVENT_BUTTON:
                    _glfw.linux_js.js[i].buttons[e.number] =
                        e.value ? GLFW_PRESS : GLFW_RELEASE;
                    break;

                default:
                    break;
            }
        }
    }
#endif // __linux__
}
开发者ID:Kkari,项目名称:University-Projects,代码行数:75,代码来源:linux_joystick.c


示例6: update_princ_encryption_1

static int
update_princ_encryption_1(void *cb, krb5_db_entry *ent)
{
    struct update_enc_mkvno *p = cb;
    char *pname = 0;
    krb5_error_code retval;
    int match;
    krb5_timestamp now;
    int result;
    krb5_kvno old_mkvno;

    retval = krb5_unparse_name(util_context, ent->princ, &pname);
    if (retval) {
        com_err(progname, retval,
                _("getting string representation of principal name"));
        goto fail;
    }

    if (krb5_principal_compare(util_context, ent->princ, master_princ)) {
        goto skip;
    }

#ifdef SOLARIS_REGEXPS
    match = (step(pname, p->expbuf) != 0);
#endif
#ifdef POSIX_REGEXPS
    match = (regexec(&p->preg, pname, 0, NULL, 0) == 0);
#endif
#ifdef BSD_REGEXPS
    match = (re_exec(pname) != 0);
#endif
    if (!match) {
        goto skip;
    }
    p->re_match_count++;
    retval = krb5_dbe_get_mkvno(util_context, ent, &old_mkvno);
    if (retval) {
        com_err(progname, retval,
                _("determining master key used for principal '%s'"), pname);
        goto fail;
    }
    /* Line up "skip" and "update" messages for viewing.  */
    if (old_mkvno == new_mkvno) {
        if (p->dry_run && p->verbose)
            printf(_("would skip:   %s\n"), pname);
        else if (p->verbose)
            printf(_("skipping: %s\n"), pname);
        p->already_current++;
        goto skip;
    }
    if (p->dry_run) {
        if (p->verbose)
            printf(_("would update: %s\n"), pname);
        p->updated++;
        goto skip;
    } else if (p->verbose)
        printf(_("updating: %s\n"), pname);
    retval = master_key_convert (util_context, ent);
    if (retval) {
        com_err(progname, retval,
                _("error re-encrypting key for principal '%s'"), pname);
        goto fail;
    }
    if ((retval = krb5_timeofday(util_context, &now))) {
        com_err(progname, retval, _("while getting current time"));
        goto fail;
    }

    if ((retval = krb5_dbe_update_mod_princ_data(util_context, ent,
                                                 now, master_princ))) {
        com_err(progname, retval,
                _("while updating principal '%s' modification time"), pname);
        goto fail;
    }

    ent->mask |= KADM5_KEY_DATA;

    if ((retval = krb5_db_put_principal(util_context, ent))) {
        com_err(progname, retval, _("while updating principal '%s' key data "
                                    "in the database"), pname);
        goto fail;
    }
    p->updated++;
skip:
    result = 0;
    goto egress;
fail:
    exit_status++;
    result = 1;
egress:
    if (pname)
        krb5_free_unparsed_name(util_context, pname);
    return result;
}
开发者ID:mrogers950,项目名称:krb5,代码行数:94,代码来源:kdb5_mkey.c


示例7: SLEN

static char *save_complete_rewrite_stylesheet_urls(save_complete_ctx *ctx,
		const char *source, unsigned long size, const nsurl *base,
		unsigned long *osize)
{
	char *rewritten;
	unsigned long offset = 0;
	unsigned int imports = 0;
	nserror error;

	/* count number occurrences of @import to (over)estimate result size */
	/* can't use strstr because source is not 0-terminated string */
	for (offset = 0; SLEN("@import") < size &&
			offset <= size - SLEN("@import"); offset++) {
		if (source[offset] == '@' &&
				tolower(source[offset + 1]) == 'i' &&
				tolower(source[offset + 2]) == 'm' &&
				tolower(source[offset + 3]) == 'p' &&
				tolower(source[offset + 4]) == 'o' &&
				tolower(source[offset + 5]) == 'r' &&
				tolower(source[offset + 6]) == 't')
			imports++;
	}

	rewritten = malloc(size + imports * 20);
	if (rewritten == NULL)
		return NULL;
	*osize = 0;

	offset = 0;
	while (offset < size) {
		const char *import_url = NULL;
		char *import_url_copy;
		int import_url_len = 0;
		nsurl *url = NULL;
		regmatch_t match[11];
		int m = regexec(&save_complete_import_re, source + offset,
				11, match, 0);
		if (m)
			break;

		if (match[2].rm_so != -1) {
			import_url = source + offset + match[2].rm_so;
			import_url_len = match[2].rm_eo - match[2].rm_so;
		} else if (match[4].rm_so != -1) {
			import_url = source + offset + match[4].rm_so;
			import_url_len = match[4].rm_eo - match[4].rm_so;
		} else if (match[6].rm_so != -1) {
			import_url = source + offset + match[6].rm_so;
			import_url_len = match[6].rm_eo - match[6].rm_so;
		} else if (match[8].rm_so != -1) {
			import_url = source + offset + match[8].rm_so;
			import_url_len = match[8].rm_eo - match[8].rm_so;
		} else if (match[10].rm_so != -1) {
			import_url = source + offset + match[10].rm_so;
			import_url_len = match[10].rm_eo - match[10].rm_so;
		}
		assert(import_url != NULL);

		import_url_copy = strndup(import_url, import_url_len);
		if (import_url_copy == NULL) {
			free(rewritten);
			return NULL;
		}

		error = nsurl_join(base, import_url_copy, &url);
		free(import_url_copy);
		if (error == NSERROR_NOMEM) {
			free(rewritten);
			return NULL;
		}

		/* copy data before match */
		memcpy(rewritten + *osize, source + offset, match[0].rm_so);
		*osize += match[0].rm_so;

		if (url != NULL) {
			hlcache_handle *content;
			content = save_complete_ctx_find_content(ctx, url);
			if (content != NULL) {
				/* replace import */
				char buf[64];
				snprintf(buf, sizeof buf, "@import '%p'",
						content);
				memcpy(rewritten + *osize, buf, strlen(buf));
				*osize += strlen(buf);
			} else {
				/* copy import */
				memcpy(rewritten + *osize,
					source + offset + match[0].rm_so,
					match[0].rm_eo - match[0].rm_so);
				*osize += match[0].rm_eo - match[0].rm_so;
			}
			nsurl_unref(url);
		} else {
			/* copy import */
			memcpy(rewritten + *osize,
				source + offset + match[0].rm_so,
				match[0].rm_eo - match[0].rm_so);
			*osize += match[0].rm_eo - match[0].rm_so;
		}
//.........这里部分代码省略.........
开发者ID:arczi84,项目名称:NetSurf-68k,代码行数:101,代码来源:save_complete.c


示例8: clear_name_png

int clear_name_png(char *name)
{
return !regexec(&write_png, name, 0, NULL, 0);
}
开发者ID:GeraintPratten,项目名称:lalsuite,代码行数:4,代码来源:hookup.c


示例9: sdp_mangle_ip


//.........这里部分代码省略.........
	ret = -1;
	len = strlen (newip);

	/* try to use pre-compiled expressions */
	need_to_deallocate = 0;
	if (ipExpression != NULL)
		{
		re = ipExpression;
#ifdef DEBUG
		fprintf(stdout,"Using PRECOMPILED expression for ip ...\n");
#endif

		}
		else /* we are not using pre-compiled expressions */
			{
			re = pkg_malloc(sizeof(regex_t));
			if (re == NULL)
				{
				LM_ERR("unable to allocate re in pkg mem\n");
				return -7;
				}
			need_to_deallocate = 1;
			if ((regcomp (re, key, REG_EXTENDED)) != 0)
				{
				LM_ERR("unable to compile %s \n",key);
				return -8;
				}
#ifdef DEBUG
		fprintf(stdout,"Using ALLOCATED expression for ip ...\n");
#endif
			}

	diff = 0;
	while ((begin < msg->buf + msg->len) && (regexec (re, begin, 1, &pmatch, 0) == 0))
	{
		off = begin - msg->buf;
		if (pmatch.rm_so == -1)
		{
			LM_ERR("offset unknown\n");
			return -9;
		}

#ifdef STRICT_CHECK
		pmatch.rm_eo --; /* return with one space,\n,\r */
#endif

		/*
                for BSD and Solaris we avoid memrchr
                pos = (char *) memrchr (begin + pmatch.rm_so, ' ',pmatch.rm_eo - pmatch.rm_so);
                */
                pos = begin+pmatch.rm_eo;
                do pos--; while (*pos != ' '); /* we should find ' ' because we matched c=IN IP4 ip */

		pos++;		/* jumping over space */
		oldlen = (pmatch.rm_eo - pmatch.rm_so) - (pos - (begin + pmatch.rm_so));	/* ip length */
		if (oldlen > 15)
		{
			LM_WARN("silent fail because oldlen > 15\n");
#ifdef STRICT_CHECK
			return -10;
#else
			goto continue2;	/* silent fail return -10; invalid ip format ,probably like 1000.3.12341.2 */
#endif


		}
开发者ID:Distrotech,项目名称:opensips,代码行数:67,代码来源:sdp_mangler.c


示例10: rematch

static bool
rematch (const char *re, const char *s)
{
  /*
   * If this system has regular expression capability, then
   * add support for regular expressions in the skip lists.
   */

#if defined(HAVE_REGCOMP)

  int result;
  regmatch_t match;
  regex_t compiled;

  /* compile the regular expression */
  result = regcomp (&compiled, re, REG_EXTENDED | REG_ICASE | REG_NOSUB);
  if (result)
    {
      char errorstring[128];

      regerror (result, &compiled, errorstring, sizeof (errorstring));
      Message ("regexp error: %s\n", errorstring);
      regfree (&compiled);
      return (false);
    }

  result = regexec (&compiled, s, 1, &match, 0);
  regfree (&compiled);

  if (result == 0)
    return (true);
  else
    return (false);

#elif defined(HAVE_RE_COMP)
  int m;
  char *rslt;

  /* compile the regular expression */
  if ((rslt = re_comp (re)) != NULL)
    {
      Message ("re_comp error: %s\n", rslt);
      return (false);
    }

  m = re_exec (s);

  switch m
    {
    case 1:
      return (true);
      break;

    case 0:
      return (false);
      break;

    default:
      Message ("re_exec error\n");
      break;
    }

#else
  return (false);
#endif

}
开发者ID:jpmatsci,项目名称:pcb,代码行数:67,代码来源:vendor.c


示例11: clear_name_dat

int clear_name_dat(char *name)
{
return !regexec(&write_dat, name, 0, NULL, 0);
}
开发者ID:GeraintPratten,项目名称:lalsuite,代码行数:4,代码来源:hookup.c


示例12: radius_compare_vps

/** Compares check and vp by value.
 *
 * Does not call any per-attribute comparison function, but does honour
 * check.operator. Basically does "vp.value check.op check.value".
 *
 * @param request Current request.
 * @param check rvalue, and operator.
 * @param vp lvalue.
 * @return 0 if check and vp are equal, -1 if vp value is less than check value, 1 is vp value is more than check
 *	value, -2 on error.
 */
int radius_compare_vps(REQUEST *request, VALUE_PAIR *check, VALUE_PAIR *vp)
{
	int ret = 0;

	/*
	 *      Check for =* and !* and return appropriately
	 */
	if (check->op == T_OP_CMP_TRUE)  return 0;
	if (check->op == T_OP_CMP_FALSE) return 1;

#ifdef HAVE_REGEX_H
	if (check->op == T_OP_REG_EQ) {
		int compare;
		regex_t reg;
		char value[1024];
		regmatch_t rxmatch[REQUEST_MAX_REGEX + 1];

		vp_prints_value(value, sizeof(value), vp, -1);

		/*
		 *	Include substring matches.
		 */
		compare = regcomp(&reg, check->vp_strvalue, REG_EXTENDED);
		if (compare != 0) {
			char buffer[256];
			regerror(compare, &reg, buffer, sizeof(buffer));

			RDEBUG("Invalid regular expression %s: %s", check->vp_strvalue, buffer);
			return -2;
		}

		memset(&rxmatch, 0, sizeof(rxmatch));	/* regexec does not seem to initialise unused elements */
		compare = regexec(&reg, value, REQUEST_MAX_REGEX + 1, rxmatch, 0);
		regfree(&reg);
		rad_regcapture(request, compare, value, rxmatch);

		ret = (compare == 0) ? 0 : -1;
		goto finish;
	}

	if (check->op == T_OP_REG_NE) {
		int compare;
		regex_t reg;
		char value[1024];
		regmatch_t rxmatch[REQUEST_MAX_REGEX + 1];

		vp_prints_value(value, sizeof(value), vp, -1);

		/*
		 *	Include substring matches.
		 */
		compare = regcomp(&reg, check->vp_strvalue, REG_EXTENDED);
		if (compare != 0) {
			char buffer[256];
			regerror(compare, &reg, buffer, sizeof(buffer));

			RDEBUG("Invalid regular expression %s: %s", check->vp_strvalue, buffer);
			return -2;
		}
		compare = regexec(&reg, value,  REQUEST_MAX_REGEX + 1, rxmatch, 0);
		regfree(&reg);

		ret = (compare != 0) ? 0 : -1;
	}
#endif

	/*
	 *	Attributes must be of the same type.
	 *
	 *	FIXME: deal with type mismatch properly if one side contain
	 *	ABINARY, OCTETS or STRING by converting the other side to
	 *	a string
	 *
	 */
	if (vp->da->type != check->da->type) return -1;

	/*
	 *	Tagged attributes are equal if and only if both the
	 *	tag AND value match.
	 */
	if (check->da->flags.has_tag && !TAG_EQ(check->tag, vp->tag)) {
		ret = ((int) vp->tag) - ((int) check->tag);
		if (ret != 0) goto finish;
	}

	/*
	 *	Not a regular expression, compare the types.
	 */
	switch(check->da->type) {
//.........这里部分代码省略.........
开发者ID:pawelbien,项目名称:freeradius-server,代码行数:101,代码来源:valuepair.c


示例13: eglob

int eglob(const char *pattern,
          int flags,
          int (*errfunc) (const char *epath, int eerrno),
          glob_t *pglob)
{
    int status = 0;

    /* Detect '**'. */
    regex_t ss_regex;
    size_t nmatch = 2;
    regmatch_t pmatch[nmatch];

    size_t start = 0;
    size_t end = 0;
    int ss_present = 0;

    status = regcomp(&ss_regex, "[^\\](/[*][*])|^(/[*][*])|^([*][*])", REG_EXTENDED);
    if (status != 0) {
        // fprintf(stderr, "[ERROR] Failed to compile regex.\n");
        regfree(&ss_regex);
        return -1;
    }

    status = regexec(&ss_regex, pattern, nmatch, pmatch, 0);
    if (status != REG_NOMATCH) {
        if (pmatch[1].rm_so != -1) {
            start = pmatch[1].rm_so;
            end = pmatch[1].rm_eo;
        }
        else {
            start = pmatch[0].rm_so;
            end = pmatch[0].rm_eo;
        }

        ss_present = 1;

        // fprintf(stderr, "Start: %zu End: %zu\n", start, end);

        status = regexec(&ss_regex, &pattern[end], nmatch, pmatch, 0);
        if (status != REG_NOMATCH) {
            regfree(&ss_regex);

            /* More than one '**' is NOT permitted. */
            // fprintf(stderr, "[ERROR] Only one '**' per glob is permitted:\n");
            // fprintf(stderr, "[ERROR] %s\n", pattern);
            // fprintf(stderr, "[ERROR] ");
            // for (size_t i = 0; i < (end + pmatch[0].rm_so + 1); i++) {
            //     fprintf(stderr, "-");
            // }
            // fprintf(stderr, "^\n");

            return -2;
        }

    }
    regfree(&ss_regex);

    /* No '**', fallback to normal glob. */
    if (ss_present == 0) {
        return glob(pattern, flags, errfunc, pglob);
    }

    // fprintf(stderr, "Found '**'...\n");

    /* Split glob into pre and post '**'. */
    const size_t pattern_size = strlen(pattern);

    int pre_mashup = 0;
    size_t pre_size = start + 1;
    if (pre_size == 1) {
        pre_size++;
        pre_mashup = 1;
    }

    char pre[pre_size];
    if (pre_mashup == 0) {
        memcpy(pre, pattern, sizeof(pre) - 1);
    }
    else {
        pre[0] = '.';
    }
    pre[sizeof(pre) - 1] = '\0';

    char post[pattern_size - end + 1];
    memcpy(post, pattern + end, sizeof(post) - 1);
    post[sizeof(post) - 1] = '\0';

    /* Glob the prefix path. */
    glob_t prefix_glob = {0, NULL, 0};
    status = glob(pre[0] == '\0' ? "." : pre, flags, errfunc, &prefix_glob);
    if (status != 0) {
        // fprintf(stderr, "[ERROR] Prefix glob failed: %s\n", pre);
        return -1;
    }

    // fprintf(stderr, "Walking %zu paths...\n", prefix_glob.gl_pathc - prefix_glob.gl_offs);

    /* Walk the paths found for prefix to compute longest path. */
    for (size_t i = prefix_glob.gl_offs; i < prefix_glob.gl_pathc; i++) {
        // fprintf(stderr, "Walking[%zu]: %s\n", i, prefix_glob.gl_pathv[i]);
//.........这里部分代码省略.........
开发者ID:calebcase,项目名称:eglob,代码行数:101,代码来源:eglob.c


示例14: match_one_pattern

static int match_one_pattern(struct grep_opt *opt, struct grep_pat *p, char *bol, char *eol, enum grep_context ctx)
{
	int hit = 0;
	int at_true_bol = 1;
	int saved_ch = 0;
	regmatch_t pmatch[10];

	if ((p->token != GREP_PATTERN) &&
	    ((p->token == GREP_PATTERN_HEAD) != (ctx == GREP_CONTEXT_HEAD)))
		return 0;

	if (p->token == GREP_PATTERN_HEAD) {
		const char *field;
		size_t len;
		assert(p->field < ARRAY_SIZE(header_field));
		field = header_field[p->field].field;
		len = header_field[p->field].len;
		if (strncmp(bol, field, len))
			return 0;
		bol += len;
		saved_ch = strip_timestamp(bol, &eol);
	}

 again:
	if (!opt->fixed) {
		regex_t *exp = &p->regexp;
		hit = !regexec(exp, bol, ARRAY_SIZE(pmatch),
			       pmatch, 0);
	}
	else {
		hit = !fixmatch(p->pattern, bol, pmatch);
	}

	if (hit && opt->word_regexp) {
		if ((pmatch[0].rm_so < 0) ||
		    (eol - bol) <= pmatch[0].rm_so ||
		    (pmatch[0].rm_eo < 0) ||
		    (eol - bol) < pmatch[0].rm_eo)
			die("regexp returned nonsense");

		/* Match beginning must be either beginning of the
		 * line, or at word boundary (i.e. the last char must
		 * not be a word char).  Similarly, match end must be
		 * either end of the line, or at word boundary
		 * (i.e. the next char must not be a word char).
		 */
		if ( ((pmatch[0].rm_so == 0 && at_true_bol) ||
		      !word_char(bol[pmatch[0].rm_so-1])) &&
		     ((pmatch[0].rm_eo == (eol-bol)) ||
		      !word_char(bol[pmatch[0].rm_eo])) )
			;
		else
			hit = 0;

		if (!hit && pmatch[0].rm_so + bol + 1 < eol) {
			/* There could be more than one match on the
			 * line, and the first match might not be
			 * strict word match.  But later ones could be!
			 */
			bol = pmatch[0].rm_so + bol + 1;
			at_true_bol = 0;
			goto again;
		}
	}
	if (p->token == GREP_PATTERN_HEAD && saved_ch)
		*eol = saved_ch;
	return hit;
}
开发者ID:Inkdit,项目名称:git,代码行数:68,代码来源:grep.c


示例15: Pass1


//.........这里部分代码省略.........
                if (name[0] == '/') {
                    Fatal("Absolute paths are illegal.");
                    return Exit_Mess;
                }
                q = name;
                for (;;) {
                    if (q[0] == '.' && q[1] == '.')
                        if (q[2] == '/' || q[2] == '\0') {
                            Fatal("Paths containing '..' are illegal.");
                            return Exit_Mess;
                        }
                    if ((q = strchr(q, '/')) == NULL)
                        break;
                    q++;
                }

                /* if we have been asked to `keep' files then skip
                   removes; i.e. we don't match these entries at
                   all. */
                if (KeepIt &&
                        (!strcmp(sp->Key,"DR") || !strcmp(sp->Key,"FR"))) {
                    match = CTM_FILTER_DISABLE;
                    break;
                }

                /* If filter expression have been defined, match the
                   path name against the expression list.  */

                if (FilterList) {
                    struct CTM_Filter *filter;

                    for (filter = FilterList; filter;
                            filter = filter->Next) {
                        if (0 == regexec(&filter->CompiledRegex, name,
                                         0, 0, 0))
                            /* if the name matches, adopt the
                               action */
                            match = filter->Action;
                    }
                }

                /* Add up the total number of matches */
                total_matches += match;
                break;
            case CTM_F_Uid:
                GETFIELD(p,sep);
                while(*p) {
                    if(!isdigit(*p)) {
                        Fatal("Non-digit in uid.");
                        return 32;
                    }
                    p++;
                }
                break;
            case CTM_F_Gid:
                GETFIELD(p,sep);
                while(*p) {
                    if(!isdigit(*p)) {
                        Fatal("Non-digit in gid.");
                        return 32;
                    }
                    p++;
                }
                break;
            case CTM_F_Mode:
                GETFIELD(p,sep);
开发者ID:edgar-pek,项目名称:PerspicuOS,代码行数:67,代码来源:ctm_pass1.c


示例16: sdp_mangle_port

int
sdp_mangle_port (struct sip_msg *msg, char *offset, char *unused)
{
	int old_content_length, new_content_length, oldlen, err, oldPort, newPort,
		diff, offsetValue,len,off,ret,need_to_deallocate;
	struct lump *l;
	regmatch_t pmatch;
	regex_t *re;
	char *s, *pos,*begin,*key;
	char buf[6];
	str body;


	key = PORT_REGEX;
	/*
	 * Checking if msg has a payload
	 */
	if (msg == NULL)
	{
		LM_ERR("received NULL msg\n");
		return -1;
	}

	if ( get_body(msg,&body)!=0 || body.len==0)
	{
		LM_ERR(" failed to get a body \n");
		return -2;
	}

	old_content_length = get_content_length(msg);

	if (offset == NULL)
		return -14;
	if (sscanf (offset, "%d", &offsetValue) != 1)
	{
		LM_ERR("invalid value for offset \n");
		return -13;
	}

	//offsetValue = (int)offset;
#ifdef DEBUG
	fprintf (stdout,"---START--------MANGLE PORT-----------------\n");
	fprintf(stdout,"===============OFFSET = %d\n",offsetValue);
#endif

	if ((offsetValue < MIN_OFFSET_VALUE) || (offsetValue > MAX_OFFSET_VALUE))
	{
		LM_ERR("invalid value %d for offset \n",offsetValue);
		return -3;
	}

	begin = body.s;
	ret = -1;

	/* try to use pre-compiled expressions */
	need_to_deallocate = 0;
	if (portExpression != NULL)
		{
		re = portExpression;
#ifdef DEBUG
		fprintf(stdout,"Using PRECOMPILED expression for port ...\n");
#endif
		}
		else /* we are not using pre-compiled expressions */
			{
			re = pkg_malloc(sizeof(regex_t));
			if (re == NULL)
				{
				LM_ERR("unable to allocate re\n");
				return -4;
				}
			need_to_deallocate = 1;
			if ((regcomp (re, key, REG_EXTENDED)) != 0)
				{
				LM_ERR("unable to compile %s \n",key);
				return -5;
				}
#ifdef DEBUG
		fprintf(stdout,"Using ALLOCATED expression for port ...\n");
#endif

			}

	diff = 0;
	while ((begin < msg->buf + msg->len) && (regexec (re, begin, 1, &pmatch, 0) == 0))
	{
		off = begin - msg->buf;
		if (pmatch.rm_so == -1)
		{
			LM_ERR("offset unknown\n");
			return -6;
		}

#ifdef STRICT_CHECK
		pmatch.rm_eo --; /* return with one space */
#endif

		/*
                for BSD and Solaris we avoid memrchr
                pos = (char *) memrchr (begin + pmatch.rm_so, ' ',pmatch.rm_eo - pmatch.rm_so);
//.........这里部分代码省略.........
开发者ID:Distrotech,项目名称:opensips,代码行数:101,代码来源:sdp_mangler.c


示例17: get_log_entries

/** @brief Read's a defined log file and stores the entries into entry list struct
 *  @param [in] log_file the full path of the log file to read
 *  @param [in] search_string a string you are searching for.
 *		Set to NULL to disable search function
 *  @param [in] reverse this bool defines which order the log entries should return
 *  @param [in] ts_start defines the start timestamp for log entries
 *	@arg >=0 means unix timestamp
 *	@arg -1 deactivated
 *  @param [in] ts_end defines the end timestamp for log entries
 *	@arg >=0 means unix timestamp
 *	@arg -1 deactivated
 *  @return
 *	@retval READLOG_OK
 *	@retval READLOG_ERROR
 *	@retval READLOG_ERROR_MEMORY
 *	@retval READLOG_ERROR_NOFILE
 *	@retval READLOG_ERROR_FILTER
 *  @author Ricardo Bartels
 *
 *  This functions reads a  \c log_file and and try's (if set) to filter for a search string.
 *  This search string uses regular expressions. The reverse option defines if you want
 *  have your log entries returned in normal or revers order. Normal order for returning
 *  would be from the newest entry to the oldest. You can also set a time "window". This
 *  defines if you want to exclude entries which are outside of these "window". Then only
 *  entries will be returned which are between start and end. Very useful if user has all
 *  entries in one log file.
**/
int get_log_entries(char *log_file, char *search_string, int reverse, time_t ts_start, time_t ts_end) {
	char *input = NULL;
	char *temp_buffer = NULL;
	char *search_regex = NULL;
	int type = 0;
	int regex_i = 0, i = 0, len = 0;
	short keep_entry = TRUE;
	time_t timestamp;
	mmapfile *thefile = NULL;
	logentry *temp_entry = NULL;
	regex_t preg;
	logfilter *temp_filter;

	if ((thefile = mmap_fopen(log_file)) != NULL) {

		if (search_string != NULL) {
			/* allocate for 3 extra chars, ^, $ and \0 */
			search_regex = malloc(sizeof(char) * (strlen(search_string) * 2 + 3));
			len = strlen(search_string);
			for (i = 0; i < len; i++, regex_i++) {
				if (search_string[i] == '*') {
					search_regex[regex_i++] = '.';
					search_regex[regex_i] = '*';
				} else
					search_regex[regex_i] = search_string[i];
			}
			//search_regex[0]='^';
			//search_regex[regex_i++]='$';

			search_regex[regex_i] = '\0';

			/* check and compile regex */
			if (regcomp(&preg, search_regex, REG_ICASE | REG_NOSUB) != 0) {
				regfree(&preg);
				mmap_fclose(thefile);
				return READLOG_ERROR_FILTER;
			}
		}

		while (1) {

			/* free memory */
			my_free(input);

			if ((input = mmap_fgets(thefile)) == NULL)
				break;

			strip(input);

			if ((int)strlen(input) == 0)
				continue;

			/* get timestamp */
			temp_buffer = strtok(input, "]");
			timestamp = (temp_buffer == NULL) ? 0L : strtoul(temp_buffer + 1, NULL, 10);

			/* skip line if out of time range */
			if ((ts_start >= 0 && timestamp < ts_start) || (ts_end >= 0 && timestamp > ts_end))
				continue;

			/* get log entry text */
			temp_buffer = strtok(NULL, "\n");

			if (search_string != NULL) {
				if (regexec(&preg, temp_buffer, 0, NULL, 0) == REG_NOMATCH)
					continue;
			}


			if (strstr(temp_buffer, " starting..."))
				type = LOGENTRY_STARTUP;
			else if (strstr(temp_buffer, " shutting down..."))
				type = LOGENTRY_SHUTDOWN;
//.........这里部分代码省略.........
开发者ID:formorer,项目名称:icinga-core,代码行数:101,代码来源:readlogs.c


示例18: irc_ignore_check

int
irc_ignore_check (struct t_irc_server *server, const char *channel,
                  const char *nick, const char *host)
{
    struct t_irc_ignore *ptr_ignore;
    int server_match, channel_match;
    char *pos;

    if (!server)
        return 0;

    /*
     * if nick is the same as server, then we will not ignore
     * (it is possible when connected to an irc proxy)
     */
    if (nick && server->nick
        && (irc_server_strcasecmp (server, server->nick, nick) == 0))
    {
        return 0;
    }

    for (ptr_ignore = irc_ignore_list; ptr_ignore;
         ptr_ignore = ptr_ignore->next_ignore)
    {
        if (strcmp (ptr_ignore->server, "*") == 0)
            server_match = 1;
        else
            server_match = (weechat_strcasecmp (ptr_ignore->server,
                                                server->name) == 0);

        channel_match = 0;
        if (!channel || (strcmp (ptr_ignore->channel, "*") == 0))
            channel_match = 1;
        else
        {
            if (irc_channel_is_channel (server, channel))
            {
                channel_match = (weechat_strcasecmp (ptr_ignore->channel,
                                                     channel) == 0);
            }
            else if (nick)
            {
                channel_match = (weechat_strcasecmp (ptr_ignore->channel,
                                                     nick) == 0);
            }
        }

        if (server_match && channel_match)
        {
            if (nick && (regexec (ptr_ignore->regex_mask, nick, 0, NULL, 0) == 0))
                return 1;
            if (host)
            {
                if (regexec (ptr_ignore->regex_mask, host, 0 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ regfree函数代码示例发布时间:2022-05-30
下一篇:
C++ regex_match函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap