| verzia 1.5, 2001/10/25 09:37:57 |
verzia 1.6, 2001/10/25 17:37:58 |
|
|
| /* |
/* |
| * $Log$ |
* $Log$ |
| |
* Revision 1.6 2001/10/25 17:37:58 host8 |
| |
* Support only some sms-gates available. |
| |
* |
| * Revision 1.5 2001/10/25 09:37:57 host8 |
* Revision 1.5 2001/10/25 09:37:57 host8 |
| * Added support for selection only some sms-gates. |
* Added support for selection only some sms-gates. |
| * |
* |
|
|
| #include <netinet/in.h> |
#include <netinet/in.h> |
| #include <arpa/inet.h> |
#include <arpa/inet.h> |
| |
|
| #include "config.h" |
#ifdef HAVE_CONFIG_H |
| |
# include "config.h" |
| |
#endif |
| #include "mail2sms.h" |
#include "mail2sms.h" |
| #include "strings.h" |
#include "strings.h" |
| |
|
| Riadok 40 void http_set_cookie(char *str) |
|
| Riadok 45 void http_set_cookie(char *str) |
|
| void http_set_referer(char *host, char *file) |
void http_set_referer(char *host, char *file) |
| { |
{ |
| if (host != NULL && file != NULL) { |
if (host != NULL && file != NULL) { |
| if (g.debug) fprintf(stderr, "Setting Referer to '%s%s'\n", |
#ifdef DEBUG |
| host, file); |
if (g.debug) |
| |
fprintf(stderr, "Setting Referer to '%s%s'\n", |
| |
host, file); |
| |
#endif |
| free(www.referer); |
free(www.referer); |
| www.referer = (char *) malloc((strlen(host)+strlen(file)+7)* |
www.referer = (char *) malloc((strlen(host)+strlen(file)+7)* |
| sizeof(char)); |
sizeof(char)); |
| Riadok 53 FILE *http_connect(void) |
|
| Riadok 61 FILE *http_connect(void) |
|
| { |
{ |
| FILE *f; |
FILE *f; |
| int s = 0; |
int s = 0; |
| int i; |
int i, idx = -1; |
| struct sockaddr_in sockaddrIn; |
struct sockaddr_in sockaddrIn; |
| |
|
| sockaddrIn.sin_port = htons(servers[id].port); |
for (i=0; servers[i].desc != NULL; i++) { |
| |
if (servers[i].id == id) { |
| |
idx = i; |
| |
break; |
| |
} |
| |
} |
| |
if (idx == -1) { |
| |
fprintf(stderr, "Id %d not found in servers[] !\n", id); |
| |
exit(1); |
| |
} |
| |
sockaddrIn.sin_port = htons(servers[idx].port); |
| sockaddrIn.sin_family = AF_INET; |
sockaddrIn.sin_family = AF_INET; |
| sockaddrIn.sin_addr.s_addr = inet_addr(servers[id].ip); |
sockaddrIn.sin_addr.s_addr = inet_addr(servers[idx].ip); |
| s = socket(PF_INET, SOCK_STREAM, 0); |
s = socket(PF_INET, SOCK_STREAM, 0); |
| |
|
| if (s != -1) { |
if (s != -1) { |
| Riadok 70 FILE *http_connect(void) |
|
| Riadok 88 FILE *http_connect(void) |
|
| if ((f = fdopen(s, "w+b")) != NULL) |
if ((f = fdopen(s, "w+b")) != NULL) |
| return (f); |
return (f); |
| } |
} |
| fprintf(stderr, "Can't connect to %s[%s]\n", servers[id].desc, |
fprintf(stderr, "Can't connect to %s[%s]\n", servers[idx].desc, |
| servers[id].ip); |
servers[idx].ip); |
| |
|
| return(NULL); |
return(NULL); |
| } // }}} |
} // }}} |
| // Function http_read_source() {{{ |
// Function http_read_source() {{{ |
| void http_read_source(FILE *f, char *host, char *file) |
void http_read_source(FILE *f, char *host, char *file) |
| { |
{ |
| |
#ifdef DEBUG |
| int info = g.debug; |
int info = g.debug; |
| |
#else |
| |
int info = 1; |
| |
#endif |
| |
|
| while (1) { |
while (1) { |
| char bla[1024]; |
char bla[1024]; |
| //char *found; |
//char *found; |
| |
|
| if (fgets(bla, sizeof(bla), f) == NULL) break; |
if (fgets(bla, sizeof(bla), f) == NULL) |
| |
break; |
| if (info) { |
if (info) { |
| fprintf(stderr, "\t%.*s\n", (int)(strlen(bla)-2), bla); |
fprintf(stderr, "\t%.*s\n", (int)(strlen(bla)-2), bla); |
| info=0; |
info=0; |
| Riadok 94 void http_read_source(FILE *f, char *hos |
|
| Riadok 117 void http_read_source(FILE *f, char *hos |
|
| } |
} |
| else if ((bla+8) == strstr(bla, " 302 Object Moved")) { |
else if ((bla+8) == strstr(bla, " 302 Object Moved")) { |
| /* TODO: implement this error-handling |
/* TODO: implement this error-handling |
| */ |
*/ |
| } |
} |
| } |
} |
| } |
} |
| |
#ifdef DEBUG |
| if (g.debug > 8 ) { |
if (g.debug > 8 ) { |
| fputs(bla, stderr); |
fputs(bla, stderr); |
| } |
} |
| |
#endif |
| if (bla == strstr(bla, "Set-Cookie: ")) |
if (bla == strstr(bla, "Set-Cookie: ")) |
| http_set_cookie(bla); |
http_set_cookie(bla); |
| } |
} |
| Riadok 122 void http_read_source(FILE *f, char *hos |
|
| Riadok 147 void http_read_source(FILE *f, char *hos |
|
| fprintf(stderr, "\t%.*s\n", (int)(strlen(bla)-2), bla); |
fprintf(stderr, "\t%.*s\n", (int)(strlen(bla)-2), bla); |
| info=0; |
info=0; |
| } |
} |
| */ |
*/ |
| } // }}} |
} // }}} |
| // Function http_request() {{{ |
// Function http_request() {{{ |
| int http_request(int method, char *file, char *host, char *fmt, ...) |
int http_request(int method, char *file, char *host, char *fmt, ...) |
| Riadok 130 int http_request(int method, char *file, |
|
| Riadok 155 int http_request(int method, char *file, |
|
| FILE *f; |
FILE *f; |
| va_list ap; |
va_list ap; |
| |
|
| if ((f=http_connect()) == NULL) return(-1); |
if ((f=http_connect()) == NULL) |
| |
return(-1); |
| |
#ifdef DEBUG |
| if (g.debug) { // Debug code STAHUJEM/POSIELAM {{{ |
if (g.debug) { // Debug code STAHUJEM/POSIELAM {{{ |
| if (method == HTTP_GET) { |
if (method == HTTP_GET) { |
| fprintf(stderr, "STAHUJEM: %s%s\n", host, file); |
fprintf(stderr, "STAHUJEM: %s%s\n", host, file); |
| Riadok 139 int http_request(int method, char *file, |
|
| Riadok 166 int http_request(int method, char *file, |
|
| fprintf(stderr, "POSIELAM: %s%s\n", host, file); |
fprintf(stderr, "POSIELAM: %s%s\n", host, file); |
| } |
} |
| } // }}} |
} // }}} |
| |
#endif |
| if (method == HTTP_GET) { |
if (method == HTTP_GET) { |
| fprintf(f, "GET %s HTTP/1.0\r\n", file); |
fprintf(f, "GET %s HTTP/1.0\r\n", file); |
| } |
} |
| Riadok 147 int http_request(int method, char *file, |
|
| Riadok 175 int http_request(int method, char *file, |
|
| } |
} |
| else { |
else { |
| fprintf(stderr, "Unknown http method %d\n", method); |
fprintf(stderr, "Unknown http method %d\n", method); |
| |
return(-1); |
| } |
} |
| fprintf(f, "Host: %s\r\n", host); |
fprintf(f, "Host: %s\r\n", host); |
| fprintf(f, "Accept: text/html, text/plain, application/applefile, "); |
fprintf(f, "Accept: text/html, text/plain, application/applefile, "); |
| Riadok 172 int http_request(int method, char *file, |
|
| Riadok 201 int http_request(int method, char *file, |
|
| fprintf(f, "%s", USER_AGENT); |
fprintf(f, "%s", USER_AGENT); |
| if (www.referer != NULL) fprintf(f, "Referer: %s\r\n", www.referer); |
if (www.referer != NULL) fprintf(f, "Referer: %s\r\n", www.referer); |
| if (www.cookies != NULL) { |
if (www.cookies != NULL) { |
| |
#ifdef DEBUG |
| if (g.debug) |
if (g.debug) |
| fprintf(stderr, "Cookie2: $Version=\"1\"\r\nCookie: %s\r\n", |
fprintf(stderr, "Cookie2: $Version=\"1\"\r\nCookie: %s\r\n", |
| www.cookies); |
www.cookies); |
| |
#endif |
| fprintf(f, "Cookie2: $Version=\"1\"\r\nCookie: %s\r\n", |
fprintf(f, "Cookie2: $Version=\"1\"\r\nCookie: %s\r\n", |
| www.cookies); |
www.cookies); |
| } |
} |
| Riadok 185 int http_request(int method, char *file, |
|
| Riadok 216 int http_request(int method, char *file, |
|
| } |
} |
| fprintf(f, "\r\n"); |
fprintf(f, "\r\n"); |
| http_read_source(f, host, file); |
http_read_source(f, host, file); |
| |
#ifdef DEBUG |
| if (g.debug) { |
if (g.debug) { |
| fprintf(stderr, "HTTP request sent, reply OK...\n"); |
fprintf(stderr, "HTTP request sent, reply OK...\n"); |
| } |
} |
| |
#endif |
| return 0; |
return 0; |
| } // }}} |
} // }}} |
| |
|