Ejemplo n.º 1
0
int parse_tftp_url(char *url, char **host, char **path, int *port)
{
	char *pos, *end;
	int l = 1;

	if (url == NULL || strncasecmp(url, "tftp://", 7) != 0)
		goto fail;
	pos = url + 7;
	*port = 0;

	end = strchr(pos, ':');
	if (end != NULL)
		 *port = 0x010000;
	else
		end = strchr(pos, '/');
	if (end == NULL) {
		end = pos + strlen(pos);
		l = 0;
	}

	*end = '\0';
	*host = pos;
	if (!isvalhostname(*host))
		 goto fail;
	pos = end + l;

	if (*port) {
		end = strchr(pos, '/');
		if (end == NULL) {
			end = pos + strlen(pos);
			l = 0;
		}
		*end = '\0';
		*port = isport(pos);
		if (*port == 0)
			goto fail;
		pos = end + l;
	} else
		*port = 69;

	*path = pos;
	if (!**path)
		return DEFAULTFILE;
	l = isvalpath(pos);
	if (!l)
		goto fail;
	if (pos[l - 1] == '/')
		return DEFAULTFILE;
	return FULLPATH;

fail:
	*host = NULL;
	*path = NULL;
	*port = 0;
	return -1;
}
Ejemplo n.º 2
0
int islegal(char *data[],int ln){
	int id=0;
	if (strcmp(data[0], "BSRule") != 0){
		printf("规则语句出现语法错误,规则头应为BSRule,在 %d 行\n",ln);
		return 1;
	}
	if (strcmp(data[1], "http") != 0 &&
		strcmp(data[1], "tcp") != 0 &&
		strcmp(data[1], "udp") != 0 &&
		strcmp(data[1], "tcp") != 0){
		printf("规则语句出现语法错误,协议类型错误,在 %d 行\n",ln);
		return 2;
	}
	if (!isip(data[2]) || !isport(data[3])){
		printf("规则语句出现语法错误,第一部分IP或端口数据错误,在 %d 行\n",ln);
		return 3;
	}
	if (strcmp(data[4],"->")!=0 &&
		strcmp(data[4],"<-")!=0 &&
		strcmp(data[4],"<->")!=0 ){
			printf("规则语句出现语法错误,数据流方向符错误,在 %d 行\n",ln);
			return 4;
	}
	if(!isip(data[5]) || !isport(data[6])){
		printf("规则语句出现语法错误,第二部分IP或端口数据错误,在 %d 行\n",ln);
		return 5;
	}
	if(!isid(data[8])){
		printf("规则语句出现语法错误,规则ID号不合法,在 %d 行\n",ln);
		return 8;
	}
	if(!isuniq(id)){
		id = atoi(data[8]);
		printf("规则语句出现语法错误,规则ID号不唯一,在 %d 行\n",ln);
		return 8;
	}
	return 0;
}