Exemple #1
0
void check(char *str, char *ptr[], int size)
{
	int t, i, d;
	if (scspn(str, size) > 0) {
		printf("Is SCP: no\n");
		return;
	}
	for(i = 0; (str[i] != '\0'); i++)
		if(str[i] == ':')
			d++;
	if (d == 1)
		printf("Is SCP: yes\n");
	else { 
		printf("Is SCP: no\n");
		return;
	}
	int j = stok(str, ':', ptr, size);
	for(i = 0; (str[i] != '\0'); i++)
		if(str[i] == '.')
			t++;
	if (t == 3) {
		for(i = 0; i < str[i] != '\0'; i++) 
			if((str[i] >= '0' && str[i] <= '9') || (str[i] == '.')) 
				t = 3;
			else {
				t = 4;
				break;
			}
	}
	char *ptr2[228];
	int k = stok(str, '.', ptr2, size);
	isIp(ptr2, size, t);
	suntok(str, '.', ptr2, k);
	suntok(str, ':', ptr, j);
	process(str, size);
	output(str);
}
Exemple #2
0
int check(char *s)
{
    char d_ru[] = "ru";
    char d_com[] = "com";
    char d_org[] = "org";
    char err_sym[] = {':', '*', '?', '<', ' ', '>', '|', '"', '\\', '@', ',', ';', '#', '$', '%', '^', '&', '(', ')', '\0'};
    char IP_num[]="0123456789";
    char prot_h[] = "http:";
    char prot_s[] = "smb:";
    char prot_f[] = "ftp:";
    char prot_r[] = "rsync:";
    char *slash_ptr[50];
    char *dot_ptr[10];
    int count_slash, count_dot, ERROR;
    int i;

    /* Length of string */
    if (slen(s) == 0) {
        printf("\tInsufficient length(0)\n");
        return ERROR = ERROR_LENGTH;
    }

    /* The less length of string is 10 */
    if (slen(s) < 10) {
        printf("\tToo short string / not enough information about path\n");
        return ERROR = ERROR_LENGTH;
    }

    /* Length of string >= 261 */
    if (slen(s) >= string_size) {
        printf("\tNot correct lenght string(>= 261)\n");
        return ERROR = ERROR_LENGTH;
    }

    count_slash = stok(s, '/', slash_ptr); // Counting number of slashes and stok it
    /* slashes verification */
    if ((count_slash >= 3) && (*slash_ptr[1] == '\0') && (*slash_ptr[2] != '\0') && (*slash_ptr[0] != '\0')) {
        ERROR = NO_ERROR;
    } else {
        printf("\tIncorrectly placed slashes\n");
        suntok(s, '/', slash_ptr, count_slash);
        return ERROR = ERROR_SLASHES;
    }

    /* protocol verification and counting number of dots */
    if ((sequal(*slash_ptr, prot_h) == 1) || (sequal(*slash_ptr, prot_s) == 1) ||
        (sequal(*slash_ptr, prot_f) == 1) || (sequal(*slash_ptr, prot_r) == 1)){
            count_dot = stok(*(slash_ptr + 2), '.', dot_ptr); // Counting number of dots
    } else {
        printf("\tProtocol is false %s\n", *slash_ptr);
        suntok(s, '/', slash_ptr, count_slash);
        return ERROR = ERROR_PROTOCOL;
    }

    /* If it's domain */
    if (count_dot == 2) {
        if (slen(*(dot_ptr)) == 0) {
            printf("\tLength of addres before the first dot == NULL\n");
            suntok(*(slash_ptr + 2), '.', dot_ptr, count_dot);
            suntok(s, '/', slash_ptr, count_slash);
            return ERROR = ERROR_LENGTH;
        }

        if (scspn(*(dot_ptr), err_sym) == -1) {// check on err_sym (*address*)
            if (scspn(*(dot_ptr + 1), err_sym) >= 0) { //check on err_sym (*.ru)
                printf("\tFounded invalid symbols in the top domain\n");
                suntok(*(slash_ptr + 2), '.', dot_ptr, count_dot);
                suntok(s, '/', slash_ptr, count_slash);
                return ERROR = ERROR_INV_SYMB;
            }

            if ((sequal(*(dot_ptr + 1), d_com) == 1) || (sequal(*(dot_ptr + 1), d_org) == 1) ||
                (sequal(*(dot_ptr + 1), d_ru) == 1)) { // the top domain verification
                    /* check directory */
                    for (i = 3; i < count_slash; i++) {
                        if ((*slash_ptr[i] == '\0') && ((i + 1) < count_slash)) {
                            printf("\tIncorrect length of directory\n");
                            suntok(*(slash_ptr + 2), '.', dot_ptr, count_dot);
                            suntok(s, '/', slash_ptr, count_slash);
                            return ERROR = ERROR_LENGTH_LL;
                        }

                        if (scspn(slash_ptr[i], err_sym) >= 0) {
                            printf("\tFounded invalid symbols in directory\n");
                            suntok(*(slash_ptr + 2), '.', dot_ptr, count_dot);
                            suntok(s, '/', slash_ptr, count_slash);
                            return ERROR = ERROR_INV_SYMB;
                        }
                    }
                    suntok(*(slash_ptr + 2), '.', dot_ptr, count_dot);
                    suntok(s, '/', slash_ptr, count_slash);
                    return ERROR = NO_ERROR;
            } else {
                printf("\tThe top domain is false");
                suntok(*(slash_ptr + 2), '.', dot_ptr, count_dot);
                suntok(s, '/', slash_ptr, count_slash);
                return ERROR = ERROR_DOMAIN;
            }
        } else {
            printf("\tNot correct domain, founded invalid symbols\n");
            suntok(*(slash_ptr + 2), '.', dot_ptr, count_dot);
            suntok(s, '/', slash_ptr, count_slash);
            return ERROR = ERROR_INV_SYMB;
        }
    } else if (count_dot == 4) {// If it's IP address
        for (i = 0; i < count_dot; i++) {
            if (slen(*(dot_ptr + i)) == 0) {
                printf("\tIncorrect length of the ip\n");
                suntok(*(slash_ptr + 2), '.', dot_ptr, count_dot);
                suntok(s, '/', slash_ptr, count_slash);
                return ERROR = ERROR_LENGTH_IP;
            }

            if (scspn(*(dot_ptr + i), err_sym) >= 0) {
                printf("not correct IP, founded invalid symbols\n");
                suntok(*(slash_ptr + 2), '.', dot_ptr, count_dot);
                suntok(s, '/', slash_ptr, count_slash);
                return ERROR = ERROR_INV_SYMB;
            }

            if (sspn(*(dot_ptr + i), IP_num) == -1 ){
                printf("not correct IP, founded invalid symbols for IP(not numeral)\n");
                suntok(*(slash_ptr + 2), '.', dot_ptr, count_dot);
                suntok(s, '/', slash_ptr, count_slash);
                return ERROR = ERROR_INV_SYMB;
            }

            if ((atoi_str(*(dot_ptr + i)) > 255) || (atoi_str(*(dot_ptr + i)) < 0)) {
                printf("Not correct IP(> 255 or < 0)\n");
                suntok(*(slash_ptr + 2), '.', dot_ptr, count_dot);
                suntok(s, '/', slash_ptr, count_slash);
                return ERROR = ERROR_RANGE_IP;
            }
        }
        /* check directory */
        for (i = 3; i < count_slash; i++) {
            if ((*slash_ptr[i] == '\0') && ((i + 1) < count_slash)) {
                printf("\tIncorrect length of directory\n");
                suntok(*(slash_ptr + 2), '.', dot_ptr, count_dot);
                suntok(s, '/', slash_ptr, count_slash);
                return ERROR = ERROR_LENGTH_LL;
            }

            if (scspn(slash_ptr[i], err_sym) >= 0) {
                printf("\tFounded invalid symbols in directory\n");
                suntok(*(slash_ptr + 2), '.', dot_ptr, count_dot);
                suntok(s, '/', slash_ptr, count_slash);
                return ERROR = ERROR_INV_SYMB;
            }
            }
        suntok(*(slash_ptr + 2), '.', dot_ptr, count_dot);
        suntok(s, '/', slash_ptr, count_slash);
        return ERROR = NO_ERROR;
    } else {
        printf("\tNot correct domain \\ IP (dots)\n");
        suntok(*(slash_ptr + 2), '.', dot_ptr, count_dot);
        suntok(s, '/', slash_ptr, count_slash);
        return ERROR = ERROR_DOTS;
    }
}