int isdomain(char *str) { char d_ru[] = "ru"; char d_com[] = "com"; char d_org[] = "org"; char *EL[MAXSIZE]; int i; if (6 > slen(str)) return 0; int Z = stok(str, '.', EL); if (!((scmp(EL[Z - 1], d_ru) == 0) || (scmp(EL[Z - 1], d_com) == 0) || (scmp(EL[Z - 1], d_org) == 0))) { suntok(str, '.', EL, Z); return 0; } suntok(str, '.', EL, Z); if (3 != Z) return 0; for (i = 0; str[i] != '\0'; i++) { if (!((str[i] >= 'A')&&(str[i] <= 'Z') || ( (str[i] >= 'a')&&(str[i] <= 'z')) || str[i] == '.' )) return 0; } return 1; }
int Researcher(char *Str) { int isipv4(char *str) { char *EL[MAXSIZE]; int i, j; if ((7 > slen(str)) || (15 < slen(str))) return 0; int Z = stok(str, '.', EL); if (Z != 4) { suntok(str, '.', EL, Z); return 0; } for (i = 0; i < Z; ++i) { for (j = 0; EL[i][j] != '\0'; ++j) { if (myisdigit(EL[i][j])) continue; else { suntok(str, '.', EL, Z); return 0; } } if (255 < myatoi(EL[i])) { suntok(str, '.', EL, Z); return 0; } } suntok(str, '.', EL, Z); return 1; }
void process(char *str) { char *ptr[20]; int count; int i; count = stok(str, '/', ptr); suntok(str, '\\', ptr, count); }
void process(char *path, char *delim) { int count, i; char *subpath[10]; count = stok(path, delim[0], subpath); for (i = 0; i < count; i++) processing(subpath[i]); suntok(path, delim[0], subpath, count); change(path); }
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); }
void process(char *pat, char *dir, char del) { char *RAW[MAXSIZE]; char *TOK[MAXSIZE]; char *a; int Z = 0, R = 0, i, j, k, dLEN, pLEN; pLEN = slen(pat); Z = stok(pat, del, RAW); dLEN = slen(dir); if (Z > 10) { printf("%sПо заданию программа не может обработать больше 10 путей%s\n", clBoldRed, clNormal); myexit(); } for (i = 0; i < Z; i++) { R = stok(RAW[i], '/', TOK); for (j = 0; j < R; j++) { if ((j == 0) && (slen(TOK[j]) > 1) && (TOK[j][0] == '~')) { for (a = pat + pLEN; a > TOK[j]; --a) *(a + dLEN) = *a; scpy(TOK[j], dir); *(TOK[j]+dLEN) = '/'; for (k = i + 1; k < Z; k++) RAW[k] += dLEN; for (k = j - 1; k < R; k++) TOK[k] += dLEN; } } suntok(RAW[i], '/', TOK, R); } suntok(pat, del, RAW, Z); return; }
void check(char *path, char *delim) { length_check(path); symbols_check(path); char *subpath[10]; int count, i; count = stok(path, delim[0], subpath); for (i = 0; i < count; i++) { domen_check(subpath[i]); ip_check(subpath[i]); } suntok(path, delim[0], subpath, count); }
int isservice(char *str) { char *EL[MAXSIZE]; int i; if ((str[0] == '*') || (str[0] == '.') || (str[slen(str)-1] == '.')) return 0; if (3 > slen(str)) return 0; int Z = stok(str, '.', EL); suntok(str, '.', EL, Z); if (2 != Z) return 0; for (i = 0; str[i] != '\0'; i++) { if (!((str[i] >= 'A')&&(str[i] <= 'Z') || ( (str[i] >= 'a')&&(str[i] <= 'z')) || (str[i] == '.') || (str[i] == '*') )) return 0; } return 1; }
void check(char *pat, char *dir, char del) { char *RAW[MAXSIZE]; int Z = 0, i; Z = stok(pat, del, RAW); for (i = 0; i < Z; i++) { if (slen(RAW[i]) > (MAXPATH - 2)) { printf("%sПолучен путь (%d) длина которого больше разрешенной%s\n", clBoldRed, i + 1, clNormal); myexit(); } if (( (RAW[i][0]) != '~') && ( (RAW[i][0]) != '/')) { printf("%sПолучен путь (%d) который не является частью фс unix%s\n", clBoldRed, i+1,clNormal); myexit(); } } suntok(pat, del, RAW, Z); }
void shift(char *str, char *pnext[], int count, int step, int tmp) { char *ptr[100]; int counter; int i; char *next_str; if (step == 0) { counter = stok(str, '\\', ptr); step = slen(str); suntok(str, '\\', ptr, counter); } for (i = step; str[i] != '\0'; i++) str[i - step] = str[i]; str[i - step] = '\0'; if (count != 1) { *(pnext[tmp] - 1) = '?'; pnext[tmp] = &(str[i - step + 1]); next_str = pnext[tmp]; shift(next_str, pnext, (count - 1), step, (tmp + 1)); } }
int main() { int i,j,k,t,s,delta, d_str, j_sdvig, index; char dir1[15] = "win"; char dir2[15] = "winXP"; char del; char raz = '\\'; char str[260] = "C:\\win\\explorer.exe+C:\\Wpn\\sys\\tem32+C:\\win\\Distrib"; char *ptr[10]; char *ptr_dir1[10]; char *ptr_raz[10]; printf("delim: "); scanf("%c",&del); char *suf = str; //C:\\Windows\\system32+C:\\User\\test+C:\\user\\explorer.exe+C:\\Windows\\Distrib /* printf("paths: "); scanf("%s",&str); printf("dir1: "); scanf("%s",&dir1); printf("dir2: "); scanf("%s",&dir2);*/ delta = slen(dir1) - slen(dir2); d_str = slen(str); //printf("delta = %d\n", delta); i = stok(str, del, ptr); k = stok(dir1, raz, ptr_dir1); //t = stok(ptr[0], raz, ptr_raz); //printf("k = %d\n", k); int f = 0; for(j = 0; j < i; j++) { sspn(ptr[j]); } for (j = 0; j < i; j++) { t = stok(ptr[j], raz, ptr_raz); if(k > 1){ for (s = 0; s < k; s++) { f += sequal(ptr_dir1[s], ptr_raz[s]); if (f == k) { index = ptr_raz[s+1] - suf; if (delta < 0) { for (j_sdvig = d_str - delta; j_sdvig > index + delta; j_sdvig--) { str[j_sdvig - delta] = str[j_sdvig]; } for (j_sdvig = j; j_sdvig < i; j_sdvig++) { ptr[j_sdvig + 1] = ptr[j_sdvig + 1] - delta; } ptr_raz[s +1] = ptr_raz[s + 1] - delta; } if (delta > 0) { //d_str = d_str - delta; for (j_sdvig = index; j_sdvig < d_str; j_sdvig++) { str[j_sdvig - delta] = str[j_sdvig]; } str[d_str-delta] = '\0'; for (j_sdvig = j; j_sdvig < i; j_sdvig++) { ptr[j_sdvig + 1] = ptr[j_sdvig + 1] - delta; } ptr_raz[s + 1] = ptr_raz[s + 1] - delta; } //shift(*ptr, *ptr_raz, str, d_str, index, delta, s, j); suntok(ptr[j], raz, ptr_raz, t); scopy(dir2, ptr[j]); f = 0; } suntok(ptr[j], raz, ptr_raz, t); } } for (s = 0; s < t; s++) { f += sequal(dir1, ptr_raz[s]); //printf("f = %d\n", f); if(f == 1){ //printf("s = %d\n", s); index = ptr_raz[s+1] - suf; ///printf("index= %d\n ", index); if (delta < 0) { for (j_sdvig = d_str - delta; j_sdvig > index + delta; j_sdvig--) { str[j_sdvig - delta] = str[j_sdvig]; } for (j_sdvig = j; j_sdvig < i; j_sdvig++) { ptr[j_sdvig + 1] = ptr[j_sdvig + 1] - delta; } ptr_raz[s + 1] = ptr_raz[s + 1] - delta; } if (delta > 0) { for (j_sdvig = index; j_sdvig < d_str; j_sdvig++) { str[j_sdvig - delta] = str[j_sdvig]; } str[d_str-delta] = '\0'; for (j_sdvig = j; j_sdvig < i; j_sdvig++) { ptr[j_sdvig + 1] = ptr[j_sdvig + 1] - delta; } ptr_raz[s + 1] = ptr_raz[s + 1] - delta; } scopy(dir2, ptr_raz[s]); f = 0; } suntok(ptr[j], raz, ptr_raz, t); } //f = 0; } suntok(str, del, ptr, i); printf("%s",str); return 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; } }
int ip_check(char *string) { int i = 0, dot = 0, y = 0; while (i != slen(string)) { if (string[i] == '.') dot++; i++; if (dot > 3) { printf("ERROR: Wrong domen-name: %s\n", string); return 0; } } char *s[20]; char buffer[260]; int z = stok(string, '.', s); i = 0; int t = 0, j = 0; while (j != z) { t = atoi(s[j++]); if (t > 255){ suntok(string, '.', s, z); y = schrn(string, '\\', 3); strcpy(buffer, string); if (y > 0){ buffer[y] = '\0'; } if (buffer[1] == '\\' && buffer[0] == '\\') { del(buffer, 2, 2); } printf("ERROR: Wrong IP-adress: %s\n", buffer); return 0; } else if (t < 0) i++; else i--; } suntok(string, '.', s, z); if (i==-4) { return 1; } else { i = slen(string); if (schrstr(string, ".com") == 0 || schrstr(string, ".ru") == 0 || schrstr(string, ".org") == 0) return 1; else { y = schrn(string, '\\', 3); strcpy(buffer, string); if (y > 0){ buffer[y] = '\0'; } if (buffer[1] == '\\' && buffer[0] == '\\') { del(buffer, 2, 2); } printf("ERROR: Wrong domen-name: %s\n", buffer); return 0; } } }