Exemple #1
0
/*
 *  convert address into a reverse lookup address
 */
static void
mkptrname(char *ip, char *rip, int rlen)
{
	char buf[128];
	char *p, *np;
	int len;

	if(cistrstr(ip, "in-addr.arpa") || cistrstr(ip, "ip6.arpa")){
		nstrcpy(rip, ip, rlen);
		return;
	}

	nstrcpy(buf, ip, sizeof buf);
	for(p = buf; *p; p++)
		;
	*p = '.';
	np = rip;
	len = 0;
	while(p >= buf){
		len++;
		p--;
		if(*p == '.'){
			memmove(np, p+1, len);
			np += len;
			len = 0;
		}
	}
	memmove(np, p+1, len);
	np += len;
	strcpy(np, "in-addr.arpa");
}
Exemple #2
0
void
write2(int fd, int ofd, char *buf, int n, int nofrom)
{
	char *from, *p;
	int m;

	write(fd, buf, n);

	if(ofd <= 0)
		return;

	if(nofrom == 0){
		write(ofd, buf, n);
		return;
	}

	/* need to escape leading From lines to avoid corrupting 'outgoing' mailbox */
	for(p=buf; *p; p+=m){
		from = cistrstr(p, "from");
		if(from == nil)
			m = n;
		else
			m = from - p;
		if(m > 0)
			write(ofd, p, m);
		if(from){
			if(p==buf || from[-1]=='\n')
				write(ofd, " ", 1);	/* escape with space if From is at start of line */
			write(ofd, from, 4);
			m += 4;
		}
		n -= m;
	}
}
Exemple #3
0
static
int
findctype(char *b, int l, char *keyword, char *s)
{
	char *p, *e;
	int i;

	p = cistrstr(s, keyword);
	if(!p)
		return -1;
	p += strlen(keyword);
	while(*p && isspace(*p))
		p++;
	if(*p != '=')
		return -1;
	p++;
	while(*p && isspace(*p))
		p++;
	if(!*p)
		return -1;
	if(*p == '"'){
		p++;
		e = strchr(p, '"');
		if(!e)
			return -1;
	}else
		for(e = p; *e < 127 && *e > ' ' ; e++)
			;
	i = e-p;
	if(i < 1)
		return -1;
	snprint(b, l, "%.*s", i, p);
	return 0;
}
Exemple #4
0
static int
hasjtag(Usbdev *udev)
{
	/* no string, for now, by default we detect no jtag */
	if(udev->product != nil && cistrstr(udev->product, "jtag") != nil)
		return 1;
	return 0;
}
Exemple #5
0
static int
hasjtag(Usbdev *udev)
{
    /* no string, for now, by default we detect no jtag */
    if(udev->product != nil && cistrstr(udev->product, "jtag") != nil)
        return 1;
    /* blank aijuboard has jtag for initial bringup */
    if(udev->csp == 0xffffff)
        return 1;
    return 0;
}
Exemple #6
0
/*
 * Somewhat of a hack.  Not a full parse, just looks for strings in the beginning
 * of the document (cistrstr only looks at first somewhat bytes).
 */
int
charset(char *s)
{
	char *meta, *emeta, *charset;

	if(defcharset == 0)
		defcharset = ISO_8859_1;
	meta = cistrstr(s, "<meta");
	if(meta == nil)
		return defcharset;
	for(emeta=meta; *emeta!='>' && *emeta!='\0'; emeta++)
		;
	charset = cistrstr(s, "charset=");
	if(charset == nil)
		return defcharset;
	charset += 8;
	if(*charset == '"')
		charset++;
	if(cistrncmp(charset, "utf-8", 5) || cistrncmp(charset, "utf8", 4))
		return UTF_8;
	return defcharset;
}
Exemple #7
0
/*
 *  convert address into a reverse lookup address
 */
static void
mkptrname(char *ip, char *rip, int rlen)
{
    uchar a[IPaddrlen];
    char *p, *e;
    int i;

    if(cistrstr(ip, "in-addr.arpa") || cistrstr(ip, "ip6.arpa") || parseip(a, ip) == -1)
        snprint(rip, rlen, "%s", ip);
    else if(isv4(a))
        snprint(rip, rlen, "%ud.%ud.%ud.%ud.in-addr.arpa",
                a[15], a[14], a[13], a[12]);
    else {
        p = rip;
        e = rip + rlen;
        for(i = 15; i >= 0; i--) {
            p = seprint(p, e, "%ux.", a[i]&0xf);
            p = seprint(p, e, "%ux.", a[i]>>4);
        }
        seprint(p, e, "ip6.arpa");
    }
}
Exemple #8
0
static
int
finddocctype(char *b, int l, char *s)
{
	char *p, *e;

	p = cistrstr(s, "<meta");
	if(!p)
		return -1;
	p += 5;
	e = strchr(s, '>');
	if(!e)
		return -1;
	snprint(b, l, "%.*s", (int)(e-p), p);
	return 0;
}
Exemple #9
0
static
int
findxmltype(char *b, int l, char *s)
{
	char *p, *e;

	p = cistrstr(s, "<?xml ");
	if(!p)
		return -1;

	p += 6;
	e = strstr(p, "?>");
	if(!e)
		return -1;
	snprint(b, l, "%.*s", (int)(e-p), p);

	return 0;
}
Exemple #10
0
int
findctype(char *b, int l, char *keyword, char *s)
{
    char *p, *e, c;
    int i;

    p = cistrstr(s, keyword);
    if(!p)
        return -1;
    p += strlen(keyword);
    while(*p && isspace(*p))
        p++;
    if(*p != '=')
        return -1;
    p++;
    while(*p && isspace(*p))
        p++;
    if(!*p)
        return -1;
    switch (c = *p) {
    case '"':
    case '\'':
        p++;
        e = strchr(p, c);
        if(!e)
            return -1;
        break;
    default:
        for(e = p; *e < 127 && *e > ' ' ; e++)
            ;
    }
    i = e-p;
    if(i < 1)
        return -1;
    snprint(b, l, "%.*s", i, p);
    return 0;
}