bosko lekovic
/
ETHtoCOM_10
nova verzija tcp+udp->serial com
clubbing.cpp@5:c9a908749d4c, 2020-04-12 (annotated)
- Committer:
- bosko001
- Date:
- Sun Apr 12 17:59:57 2020 +0000
- Revision:
- 5:c9a908749d4c
- Parent:
- 3:1196befeace0
- Child:
- 8:c0f54b381346
12.04.2020; napravljena class C_HTMLparse; treba napraviti obradu POST upita
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bosko001 | 2:45b351b4fc2a | 1 | #include "clubbing.h" |
bosko001 | 2:45b351b4fc2a | 2 | |
bosko001 | 2:45b351b4fc2a | 3 | |
bosko001 | 2:45b351b4fc2a | 4 | |
bosko001 | 2:45b351b4fc2a | 5 | #include <stdio.h> |
bosko001 | 2:45b351b4fc2a | 6 | #include <stdlib.h> |
bosko001 | 2:45b351b4fc2a | 7 | #include <string.h> |
bosko001 | 2:45b351b4fc2a | 8 | #include <ctype.h> |
bosko001 | 2:45b351b4fc2a | 9 | |
bosko001 | 2:45b351b4fc2a | 10 | |
bosko001 | 3:1196befeace0 | 11 | /********************** PRINT-ovi *********************************/ |
bosko001 | 3:1196befeace0 | 12 | |
bosko001 | 5:c9a908749d4c | 13 | void P_niz( const char *s, const char *niz, int val ) |
bosko001 | 3:1196befeace0 | 14 | { |
bosko001 | 3:1196befeace0 | 15 | printf("%s",s); |
bosko001 | 3:1196befeace0 | 16 | for( int i=0; i < val; i++) printf("%c", niz[i]); |
bosko001 | 3:1196befeace0 | 17 | printf("\n\r"); |
bosko001 | 3:1196befeace0 | 18 | fflush(stdout); |
bosko001 | 3:1196befeace0 | 19 | } |
bosko001 | 3:1196befeace0 | 20 | |
bosko001 | 5:c9a908749d4c | 21 | void P_int(const char *s, int i ) |
bosko001 | 3:1196befeace0 | 22 | { |
bosko001 | 3:1196befeace0 | 23 | printf("%s = %d\n\r", s, i); fflush(stdout); |
bosko001 | 3:1196befeace0 | 24 | } |
bosko001 | 3:1196befeace0 | 25 | |
bosko001 | 3:1196befeace0 | 26 | void P_str(const char *s, const char *p ) |
bosko001 | 3:1196befeace0 | 27 | { |
bosko001 | 3:1196befeace0 | 28 | printf("%s = %s\n\r", s, p); fflush(stdout); |
bosko001 | 3:1196befeace0 | 29 | } |
bosko001 | 3:1196befeace0 | 30 | |
bosko001 | 3:1196befeace0 | 31 | |
bosko001 | 3:1196befeace0 | 32 | |
bosko001 | 3:1196befeace0 | 33 | /************************ IP testovi ****************************/ |
bosko001 | 5:c9a908749d4c | 34 | int test_num( const char *s ) |
bosko001 | 2:45b351b4fc2a | 35 | { |
bosko001 | 2:45b351b4fc2a | 36 | int m=strlen(s), n=0, i; |
bosko001 | 2:45b351b4fc2a | 37 | for( i=0; i<m; i++) |
bosko001 | 2:45b351b4fc2a | 38 | if( isdigit(s[i]) ) n++; |
bosko001 | 2:45b351b4fc2a | 39 | if(i==n) return 1; |
bosko001 | 2:45b351b4fc2a | 40 | return 0; |
bosko001 | 2:45b351b4fc2a | 41 | } |
bosko001 | 2:45b351b4fc2a | 42 | |
bosko001 | 5:c9a908749d4c | 43 | int test_ip( const char *s ) |
bosko001 | 2:45b351b4fc2a | 44 | { |
bosko001 | 2:45b351b4fc2a | 45 | char str[16]; |
bosko001 | 2:45b351b4fc2a | 46 | strncpy( str, s, 16); |
bosko001 | 2:45b351b4fc2a | 47 | |
bosko001 | 2:45b351b4fc2a | 48 | |
bosko001 | 2:45b351b4fc2a | 49 | int d = strlen(str); |
bosko001 | 2:45b351b4fc2a | 50 | |
bosko001 | 2:45b351b4fc2a | 51 | if( d < 7) return 0; |
bosko001 | 2:45b351b4fc2a | 52 | else |
bosko001 | 2:45b351b4fc2a | 53 | { |
bosko001 | 2:45b351b4fc2a | 54 | int k=0; |
bosko001 | 2:45b351b4fc2a | 55 | for( int i=0; i<d; i++) |
bosko001 | 2:45b351b4fc2a | 56 | if( str[i] == '.' ) k++; |
bosko001 | 2:45b351b4fc2a | 57 | if(k != 3 ) { return 0; } |
bosko001 | 2:45b351b4fc2a | 58 | k=0; |
bosko001 | 2:45b351b4fc2a | 59 | char *token; |
bosko001 | 2:45b351b4fc2a | 60 | token = strtok(str, "."); |
bosko001 | 2:45b351b4fc2a | 61 | while( token != NULL ) |
bosko001 | 2:45b351b4fc2a | 62 | { |
bosko001 | 2:45b351b4fc2a | 63 | if( test_num(token) ) k++; |
bosko001 | 2:45b351b4fc2a | 64 | token = strtok(NULL, "."); |
bosko001 | 2:45b351b4fc2a | 65 | } |
bosko001 | 2:45b351b4fc2a | 66 | if(k==4) return 1; |
bosko001 | 2:45b351b4fc2a | 67 | else return 0; |
bosko001 | 2:45b351b4fc2a | 68 | |
bosko001 | 2:45b351b4fc2a | 69 | } |
bosko001 | 2:45b351b4fc2a | 70 | |
bosko001 | 2:45b351b4fc2a | 71 | } |
bosko001 | 2:45b351b4fc2a | 72 | |
bosko001 | 3:1196befeace0 | 73 | |
bosko001 | 3:1196befeace0 | 74 |