| verzia 1.4, 2001/09/24 06:59:45 |
verzia 1.5, 2001/09/24 18:12:56 |
|
|
| /* |
/* |
| * Author: rajo <host8@kepler.fmph.uniba.sk> |
* Author: rajo <host8@kepler.fmph.uniba.sk> |
| * $Log$ |
* $Log$ |
| |
* Revision 1.5 2001/09/24 18:12:56 host8 |
| |
* Added files strings.[ch] http.[ch] |
| |
* |
| * Revision 1.4 2001/09/24 06:59:45 host8 |
* Revision 1.4 2001/09/24 06:59:45 host8 |
| * Added GLOBTELNET site |
* Added GLOBTELNET site |
| * |
* |
| * Revision 1.3 2001/09/20 14:37:22 host8 |
* Revision 1.3 2001/09/20 14:37:22 host8 |
| * Changed keyword substitution ($Log$ |
* Changed keyword substitution ($Log$ |
| |
* Changed keyword substitution (Revision 1.5 2001/09/24 18:12:56 host8 |
| |
* Changed keyword substitution (Added files strings.[ch] http.[ch] |
| |
* Changed keyword substitution ( |
| * Changed keyword substitution (Revision 1.4 2001/09/24 06:59:45 host8 |
* Changed keyword substitution (Revision 1.4 2001/09/24 06:59:45 host8 |
| * Changed keyword substitution (Added GLOBTELNET site |
* Changed keyword substitution (Added GLOBTELNET site |
| * Changed keyword substitution ( test) |
* Changed keyword substitution ( test) |
|
|
| #include <stdio.h> |
#include <stdio.h> |
| #include <stdlib.h> |
#include <stdlib.h> |
| #include <stdarg.h> |
#include <stdarg.h> |
| #include <unistd.h> |
|
| #include <string.h> |
#include <string.h> |
| #include <ctype.h> |
#include <unistd.h> |
| #include <errno.h> |
#include <errno.h> |
| #include <getopt.h> |
#include <getopt.h> |
| #include <sys/socket.h> |
|
| #include <sys/types.h> |
|
| #include <netinet/in.h> |
|
| #include <arpa/inet.h> |
|
| //#include <netdb.h> |
//#include <netdb.h> |
| |
|
| #include "mail2sms.h" |
#include "mail2sms.h" |
| |
#include "http.h" |
| |
#include "strings.h" |
| |
|
| /* }}}1 */ |
/* }}}1 */ |
| /* global variables {{{1 */ |
/* global variables {{{ */ |
| char *message, *scratch, *keybd; |
char *message, *scratch, *keybd; |
| GLOB g; |
GLOB g; |
| WWW www; |
WWW www; |
| |
|
| /* }}}1 */ |
/* }}} */ |
| /* Functions {{{1 */ |
|
| /* String functions {{{2 */ |
|
| // Function isnnumber() {{{ |
|
| int isnnumber(char *str, int len) |
|
| { |
|
| int i; |
|
| for(i=0; 1<len; i++) |
|
| if (!isdigit(*str++)) |
|
| return 0; |
|
| return 1; |
|
| } // }}} |
|
| // Function strdel() {{{ |
|
| char *strdel(char *str) |
|
| { |
|
| register int k=-1; |
|
| while (++k, str[k]!='\0') |
|
| str[k]=str[k+1]; |
|
| return(str); |
|
| } // }}} |
|
| // Function strtolower() {{{ |
|
| char *strtolower(char *str) |
|
| { |
|
| while (*str) { |
|
| *str=tolower(*str); |
|
| str++; |
|
| } |
|
| return str; |
|
| } // }}} |
|
| // Function strip() {{{ |
|
| char *strip(char *str) |
|
| { |
|
| register int k=-1; |
|
| while (++k, str[k]!='\0') { |
|
| if ((*(str+k)==*(str+k+1)) && |
|
| (!isdigit(*(str+k)))) { |
|
| strdel(str+k); k--; |
|
| } |
|
| } |
|
| return(str); |
|
| } // }}} |
|
| // Function hexa() {{{ |
|
| char *hexa(int c) |
|
| { |
|
| char *str; |
|
| |
|
| if (c>=0 && c<256) { |
|
| str = (char *) malloc(4*sizeof(char)); |
|
| sprintf(str, "%.2X", c); |
|
| // printf("HEXA: '%s'\n", str); |
|
| return(str); |
|
| } |
|
| return(NULL); |
|
| } // }}} |
|
| // Function compress_str() {{{ |
|
| char *compress_str(char *str) |
|
| { |
|
| int j; |
|
| |
|
| strip(str); |
|
| j=-1; |
|
| while (++j,*(str+j)!='\0') { |
|
| if (*(str+j)==' ') { |
|
| strdel(str+j); |
|
| *(str+j)=toupper(*(str+j)); |
|
| } |
|
| } |
|
| return str; |
|
| |
|
| } // }}} |
|
| // Function add_str_to_sms() {{{ |
|
| void add_str_to_sms(char *str) |
|
| { |
|
| int j; |
|
| char *pom; |
|
| |
|
| compress_str(str); |
|
| if (strlen(g.text) < SMS_LEN) { |
|
| j=0; |
|
| while (strlen(g.text)<SMS_LEN && *(str+j)!='\0') { |
|
| if (isalnum(*(str+j))) { |
|
| strncat(g.text, (str+j), 1); |
|
| } |
|
| else { |
|
| if ((SMS_LEN-strlen(g.text)) > 2) { |
|
| strcat(g.text, "%"); |
|
| pom = hexa(*(str+j)); |
|
| strcat(g.text, pom); |
|
| free(pom); |
|
| } |
|
| else return; |
|
| } |
|
| j++; |
|
| } |
|
| } |
|
| return; |
|
| |
|
| } // }}} |
|
| /* }}}2 */ |
|
| // Function void_read_at_exit() {{{ |
// Function void_read_at_exit() {{{ |
| void void_read_at_exit(void) |
void void_read_at_exit(void) |
| { |
{ |
| Riadok 151 void void_read_at_exit(void) |
|
| Riadok 56 void void_read_at_exit(void) |
|
| FD_ZERO(&fds); |
FD_ZERO(&fds); |
| FD_SET(0,&fds); |
FD_SET(0,&fds); |
| switch(select(FD_SETSIZE,&fds,0,0,0)) { |
switch(select(FD_SETSIZE,&fds,0,0,0)) { |
| case -1 : |
case -1 : |
| perror(""); |
perror(""); |
| exit(errno); |
exit(errno); |
| break; |
break; |
| Riadok 161 void void_read_at_exit(void) |
|
| Riadok 66 void void_read_at_exit(void) |
|
| else koniec=1; |
else koniec=1; |
| } |
} |
| break; |
break; |
| } // end switch( select() ) |
} // end switch( select() ) |
| } // end while(!koniec) |
} // end while(!koniec) |
| |
|
| free(message); |
free(message); |
| Riadok 169 void void_read_at_exit(void) |
|
| Riadok 74 void void_read_at_exit(void) |
|
| free(keybd); |
free(keybd); |
| exit(0); |
exit(0); |
| } // }}} |
} // }}} |
| // Function http_set_cookie() {{{ |
|
| void http_set_cookie(char *str) |
|
| { |
|
| if (str!=NULL) { |
|
| if (str==strstr("Set-Cookie: ", str)) { |
|
| www.cookies = strdup(str + 13); |
|
| } |
|
| } |
|
| } // }}} |
|
| // Function http_set_referer() {{{ |
|
| void http_set_referer(char *host, char *file) |
|
| { |
|
| if (host!=NULL&&file!=NULL) { |
|
| if (g.debug) fprintf(stderr, "Setting Referer to '%s%s'\n", |
|
| host, file); |
|
| free(www.referer); |
|
| www.referer = (char *) malloc((strlen(host)+strlen(file)+7)* |
|
| sizeof(char)); |
|
| sprintf(www.referer, "http://%s%s", host, file); |
|
| } |
|
| } // }}} |
|
| // Function http_connect() {{{ |
|
| FILE *http_connect(void) |
|
| { |
|
| FILE *f; |
|
| int s = 0; |
|
| int i; |
|
| struct sockaddr_in sin; |
|
| |
|
| if (g.gate==AZET) { |
|
| sin.sin_port = htons(AZET_PORT); |
|
| sin.sin_family = AF_INET; |
|
| sin.sin_addr.s_addr = inet_addr(AZET_SERVER); |
|
| s = socket(PF_INET, SOCK_STREAM, 0); |
|
| } |
|
| else if (g.gate==WHIZDIARY) { |
|
| sin.sin_port = htons(WHIZDIARY_PORT); |
|
| sin.sin_family = AF_INET; |
|
| sin.sin_addr.s_addr = inet_addr(WHIZDIARY_SERVER); |
|
| s = socket(PF_INET, SOCK_STREAM, 0); |
|
| } |
|
| else if (g.gate==SPISNET) { |
|
| sin.sin_port = htons(SPISNET_PORT); |
|
| sin.sin_family = AF_INET; |
|
| sin.sin_addr.s_addr = inet_addr(SPISNET_SERVER); |
|
| s = socket(PF_INET, SOCK_STREAM, 6); |
|
| } |
|
| if (s != -1) { |
|
| for (i=0; i<MAX_CONNECTS; i++) { |
|
| if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) != -1) |
|
| break; |
|
| } |
|
| if ((f = fdopen(s, "w+b")) != NULL) |
|
| return (f); |
|
| } |
|
| if (g.gate==AZET) { |
|
| fprintf(stderr, "Nemozem sa pripojit na %s\n", AZET_SERVER); |
|
| } |
|
| else if (g.gate==WHIZDIARY) { |
|
| fprintf(stderr, "Nemozem sa pripojit na %s\n", WHIZDIARY_SERVER); |
|
| } |
|
| else if (g.gate==SPISNET) { |
|
| fprintf(stderr, "Nemozem sa pripojit na %s\n", SPISNET_SERVER); |
|
| } |
|
| return(NULL); |
|
| } // }}} |
|
| // Function http_read_source() {{{ |
|
| void http_read_source(FILE *f, char *host, char *file) |
|
| { |
|
| int info = g.debug; |
|
| |
|
| while (1) { |
|
| char bla[1024]; |
|
| //char *found; |
|
| |
|
| if (fgets(bla, sizeof(bla), f) == NULL) break; |
|
| if (info) { |
|
| fprintf(stderr, "\t%.*s\n", (int)(strlen(bla)-2), bla); |
|
| info=0; |
|
| if (strstr(bla, "HTTP/1.") != NULL) { |
|
| if ((bla+8)==strstr(bla, " 200 OK")) |
|
| http_set_referer(host, file); |
|
| } |
|
| } |
|
| if (g.debug > 8 ) { |
|
| fputs(bla, stderr); |
|
| } |
|
| if (bla == strstr(bla, "Set-Cookie: ")) |
|
| http_set_cookie(bla); |
|
| } |
|
| fclose (f); |
|
| |
|
| /* |
|
| if (strstr(bla, "Kvôli neznámej chybe sa nepodarilo odosla SMS" |
|
| " správu. Odolite ju ete raz.") |
|
| != NULL) { |
|
| fprintf(stderr, "\t%.70s", bla+23); |
|
| return(1); |
|
| } |
|
| found = strstr(bla, "Na toto \350\355slo m\364\236te " |
|
| "dnes posla\235 e\232te"); |
|
| if (found != NULL) { |
|
| fprintf(stderr, "\tMozno poslat este %.5s sprav.\n", found + 37); |
|
| } |
|
| if (info) { |
|
| fprintf(stderr, "\t%.*s\n", (int)(strlen(bla)-2), bla); |
|
| info=0; |
|
| } |
|
| */ |
|
| } // }}} |
|
| // Function http_request() {{{ |
|
| int http_request(int method, char *file, char *host, char *fmt, ...) |
|
| { |
|
| FILE *f; |
|
| va_list ap; |
|
| |
|
| if ((f=http_connect()) == NULL) return(-1); |
|
| if (g.debug) { // Debug code STAHUJEM/POSIELAM {{{ |
|
| if(method==HTTP_GET) { |
|
| fprintf(stderr, "STAHUJEM: %s%s\n", host, file); |
|
| } |
|
| else { |
|
| fprintf(stderr, "POSIELAM: %s%s\n", host, file); |
|
| } |
|
| } // }}} |
|
| if (method==HTTP_GET) { |
|
| fprintf(f, "GET %s HTTP/1.0\r\n", file); |
|
| } |
|
| else if(method==HTTP_POST) { |
|
| fprintf(f, "POST %s HTTP/1.0\r\n", file); |
|
| } |
|
| else { |
|
| fprintf(stderr, "Unknown http method %d\n", method); |
|
| } |
|
| fprintf(f, "Host: %s\r\n", host); |
|
| fprintf(f, "Accept: text/html, text/plain, application/applefile, "); |
|
| fprintf(f, "application/x-metamail-patch, sun-deskset-message, "); |
|
| fprintf(f, "mail-file, default, postscript-file, audio-file, "); |
|
| fprintf(f, "x-sun-attachment, text/enriched, text/richtext, "); |
|
| fprintf(f, "application/andrew-inset, x-be2\r\n"); |
|
| fprintf(f, "Accept: application/postscript, message/external-body, "); |
|
| fprintf(f, "message/partial, image/g3fax, application/pdf, "); |
|
| fprintf(f, "application/pgp, application/pgp, video/mpeg, video/*, "); |
|
| fprintf(f, "image/*, audio/mod, text/sgml, */*;q=0.01\r\n"); |
|
| fprintf(f, "Accept-Encoding: gzip, compress\r\n"); |
|
| fprintf(f, "Accept-Language: en\r\n"); |
|
| |
|
| //fprintf(f, "Accept: text/html, text/plain, audio/mod, image/*, video/*, video/mpeg, application/pgp, application/pgp, application/pdf, message/partial, message/external-body, application/postscript, x-be2, application/andrew-inset, text/richtext, text/enriched\r\nAccept: x-sun-attachment, audio-file, postscript-file, default, mail-file, sun-deskset-message, application/x-metamail-patch, text/sgml, video/mpeg, image/jpeg, image/tiff, image/x-rgb, image/png, image/x-xbitmap, image/x-xbm, image/gif\r\nAccept: application/postscript, */*;q=0.01\r\nAccept-Encoding: gzip, compress\r\nAccept-Language: en\r\n"); |
|
| //fprintf(f, "Negotiate: trans\r\n"); |
|
| if(method==HTTP_POST) { |
|
| fprintf(f, "Pragma: no-cache\r\n"); |
|
| fprintf(f, "Cache-Control: no-cache\r\n"); |
|
| } |
|
| fprintf(f, "%s", USER_AGENT); |
|
| if (www.referer!=NULL) fprintf(f, "Referer: %s\r\n", www.referer); |
|
| if (www.cookies!=NULL) { |
|
| if (g.debug) |
|
| fprintf(stderr, "Cookie2: $Version=\"1\"\r\nCookie: %s\r\n", |
|
| www.cookies); |
|
| fprintf(f, "Cookie2: $Version=\"1\"\r\nCookie: %s\r\n", |
|
| www.cookies); |
|
| } |
|
| if (fmt!=NULL) { |
|
| va_start(ap, fmt); |
|
| vfprintf(f, fmt, ap); |
|
| va_end(ap); |
|
| } |
|
| fprintf(f, "\r\n"); |
|
| http_read_source(f, host, file); |
|
| if (g.debug) { |
|
| fprintf(stderr, "HTTP request sent, reply OK...\n"); |
|
| } |
|
| return 0; |
|
| } // }}} |
|
| // Function sendsms() {{{ |
// Function sendsms() {{{ |
| int sendsms(char *str, int show_info) |
int sendsms(char *str, int show_info) |
| { |
{ |
| Riadok 383 int sendsms(char *str, int show_info) |
|
| Riadok 114 int sendsms(char *str, int show_info) |
|
| } |
} |
| else if (g.gate==GLOBTELNET) { |
else if (g.gate==GLOBTELNET) { |
| /* Begin of frames * |
/* Begin of frames * |
| http_request(HTTP_GET, "/get/guest/app.php3.html", |
http_request(HTTP_GET, "/get/guest/app.php3.html", |
| "www.globtelnet.sk", NULL); |
"www.globtelnet.sk", NULL); |
| http_request(HTTP_GET, "/get/guest/core/core.php3.html", |
http_request(HTTP_GET, "/get/guest/core/core.php3.html", |
| "www.globtelnet.sk", NULL); |
"www.globtelnet.sk", NULL); |
| http_request(HTTP_GET, "/get/guest/app.php3:_navigator:.html", |
http_request(HTTP_GET, "/get/guest/app.php3:_navigator:.html", |
| "www.globtelnet.sk", NULL); |
"www.globtelnet.sk", NULL); |
| http_request(HTTP_GET, "/get/all/app.php3:_linkbar.html", |
http_request(HTTP_GET, "/get/all/app.php3:_linkbar.html", |
| "www.globtelnet.sk", NULL); |
"www.globtelnet.sk", NULL); |
| * End of frames */ |
* End of frames */ |
| http_request(HTTP_GET, "/get/all/core/register.php3.html", |
http_request(HTTP_GET, "/get/all/core/register.php3.html", |
| "www.globtelnet.sk", NULL); |
"www.globtelnet.sk", NULL); |
| /* login */ |
/* login */ |
| Riadok 465 void analyze_mail(char *str) |
|
| Riadok 196 void analyze_mail(char *str) |
|
| return; |
return; |
| } |
} |
| if ((!strcmp(str,"\n")) && g.is_header&&1) { |
if ((!strcmp(str,"\n")) && g.is_header&&1) { |
| printf("END OF HEADER\n"); |
fprintf(stderr, "END OF HEADER\n"); |
| g.is_header=0; |
g.is_header=0; |
| g.skipped_header=1; |
g.skipped_header=1; |
| return; |
return; |
| Riadok 548 int main(int argc, char *argv[]) |
|
| Riadok 279 int main(int argc, char *argv[]) |
|
| switch (c) { |
switch (c) { |
| case 'n': |
case 'n': |
| g.number = optarg; // priradenie tel. cisla |
g.number = optarg; // priradenie tel. cisla |
| printf("n: number = %s\n", g.number); |
fprintf(stderr, "n: number = %s\n", g.number); |
| break; |
break; |
| case 'g': |
case 'g': |
| printf("%s\n", optarg); |
fprintf(stderr, "%s\n", optarg); |
| if (strcmp(optarg, "azet")==0) { |
if (strcmp(optarg, "azet")==0) { |
| g.gate = AZET; |
g.gate = AZET; |
| } |
} |
| Riadok 571 int main(int argc, char *argv[]) |
|
| Riadok 302 int main(int argc, char *argv[]) |
|
| break; |
break; |
| case 'm': |
case 'm': |
| g.is_mail = 1; |
g.is_mail = 1; |
| printf("m: is_mail = %d\n", g.is_mail); |
fprintf(stderr, "m: is_mail = %d\n", g.is_mail); |
| break; |
break; |
| case 'M': |
case 'M': |
| g.is_mail = 0; |
g.is_mail = 0; |
| printf("M: is_mail = %d\n", g.is_mail); |
fprintf(stderr, "M: is_mail = %d\n", g.is_mail); |
| break; |
break; |
| case 'r': |
case 'r': |
| g.reverse = 1; |
g.reverse = 1; |
| Riadok 643 int main(int argc, char *argv[]) |
|
| Riadok 374 int main(int argc, char *argv[]) |
|
| strcat(message, argv[optind++]); |
strcat(message, argv[optind++]); |
| if(argv[optind] != NULL) strcat(message, "+"); |
if(argv[optind] != NULL) strcat(message, "+"); |
| } |
} |
| printf ("\n"); |
fprintf(stderr, "\n"); |
| if (g.debug) |
if (g.debug) |
| fprintf (stderr, "\n"); |
fprintf (stderr, "\n"); |
| } |
} |
| printf("message: %s\n", message); |
fprintf(stderr, "message: %s\n", message); |
| |
|
| while (!koniec) { |
while (!koniec) { |
| FD_ZERO(&fds); |
FD_ZERO(&fds); |
| Riadok 699 int main(int argc, char *argv[]) |
|
| Riadok 430 int main(int argc, char *argv[]) |
|
| free(keybd); |
free(keybd); |
| return 0; |
return 0; |
| } // }}} |
} // }}} |
| /* }}}1 */ |
|
| /* Modeline for ViM {{{1 |
/* Modeline for ViM {{{1 |
| * vim:set ts=4: |
* vim:set ts=4: |
| * vim600:fdm=marker fdl=0 fdc=3: |
* vim600:fdm=marker fdl=0 fdc=3: |