summaryrefslogtreecommitdiff
path: root/src/htsserver.c
diff options
context:
space:
mode:
authorXavier Roche <xroche@users.noreply.github.com>2013-05-14 20:30:28 +0000
committerXavier Roche <xroche@users.noreply.github.com>2013-05-14 20:30:28 +0000
commit07f4b003675260004c49755dde413944a16ca2d3 (patch)
tree11050b4c7fbe1d7c63a38f5f9a6b5ba6d8260ae1 /src/htsserver.c
parentb09def438c5e47305e4a5ab18d8a646a3b004fdc (diff)
Indenting cleanup for all *.[ch] files, except htsparse.c (too ugly to be automatically indented for now) and /minizip/, /mmsrip/ (external files)
setup: indent -l80 -lc80 -nhnl -nut -bad -bap -bbo -br -brf -bli2 -brs -bls -br -ss -sai -pmt -nsaw -nsaf -nprs -i2 -ce -npsl -npcs -cs -sob -cdw -nbc -lp logs: indent: ./src/htsback.c:157: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htsback.c:1417: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htsback.c:1826: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htsback.c:1833: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htsback.c:1981: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htsback.c:2685: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htsback.c:2747: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htsback.c:2861: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htsback.c:3128: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htsback.c:3512: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htswizard.c:140: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htswizard.c:597: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htswizard.c:598: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htswizard.c:611: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htscoremain.c:97: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htscoremain.c:106: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htscoremain.c:106: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htscoremain.c:256: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htscoremain.c:262: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htscoremain.c:935: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/httrack.c:271: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/httrack.c:272: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/httrack.c:273: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/httrack.c:274: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/httrack.c:275: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/httrack.c:276: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/httrack.c:277: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/httrack.c:278: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/httrack.c:279: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/httrack.c:280: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/httrack.c:281: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/httrack.c:662: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/httrack.c:752: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htsweb.c:413: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htsweb.c:414: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htsweb.c:415: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htsweb.c:416: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htsweb.c:417: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htsweb.c:418: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htsweb.c:419: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htsweb.c:420: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htsweb.c:421: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htsweb.c:422: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htsweb.c:423: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/proxy/proxytrack.c:188: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/proxy/proxytrack.c:507: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/proxy/proxytrack.c:508: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/proxy/proxytrack.c:509: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/proxy/proxytrack.c:510: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/proxy/proxytrack.c:511: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/proxy/proxytrack.c:512: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/proxy/proxytrack.c:580: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/proxy/proxytrack.c:581: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/proxy/proxytrack.h:115: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/proxy/proxytrack.h:246: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/proxy/proxytrack.h:247: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/proxy/proxytrack.h:248: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/proxy/proxytrack.h:249: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/proxy/proxytrack.h:250: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/proxy/proxytrack.h:251: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/proxy/proxytrack.h:314: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/proxy/proxytrack.h:315: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htstools.c:151: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htstools.c:158: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htstools.c:161: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htstools.c:166: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htstools.c:174: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htstools.c:177: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htstools.c:188: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htstools.c:243: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htstools.c:245: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htstools.c:248: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htstools.c:257: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htstools.c:647: Warning:old style assignment ambiguity in "=*". Assuming "= *" indent: ./src/htsbauth.c:364: Warning:old style assignment ambiguity in "=&". Assuming "= &" indent: ./src/htsbauth.c:387: Warning:old style assignment ambiguity in "=&". Assuming "= &" indent: ./src/htscache.c:473: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htsserver.h:112: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htsserver.h:187: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htsjava.c:312: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htsjava.c:379: Warning:old style assignment ambiguity in "=&". Assuming "= &" indent: ./src/htsjava.c:407: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htsjava.c:472: Warning:old style assignment ambiguity in "=&". Assuming "= &" indent: ./src/htsjava.c:483: Warning:old style assignment ambiguity in "=*". Assuming "= *" indent: ./src/htslib.c:593: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htslib.c:809: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htslib.c:1743: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htslib.c:1874: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htslib.c:1896: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htslib.c:1984: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htslib.c:2085: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htslib.c:2604: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htslib.c:2605: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htslib.c:2606: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htslib.c:2607: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htslib.c:2608: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htslib.c:2609: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htslib.c:2672: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htslib.c:2673: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htslib.c:2906: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htslib.c:2928: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htslib.c:2996: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htslib.c:4802: Warning:old style assignment ambiguity in "=&". Assuming "= &" indent: ./src/htslib.c:5353: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htslib.c:5354: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htslib.c:5355: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htslib.c:5357: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htslib.c:5429: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htslib.c:5435: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htscore.c:208: Warning:old style assignment ambiguity in "=&". Assuming "= &" indent: ./src/htscore.c:277: Warning:old style assignment ambiguity in "=&". Assuming "= &" indent: ./src/htscore.c:279: Warning:old style assignment ambiguity in "=&". Assuming "= &" indent: ./src/htscore.c:357: Warning:old style assignment ambiguity in "=*". Assuming "= *" indent: ./src/htscore.c:394: Warning:old style assignment ambiguity in "=*". Assuming "= *" indent: ./src/htscore.c:1544: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htscore.c:3330: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htscore.c:3361: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htshash.c:140: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htshash.c:217: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htsname.c:733: Warning:old style assignment ambiguity in "=*". Assuming "= *" indent: ./src/htsname.c:749: Warning:old style assignment ambiguity in "=*". Assuming "= *" indent: ./src/htsname.c:933: Warning:old style assignment ambiguity in "=*". Assuming "= *" indent: ./src/htsname.c:1520: Warning:old style assignment ambiguity in "=*". Assuming "= *" indent: ./src/htszlib.c:76: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htszlib.c:81: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htscatchurl.c:268: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htsinthash.c:156: Warning:old style assignment ambiguity in "=&". Assuming "= &" indent: ./src/htsinthash.c:159: Warning:old style assignment ambiguity in "=&". Assuming "= &" indent: ./src/htsinthash.c:176: Warning:old style assignment ambiguity in "=&". Assuming "= &" indent: ./src/htsinthash.c:179: Warning:old style assignment ambiguity in "=&". Assuming "= &" indent: ./src/htsinthash.c:226: Warning:old style assignment ambiguity in "=&". Assuming "= &" indent: ./src/htsinthash.c:253: Warning:old style assignment ambiguity in "=&". Assuming "= &" indent: ./src/htsftp.c:169: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htsftp.c:177: Warning:old style assignment ambiguity in "=-". Assuming "= -" indent: ./src/htsfilters.c:67: Warning:old style assignment ambiguity in "=*". Assuming "= *" indent: ./src/htsfilters.c:80: Warning:old style assignment ambiguity in "=*". Assuming "= *"
Diffstat (limited to 'src/htsserver.c')
-rw-r--r--src/htsserver.c1090
1 files changed, 605 insertions, 485 deletions
diff --git a/src/htsserver.c b/src/htsserver.c
index 39522dd..01562d7 100644
--- a/src/htsserver.c
+++ b/src/htsserver.c
@@ -17,30 +17,26 @@ You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
Important notes:
- We hereby ask people using this source NOT to use it in purpose of grabbing
emails addresses, or collecting any other private information on persons.
This would disgrace our work, and spoil the many hours we spent on it.
-
Please visit our Website: http://www.httrack.com
*/
-
/* ------------------------------------------------------------ */
/* File: Mini-server */
/* Author: Xavier Roche */
/* ------------------------------------------------------------ */
-
/* specific definitions */
/* specific definitions */
/* Bypass internal definition protection */
#define HTS_INTERNAL_BYTECODE
- #include "htsbase.h"
+#include "htsbase.h"
#undef HTS_INTERNAL_BYTECODE
#include "htsnet.h"
@@ -72,96 +68,95 @@ Please visit our Website: http://www.httrack.com
/* Bypass internal definition protection */
#define HTS_INTERNAL_BYTECODE
- #include "htsinthash.h"
+#include "htsinthash.h"
#undef HTS_INTERNAL_BYTECODE
-int NewLangStrSz=1024;
-inthash NewLangStr=NULL;
-int NewLangStrKeysSz=1024;
-inthash NewLangStrKeys=NULL;
-int NewLangListSz=1024;
-inthash NewLangList=NULL;
+int NewLangStrSz = 1024;
+inthash NewLangStr = NULL;
+int NewLangStrKeysSz = 1024;
+inthash NewLangStrKeys = NULL;
+int NewLangListSz = 1024;
+inthash NewLangList = NULL;
+
/* Language files */
#include "htsserver.h"
-char* gethomedir(void);
+char *gethomedir(void);
int commandRunning = 0;
int commandEndRequested = 0;
int commandEnd = 0;
int commandReturn = 0;
-char* commandReturnMsg = NULL;
-char* commandReturnCmdl = NULL;
+char *commandReturnMsg = NULL;
+char *commandReturnCmdl = NULL;
int commandReturnSet = 0;
httrackp *global_opt = NULL;
/* Extern */
-extern void webhttrack_main(char* cmd);
+extern void webhttrack_main(char *cmd);
extern void webhttrack_lock(void);
extern void webhttrack_release(void);
-static int is_image(char* file) {
- return ( (strstr(file, ".gif") != NULL) );
+static int is_image(char *file) {
+ return ((strstr(file, ".gif") != NULL));
}
-static int is_text(char* file) {
- return ( (strstr(file, ".txt") != NULL) );
+static int is_text(char *file) {
+ return ((strstr(file, ".txt") != NULL));
}
-static int is_html(char* file) {
- return ( (strstr(file, ".htm") != NULL) );
+static int is_html(char *file) {
+ return ((strstr(file, ".htm") != NULL));
}
-static void sig_brpipe( int code ) {
+static void sig_brpipe(int code) {
/* ignore */
}
static int check_readinput_t(T_SOC soc, int timeout);
-static int recv_bl(T_SOC soc, void* buffer, size_t len, int timeout);
-static int linputsoc(T_SOC soc, char* s, int max);
-static int check_readinput(htsblk* r);
-static int linputsoc_t(T_SOC soc, char* s, int max, int timeout);
-
-
-static int linput(FILE* fp,char* s,int max);
+static int recv_bl(T_SOC soc, void *buffer, size_t len, int timeout);
+static int linputsoc(T_SOC soc, char *s, int max);
+static int check_readinput(htsblk * r);
+static int linputsoc_t(T_SOC soc, char *s, int max, int timeout);
+static int linput(FILE * fp, char *s, int max);
// URL Link catcher
// 0- Init the URL catcher with standard port
// smallserver_init(&port,&return_host);
-T_SOC smallserver_init_std(int* port_prox, char* adr_prox, int defaultPort) {
- T_SOC soc;
- if (defaultPort <= 0) {
- int try_to_listen_to[]={8080,8081,8082,8083,8084,8085,8086,8087,8088,8089,
- 32000,32001,32002,32003,32004,32006,32006,32007,32008,32009,
- 42000,42001,42002,42003,42004,42006,42006,42007,42008,42009,
- 0,-1};
- int i=0;
- do {
- soc=smallserver_init(&try_to_listen_to[i],adr_prox);
- *port_prox=try_to_listen_to[i];
- i++;
- } while( (soc == INVALID_SOCKET) && (try_to_listen_to[i]>=0));
- } else {
- soc=smallserver_init(&defaultPort, adr_prox);
- *port_prox = defaultPort;
- }
- return soc;
-}
+T_SOC smallserver_init_std(int *port_prox, char *adr_prox, int defaultPort) {
+ T_SOC soc;
+
+ if (defaultPort <= 0) {
+ int try_to_listen_to[] =
+ { 8080, 8081, 8082, 8083, 8084, 8085, 8086, 8087, 8088, 8089,
+ 32000, 32001, 32002, 32003, 32004, 32006, 32006, 32007, 32008, 32009,
+ 42000, 42001, 42002, 42003, 42004, 42006, 42006, 42007, 42008, 42009,
+ 0, -1
+ };
+ int i = 0;
+ do {
+ soc = smallserver_init(&try_to_listen_to[i], adr_prox);
+ *port_prox = try_to_listen_to[i];
+ i++;
+ } while((soc == INVALID_SOCKET) && (try_to_listen_to[i] >= 0));
+ } else {
+ soc = smallserver_init(&defaultPort, adr_prox);
+ *port_prox = defaultPort;
+ }
+ return soc;
+}
// 1- Init the URL catcher
// smallserver_init(&port,&return_host);
-T_SOC smallserver_init(int* port,char* adr) {
+T_SOC smallserver_init(int *port, char *adr) {
T_SOC soc = INVALID_SOCKET;
- char h_loc[256+2];
-
- commandRunning =
- commandEnd =
- commandReturn =
- commandReturnSet =
+ char h_loc[256 + 2];
+
+ commandRunning = commandEnd = commandReturn = commandReturnSet =
commandEndRequested = 0;
if (commandReturnMsg)
free(commandReturnMsg);
@@ -170,62 +165,64 @@ T_SOC smallserver_init(int* port,char* adr) {
free(commandReturnCmdl);
commandReturnCmdl = NULL;
- if (gethostname(h_loc,256)==0) { // host name
+ if (gethostname(h_loc, 256) == 0) { // host name
SOCaddr server;
- int server_size=sizeof(server);
+ int server_size = sizeof(server);
+
/*t_hostent* hp_loc;
- t_fullhostent buffer;*/
+ t_fullhostent buffer; */
// effacer structure
memset(&server, 0, sizeof(server));
-
- /*if ( (hp_loc=vxgethostbyname(h_loc, &buffer)) )*/ { // notre host
+
+ /*if ( (hp_loc=vxgethostbyname(h_loc, &buffer)) ) */ {
+ // notre host
// copie adresse
// NO (bind all)
// SOCaddr_copyaddr(server, server_size, hp_loc->h_addr_list[0], hp_loc->h_length);
- SOCaddr_initany(server, server_size);
- if ( (soc = (T_SOC) socket(SOCaddr_sinfamily(server), SOCK_STREAM, 0)) != INVALID_SOCKET) {
+ SOCaddr_initany(server, server_size);
+ if ((soc =
+ (T_SOC) socket(SOCaddr_sinfamily(server), SOCK_STREAM,
+ 0)) != INVALID_SOCKET) {
SOCaddr_initport(server, *port);
- if ( bind(soc,(struct sockaddr*) &server, server_size) == 0 ) {
+ if (bind(soc, (struct sockaddr *) &server, server_size) == 0) {
/*SOClen len;
- SOCaddr server2;
- len=sizeof(server2);*/
+ SOCaddr server2;
+ len=sizeof(server2); */
// effacer structure
/*memset(&server2, 0, sizeof(server2));
- if (getsockname(soc,(struct sockaddr*) &server2,&len) == 0) {
- *port=ntohs(SOCaddr_sinport(server)); // récupérer port*/
- if (listen(soc,10)>=0) { // au pif le 10
- // SOCaddr_inetntoa(adr, 128, server2, len);
- strcpy(adr, h_loc);
- } else {
-#ifdef _WIN32
- closesocket(soc);
-#else
- close(soc);
-#endif
- soc=INVALID_SOCKET;
- }
-
-
- /*} else {
+ if (getsockname(soc,(struct sockaddr*) &server2,&len) == 0) {
+ *port=ntohs(SOCaddr_sinport(server)); // récupérer port */
+ if (listen(soc, 10) >= 0) { // au pif le 10
+ // SOCaddr_inetntoa(adr, 128, server2, len);
+ strcpy(adr, h_loc);
+ } else {
#ifdef _WIN32
closesocket(soc);
#else
close(soc);
#endif
- soc=INVALID_SOCKET;
- }*/
-
-
+ soc = INVALID_SOCKET;
+ }
+
+ /*} else {
+ #ifdef _WIN32
+ closesocket(soc);
+ #else
+ close(soc);
+ #endif
+ soc=INVALID_SOCKET;
+ } */
+
} else {
#ifdef _WIN32
closesocket(soc);
#else
close(soc);
#endif
- soc=INVALID_SOCKET;
+ soc = INVALID_SOCKET;
}
}
}
@@ -235,7 +232,6 @@ T_SOC smallserver_init(int* port,char* adr) {
// 2 - Wait for URL
-
// check if data is available
// smallserver
@@ -244,12 +240,12 @@ T_SOC smallserver_init(int* port,char* adr) {
// data: 32Kb
typedef struct {
- char* name;
+ char *name;
int value;
} initIntElt;
typedef struct {
- char* name;
- char* value;
+ char *name;
+ char *value;
} initStrElt;
#define SET_ERROR(err) do { \
@@ -257,23 +253,24 @@ typedef struct {
error_redirect = "/server/error.html"; \
} while(0)
-int smallserver(T_SOC soc,char* url,char* method,char* data, char* path) {
- int timeout=30;
- int retour=0;
- int willexit=0;
+int smallserver(T_SOC soc, char *url, char *method, char *data, char *path) {
+ int timeout = 30;
+ int retour = 0;
+ int willexit = 0;
int buffer_size = 32768;
- char* buffer = (char*)malloc(buffer_size);
+ char *buffer = (char *) malloc(buffer_size);
String headers = STRING_EMPTY;
String output = STRING_EMPTY;
String tmpbuff = STRING_EMPTY;
String tmpbuff2 = STRING_EMPTY;
String fspath = STRING_EMPTY;
- char catbuff[CATBUFF_SIZE];
+ char catbuff[CATBUFF_SIZE];
/* Load strings */
htslang_init();
if (!htslang_load(NULL, path)) {
- fprintf(stderr, "unable to find lang.def and/or lang/ strings in %s\n", path);
+ fprintf(stderr, "unable to find lang.def and/or lang/ strings in %s\n",
+ path);
return 0;
}
LANG_T(path, 0);
@@ -281,46 +278,52 @@ int smallserver(T_SOC soc,char* url,char* method,char* data, char* path) {
/* Init various values */
{
char pth[1024];
- char* initOn[] = { "parseall", "Cache", "ka",
- "cookies", "parsejava", "testall", "updhack", "urlhack", "index", NULL };
+
+ char *initOn[] = { "parseall", "Cache", "ka",
+ "cookies", "parsejava", "testall", "updhack", "urlhack", "index", NULL
+ };
initIntElt initInt[] = {
- { "filter", 4 },
- { "travel", 2 },
- { "travel2", 1 },
- { "travel3", 1 },
+ {"filter", 4},
+ {"travel", 2},
+ {"travel2", 1},
+ {"travel3", 1},
/* */
- { "connexion", 4 },
+ {"connexion", 4},
/* */
- { "maxrate", 25000 },
+ {"maxrate", 25000},
/* */
- { "build", 1 },
+ {"build", 1},
/* */
- { "checktype", 2},
- { "robots", 3 },
+ {"checktype", 2},
+ {"robots", 3},
- { NULL, 0 }
+ {NULL, 0}
};
initStrElt initStr[] = {
- { "user", "Mozilla/4.5 (compatible; HTTrack 3.0x; Windows 98)" },
- { "footer", "<!-- Mirrored from %s%s by HTTrack Website Copier/3.x [XR&CO'2013], %s -->" },
- { "url2", "+*.png +*.gif +*.jpg +*.css +*.js -ad.doubleclick.net/*" },
- { NULL, NULL }
+ {"user", "Mozilla/4.5 (compatible; HTTrack 3.0x; Windows 98)"},
+ {"footer",
+ "<!-- Mirrored from %s%s by HTTrack Website Copier/3.x [XR&CO'2013], %s -->"},
+ {"url2", "+*.png +*.gif +*.jpg +*.css +*.js -ad.doubleclick.net/*"},
+ {NULL, NULL}
};
int i = 0;
- for(i = 0 ; initInt[i].name ; i++) {
+
+ for(i = 0; initInt[i].name; i++) {
char tmp[32];
+
sprintf(tmp, "%d", initInt[i].value);
- inthash_write(NewLangList, initInt[i].name, (intptr_t)strdup(tmp));
+ inthash_write(NewLangList, initInt[i].name, (intptr_t) strdup(tmp));
}
- for(i = 0 ; initOn[i] ; i++) {
- inthash_write(NewLangList, initOn[i], (intptr_t)strdup("1")); /* "on" */
+ for(i = 0; initOn[i]; i++) {
+ inthash_write(NewLangList, initOn[i], (intptr_t) strdup("1")); /* "on" */
}
- for(i = 0 ; initStr[i].name ; i++) {
- inthash_write(NewLangList, initStr[i].name, (intptr_t)strdup(initStr[i].value));
+ for(i = 0; initStr[i].name; i++) {
+ inthash_write(NewLangList, initStr[i].name,
+ (intptr_t) strdup(initStr[i].value));
}
strcpybuff(pth, gethomedir());
strcatbuff(pth, "/websites");
- inthash_write(NewLangList, "path", (intptr_t)strdup(pth));
+ inthash_write(NewLangList, "path", (intptr_t) strdup(pth));
}
/* Lock */
@@ -333,7 +336,7 @@ int smallserver(T_SOC soc,char* url,char* method,char* data, char* path) {
char line2[1024];
T_SOC soc_c;
LLint length = 0;
- char* error_redirect = NULL;
+ char *error_redirect = NULL;
line[0] = '\0';
buffer[0] = '\0';
@@ -353,22 +356,23 @@ int smallserver(T_SOC soc,char* url,char* method,char* data, char* path) {
/* sigpipe */
#ifndef _WIN32
- signal( SIGPIPE , sig_brpipe );
+ signal(SIGPIPE, sig_brpipe);
#endif
/* Accept */
- while ( (soc_c = (T_SOC) accept(soc, NULL, NULL)) == INVALID_SOCKET);
+ while((soc_c = (T_SOC) accept(soc, NULL, NULL)) == INVALID_SOCKET) ;
/* Lock */
webhttrack_lock();
- if(linputsoc_t(soc_c, line1, sizeof(line1) - 2, timeout) > 0) {
+ if (linputsoc_t(soc_c, line1, sizeof(line1) - 2, timeout) > 0) {
int meth = 0;
+
if (strfield(line1, "get ")) {
meth = 1;
} else if (strfield(line1, "post ")) {
meth = 2;
- } else if (strfield(line1, "head ")) { /* yes, we can do that */
+ } else if (strfield(line1, "head ")) { /* yes, we can do that */
meth = 10;
} else {
#ifdef _DEBUG
@@ -380,25 +384,29 @@ int smallserver(T_SOC soc,char* url,char* method,char* data, char* path) {
length = buffer_size - 2;
while(linputsoc_t(soc_c, line, sizeof(line) - 2, timeout) > 0) {
int p;
- if ((p=strfield(line,"Content-length:"))!=0) {
- sscanf(line+p, LLintP, &(length));
- }
- else if ((p=strfield(line,"Accept-language:"))!=0) {
+
+ if ((p = strfield(line, "Content-length:")) != 0) {
+ sscanf(line + p, LLintP, &(length));
+ } else if ((p = strfield(line, "Accept-language:")) != 0) {
char tmp[32];
- char* s = line + p;
- /*int l;*/
- while(*s == ' ') s++;
+ char *s = line + p;
+
+ /*int l; */
+ while(*s == ' ')
+ s++;
tmp[0] = '\0';
strncatbuff(tmp, s, 2);
- /*l = LANG_SEARCH(path, tmp);*/
+ /*l = LANG_SEARCH(path, tmp); */
}
}
if (meth == 2) {
int sz = 0;
+
if (length > buffer_size - 2) {
length = buffer_size - 2;
}
- if (length > 0 && (sz=recv_bl(soc_c, buffer, (int)length, timeout)) < 0) {
+ if (length > 0
+ && (sz = recv_bl(soc_c, buffer, (int) length, timeout)) < 0) {
meth = 0;
} else {
buffer[sz] = '\0';
@@ -411,52 +419,59 @@ int smallserver(T_SOC soc,char* url,char* method,char* data, char* path) {
commandReturnSet = 1;
if (commandReturn) {
char tmp[32];
+
sprintf(tmp, "%d", commandReturn);
- inthash_write(NewLangList, "commandReturn", (intptr_t)strdup(tmp));
- inthash_write(NewLangList, "commandReturnMsg", (intptr_t)commandReturnMsg);
- inthash_write(NewLangList, "commandReturnCmdl", (intptr_t)commandReturnCmdl);
+ inthash_write(NewLangList, "commandReturn", (intptr_t) strdup(tmp));
+ inthash_write(NewLangList, "commandReturnMsg",
+ (intptr_t) commandReturnMsg);
+ inthash_write(NewLangList, "commandReturnCmdl",
+ (intptr_t) commandReturnCmdl);
} else {
- inthash_write(NewLangList, "commandReturn", (intptr_t)NULL);
- inthash_write(NewLangList, "commandReturnMsg", (intptr_t)NULL);
- inthash_write(NewLangList, "commandReturnCmdl", (intptr_t)NULL);
+ inthash_write(NewLangList, "commandReturn", (intptr_t) NULL);
+ inthash_write(NewLangList, "commandReturnMsg", (intptr_t) NULL);
+ inthash_write(NewLangList, "commandReturnCmdl", (intptr_t) NULL);
}
}
/* SID check */
{
intptr_t adr = 0;
+
if (inthash_readptr(NewLangList, "_sid", &adr)) {
- if (inthash_write(NewLangList, "sid", (intptr_t)strdup((char*)adr))) {
+ if (inthash_write
+ (NewLangList, "sid", (intptr_t) strdup((char *) adr))) {
}
}
}
/* check variables */
if (meth && buffer[0]) {
- char* s = buffer;
+ char *s = buffer;
char *e, *f;
+
strcatbuff(buffer, "&");
- while( s && (e = strchr(s, '=')) && (f = strchr(s, '&')) ) {
- char* ua;
+ while(s && (e = strchr(s, '=')) && (f = strchr(s, '&'))) {
+ char *ua;
String sua = STRING_EMPTY;
+
*e = *f = '\0';
ua = e + 1;
- if (strfield2(ua, "on")) /* hack : "on" == 1 */
+ if (strfield2(ua, "on")) /* hack : "on" == 1 */
ua = "1";
unescapehttp(ua, &sua);
- inthash_write(NewLangList, s, (intptr_t)StringAcquire(&sua));
+ inthash_write(NewLangList, s, (intptr_t) StringAcquire(&sua));
s = f + 1;
}
}
-
/* Error check */
{
intptr_t adr = 0;
intptr_t adr2 = 0;
+
if (inthash_readptr(NewLangList, "sid", &adr)) {
if (inthash_readptr(NewLangList, "_sid", &adr2)) {
- if (strcmp((char*)adr, (char*)adr2) != 0) {
+ if (strcmp((char *) adr, (char *) adr2) != 0) {
meth = 0;
}
}
@@ -465,57 +480,65 @@ int smallserver(T_SOC soc,char* url,char* method,char* data, char* path) {
/* Check variables (internal) */
if (meth) {
- int doLoad=0;
+ int doLoad = 0;
intptr_t adr = 0;
+
if (inthash_readptr(NewLangList, "lang", &adr)) {
int n = 0;
- if (sscanf((char*)adr, "%d", &n) == 1 && n > 0 && n - 1 != LANG_T(path, -1)) {
+
+ if (sscanf((char *) adr, "%d", &n) == 1 && n > 0
+ && n - 1 != LANG_T(path, -1)) {
LANG_T(path, n - 1);
/* make a backup, because the GUI will override it */
- inthash_write(NewLangList, "lang_", (intptr_t)strdup((char*)adr));
+ inthash_write(NewLangList, "lang_",
+ (intptr_t) strdup((char *) adr));
}
}
/* Load existing project settings */
if (inthash_readptr(NewLangList, "loadprojname", &adr)) {
- char* pname = (char*) adr;
+ char *pname = (char *) adr;
+
if (*pname) {
- inthash_write(NewLangList, "projname", (intptr_t)strdup(pname));
+ inthash_write(NewLangList, "projname", (intptr_t) strdup(pname));
}
- inthash_write(NewLangList, "loadprojname", (intptr_t)NULL);
- doLoad=1;
- }
- else if (inthash_readptr(NewLangList, "loadprojcateg", &adr)) {
- char* pname = (char*) adr;
+ inthash_write(NewLangList, "loadprojname", (intptr_t) NULL);
+ doLoad = 1;
+ } else if (inthash_readptr(NewLangList, "loadprojcateg", &adr)) {
+ char *pname = (char *) adr;
+
if (*pname) {
- inthash_write(NewLangList, "projcateg", (intptr_t)strdup(pname));
+ inthash_write(NewLangList, "projcateg", (intptr_t) strdup(pname));
}
- inthash_write(NewLangList, "loadprojcateg", (intptr_t)NULL);
+ inthash_write(NewLangList, "loadprojcateg", (intptr_t) NULL);
}
-
+
/* intial configuration */
{
if (!inthash_read(NewLangList, "conf_file_loaded", NULL)) {
- inthash_write(NewLangList, "conf_file_loaded", (intptr_t)strdup("true"));
+ inthash_write(NewLangList, "conf_file_loaded",
+ (intptr_t) strdup("true"));
doLoad = 2;
}
}
-
+
/* path : <path>/<project> */
if (!commandRunning) {
intptr_t adrpath = 0, adrprojname = 0;
+
if (inthash_readptr(NewLangList, "path", &adrpath)
- && inthash_readptr(NewLangList, "projname", &adrprojname)) {
+ && inthash_readptr(NewLangList, "projname", &adrprojname)) {
StringClear(fspath);
- StringCat(fspath, (char*)adrpath);
+ StringCat(fspath, (char *) adrpath);
StringCat(fspath, "/");
- StringCat(fspath, (char*)adrprojname);
+ StringCat(fspath, (char *) adrprojname);
}
}
-
+
/* Load existing project settings */
if (doLoad) {
- FILE* fp;
+ FILE *fp;
+
if (doLoad == 1) {
StringCat(fspath, "/hts-cache/winprofile.ini");
} else if (doLoad == 2) {
@@ -530,85 +553,96 @@ int smallserver(T_SOC soc,char* url,char* method,char* data, char* path) {
if (fp) {
/* Read file */
while(!feof(fp)) {
- char* str = line;
- char* pos;
+ char *str = line;
+ char *pos;
+
if (!linput(fp, line, sizeof(line) - 2)) {
*str = '\0';
}
- pos=strchr(line, '=');
+ pos = strchr(line, '=');
if (pos) {
String escline = STRING_EMPTY;
- *pos++='\0';
+
+ *pos++ = '\0';
if (pos[0] == '0' && pos[1] == '\0')
- *pos = '\0'; /* 0 => empty */
+ *pos = '\0'; /* 0 => empty */
unescapeini(pos, &escline);
- inthash_write(NewLangList, line, (intptr_t)StringAcquire(&escline));
+ inthash_write(NewLangList, line,
+ (intptr_t) StringAcquire(&escline));
}
}
-
+
fclose(fp);
}
}
-
+
}
/* Execute command */
{
intptr_t adr = 0;
int p = 0;
+
if (inthash_readptr(NewLangList, "command", &adr)) {
- if (strcmp((char*)adr, "cancel") == 0) {
+ if (strcmp((char *) adr, "cancel") == 0) {
if (commandRunning) {
if (!commandEndRequested) {
- commandEndRequested=1;
+ commandEndRequested = 1;
hts_request_stop(global_opt, 0);
} else {
- hts_request_stop(global_opt, 1); /* note: the force flag does not have anyeffect yet */
- commandEndRequested=2; /* will break the loop() callback */
+ hts_request_stop(global_opt, 1); /* note: the force flag does not have anyeffect yet */
+ commandEndRequested = 2; /* will break the loop() callback */
}
}
- } else if ((p=strfield((char*)adr, "cancel-file="))) {
+ } else if ((p = strfield((char *) adr, "cancel-file="))) {
if (commandRunning) {
- hts_cancel_file_push(global_opt, (char*)adr + p);
+ hts_cancel_file_push(global_opt, (char *) adr + p);
}
- } else if (strcmp((char*)adr, "cancel-parsing") == 0) {
+ } else if (strcmp((char *) adr, "cancel-parsing") == 0) {
if (commandRunning) {
hts_cancel_parsing(global_opt);
}
- } else if ((p=strfield((char*)adr, "pause="))) {
+ } else if ((p = strfield((char *) adr, "pause="))) {
if (commandRunning) {
hts_setpause(global_opt, 1);
}
- } else if ((p=strfield((char*)adr, "unpause"))) {
+ } else if ((p = strfield((char *) adr, "unpause"))) {
if (commandRunning) {
hts_setpause(global_opt, 0);
}
- } else if (strcmp((char*)adr, "abort") == 0) {
+ } else if (strcmp((char *) adr, "abort") == 0) {
if (commandRunning) {
hts_request_stop(global_opt, 1);
- commandEndRequested=2; /* will break the loop() callback */
+ commandEndRequested = 2; /* will break the loop() callback */
}
- } else if ((p=strfield((char*)adr, "add-url="))) {
+ } else if ((p = strfield((char *) adr, "add-url="))) {
if (commandRunning) {
- char* ptraddr[2];
- ptraddr[0] = (char*)adr + p;
+ char *ptraddr[2];
+
+ ptraddr[0] = (char *) adr + p;
ptraddr[1] = NULL;
hts_addurl(global_opt, ptraddr);
}
- } else if ((p=strfield((char*)adr, "httrack"))) {
+ } else if ((p = strfield((char *) adr, "httrack"))) {
if (!commandRunning) {
intptr_t adrcd = 0;
+
if (inthash_readptr(NewLangList, "command_do", &adrcd)) {
intptr_t adrw = 0, adrpath = 0;
+
if (inthash_readptr(NewLangList, "winprofile", &adrw)) {
/* User general profile */
intptr_t adruserprofile = 0;
- if (inthash_readptr(NewLangList, "userprofile", &adruserprofile)
- && adruserprofile != 0) {
- int count = (int) strlen((char*)adruserprofile);
+
+ if (inthash_readptr
+ (NewLangList, "userprofile", &adruserprofile)
+ && adruserprofile != 0) {
+ int count = (int) strlen((char *) adruserprofile);
+
if (count > 0) {
- FILE* fp;
+ FILE *fp;
+
StringClear(tmpbuff);
StringCopy(tmpbuff, gethomedir());
#ifdef _WIN32
@@ -618,87 +652,100 @@ int smallserver(T_SOC soc,char* url,char* method,char* data, char* path) {
#endif
fp = fopen(StringBuff(tmpbuff), "wb");
if (fp != NULL) {
- (void)((int)fwrite((void*)adruserprofile, 1, count, fp));
+ (void) ((int)
+ fwrite((void *) adruserprofile, 1, count, fp));
fclose(fp);
}
}
}
-
+
/* Profile */
StringClear(tmpbuff);
StringCat(tmpbuff, StringBuff(fspath));
StringCat(tmpbuff, "/hts-cache/");
-
+
/* Create minimal directory structure */
if (!structcheck(StringBuff(tmpbuff))) {
- FILE* fp;
+ FILE *fp;
+
StringCat(tmpbuff, "winprofile.ini");
fp = fopen(StringBuff(tmpbuff), "wb");
if (fp != NULL) {
- int count = (int) strlen((char*)adrw);
- if ((int)fwrite((void*)adrw, 1, count, fp) == count) {
-
- /* Wipe the doit.log file, useless here (all options are replicated) and
- even a bit annoying (duplicate/ghost options)
- The behaviour is exactly the same as in WinHTTrack
- */
+ int count = (int) strlen((char *) adrw);
+
+ if ((int) fwrite((void *) adrw, 1, count, fp) == count) {
+
+ /* Wipe the doit.log file, useless here (all options are replicated) and
+ even a bit annoying (duplicate/ghost options)
+ The behaviour is exactly the same as in WinHTTrack
+ */
StringClear(tmpbuff);
StringCat(tmpbuff, StringBuff(fspath));
StringCat(tmpbuff, "/hts-cache/doit.log");
remove(StringBuff(tmpbuff));
-
+
/*
- RUN THE SERVER
- */
- if (strcmp((char*)adrcd, "start") == 0) {
- webhttrack_main((char*)adr + p);
+ RUN THE SERVER
+ */
+ if (strcmp((char *) adrcd, "start") == 0) {
+ webhttrack_main((char *) adr + p);
} else {
commandRunning = 0;
commandEnd = 1;
}
} else {
char tmp[1024];
- sprintf(tmp, "Unable to write %d bytes in the the init file %s", count, StringBuff(fspath));
+
+ sprintf(tmp,
+ "Unable to write %d bytes in the the init file %s",
+ count, StringBuff(fspath));
SET_ERROR(tmp);
}
fclose(fp);
} else {
char tmp[1024];
- sprintf(tmp, "Unable to create the init file %s", StringBuff(fspath));
+
+ sprintf(tmp, "Unable to create the init file %s",
+ StringBuff(fspath));
SET_ERROR(tmp);
}
} else {
char tmp[1024];
- sprintf(tmp, "Unable to create the directory structure in %s", StringBuff(fspath));
+
+ sprintf(tmp,
+ "Unable to create the directory structure in %s",
+ StringBuff(fspath));
SET_ERROR(tmp);
}
-
+
} else {
- SET_ERROR("Internal server error: unable to fetch project name or path");
+ SET_ERROR
+ ("Internal server error: unable to fetch project name or path");
}
}
}
- } else if (strcmp((char*)adr, "quit") == 0) {
- willexit=1;
+ } else if (strcmp((char *) adr, "quit") == 0) {
+ willexit = 1;
}
- inthash_write(NewLangList, "command", (intptr_t)NULL);
+ inthash_write(NewLangList, "command", (intptr_t) NULL);
}
}
/* Response */
if (meth) {
int virtualpath = 0;
- char* pos;
- char* url = strchr(line1, ' ');
- if (url && *++url == '/' && (pos = strchr(url, ' ')) && !(*pos = '\0') ) {
+ char *pos;
+ char *url = strchr(line1, ' ');
+
+ if (url && *++url == '/' && (pos = strchr(url, ' ')) && !(*pos = '\0')) {
char fsfile[1024];
- char* file;
- FILE* fp;
- char* qpos;
+ char *file;
+ FILE *fp;
+ char *qpos;
/* get the URL */
if (error_redirect == NULL) {
- if ( (qpos = strchr(url, '?')) ) {
+ if ((qpos = strchr(url, '?'))) {
*qpos = '\0';
}
fsfile[0] = '\0';
@@ -712,7 +759,7 @@ int smallserver(T_SOC soc,char* url,char* method,char* data, char* path) {
file = error_redirect;
meth = 2;
}
-
+
if (strncmp(file, "/website/", 9) == 0) {
virtualpath = 1;
}
@@ -726,39 +773,35 @@ int smallserver(T_SOC soc,char* url,char* method,char* data, char* path) {
file = "/server/finished.html";
}
}
-
+
if (strlen(path) + strlen(file) + 32 < sizeof(fsfile)) {
if (strncmp(file, "/website/", 9) != 0) {
sprintf(fsfile, "%shtml%s", path, file);
} else {
intptr_t adr = 0;
+
if (inthash_readptr(NewLangList, "projpath", &adr)) {
- sprintf(fsfile, "%s%s", (char*)adr, file + 9);
+ sprintf(fsfile, "%s%s", (char *) adr, file + 9);
}
}
}
-
- if (fsfile[0] && strstr(file, "..") == NULL && (fp = fopen(fsfile, "rb"))) {
- char ok[] = "HTTP/1.0 200 OK\r\n"
- "Connection: close\r\n"
- "Server: httrack-small-server\r\n"
- "Content-type: text/html\r\n"
+
+ if (fsfile[0] && strstr(file, "..") == NULL
+ && (fp = fopen(fsfile, "rb"))) {
+ char ok[] =
+ "HTTP/1.0 200 OK\r\n" "Connection: close\r\n"
+ "Server: httrack-small-server\r\n" "Content-type: text/html\r\n"
"Cache-Control: no-cache, must-revalidate, private\r\n"
- "Pragma: no-cache\r\n"
- ;
- char ok_img[] = "HTTP/1.0 200 OK\r\n"
- "Connection: close\r\n"
- "Server: httrack small server\r\n"
- "Content-type: image/gif\r\n"
- ;
- char ok_text[] = "HTTP/1.0 200 OK\r\n"
- "Connection: close\r\n"
- "Server: httrack small server\r\n"
- "Content-type: text/plain\r\n"
- ;
+ "Pragma: no-cache\r\n";
+ char ok_img[] =
+ "HTTP/1.0 200 OK\r\n" "Connection: close\r\n"
+ "Server: httrack small server\r\n" "Content-type: image/gif\r\n";
+ char ok_text[] =
+ "HTTP/1.0 200 OK\r\n" "Connection: close\r\n"
+ "Server: httrack small server\r\n" "Content-type: text/plain\r\n";
/* register current page */
- inthash_write(NewLangList, "thisfile", (intptr_t)strdup(file));
+ inthash_write(NewLangList, "thisfile", (intptr_t) strdup(file));
/* Force GET for the last request */
if (meth == 2 && willexit) {
@@ -767,13 +810,15 @@ int smallserver(T_SOC soc,char* url,char* method,char* data, char* path) {
/* posted data are redirected to get protocol */
if (meth == 2) {
- char redir[] = "HTTP/1.0 302 Redirect\r\n"
- "Connection: close\r\n"
+ char redir[] =
+ "HTTP/1.0 302 Redirect\r\n" "Connection: close\r\n"
"Server: httrack-small-server\r\n";
intptr_t adr = 0;
- char* newfile = file;
+ char *newfile = file;
+
if (inthash_readptr(NewLangList, "redirect", &adr) && adr != 0) {
- char* newadr = (char*)adr;
+ char *newadr = (char *) adr;
+
if (*newadr) {
newfile = newadr;
}
@@ -781,20 +826,22 @@ int smallserver(T_SOC soc,char* url,char* method,char* data, char* path) {
StringMemcat(headers, redir, strlen(redir));
{
char tmp[256];
+
if (strlen(file) < sizeof(tmp) - 32) {
sprintf(tmp, "Location: %s\r\n", newfile);
StringMemcat(headers, tmp, strlen(tmp));
}
}
- inthash_write(NewLangList, "redirect", (intptr_t)NULL);
- }
- else if (is_html(file)) {
+ inthash_write(NewLangList, "redirect", (intptr_t) NULL);
+ } else if (is_html(file)) {
int outputmode = 0;
+
StringMemcat(headers, ok, sizeof(ok) - 1);
while(!feof(fp)) {
- char* str = line;
+ char *str = line;
int prevlen = (int) StringLength(output);
int nocr = 0;
+
if (!linput(fp, line, sizeof(line) - 2)) {
*str = '\0';
}
@@ -803,34 +850,34 @@ int smallserver(T_SOC soc,char* url,char* method,char* data, char* path) {
str[strlen(str) - 1] = '\0';
}
while(*str) {
- char* pos;
+ char *pos;
size_t n;
- if (*str == '$' && *++str == '{' && (pos = strchr(++str, '}')) && (n = (pos - str) ) && n < 1024 ) {
+
+ if (*str == '$' && *++str == '{' && (pos = strchr(++str, '}'))
+ && (n = (pos - str)) && n < 1024) {
char name_[1024 + 2];
- char* name = name_;
- char* langstr = NULL;
+ char *name = name_;
+ char *langstr = NULL;
int p;
int format = 0;
int listDefault = 0;
+
name[0] = '\0';
strncatbuff(name, str, n);
if (strncmp(name, "/*", 2) == 0) {
/* comments */
- }
- else if (( p = strfield(name, "html:"))) {
+ } else if ((p = strfield(name, "html:"))) {
name += p;
format = 1;
- }
- else if (( p = strfield(name, "list:"))) {
+ } else if ((p = strfield(name, "list:"))) {
name += p;
format = 2;
- }
- else if (( p = strfield(name, "liststr:"))) {
+ } else if ((p = strfield(name, "liststr:"))) {
name += p;
format = -2;
- }
- else if (( p = strfield(name, "file-exists:"))) {
- char* pos2;
+ } else if ((p = strfield(name, "file-exists:"))) {
+ char *pos2;
+
name += p;
format = 0;
pos2 = strchr(name, ':');
@@ -843,9 +890,9 @@ int smallserver(T_SOC soc,char* url,char* method,char* data, char* path) {
}
}
}
- }
- else if (( p = strfield(name, "do:"))) {
- char* pos2;
+ } else if ((p = strfield(name, "do:"))) {
+ char *pos2;
+
name += p;
format = 1;
pos2 = strchr(name, ':');
@@ -854,15 +901,15 @@ int smallserver(T_SOC soc,char* url,char* method,char* data, char* path) {
*pos2 = '\0';
pos2++;
} else {
- pos2="";
+ pos2 = "";
}
if (strcmp(name, "output-mode") == 0) {
if (strcmp(pos2, "html") == 0) {
outputmode = 1;
} else if (strcmp(pos2, "inifile") == 0) {
- outputmode = 2;
+ outputmode = 2;
} else if (strcmp(pos2, "html-urlescaped") == 0) {
- outputmode = 3;
+ outputmode = 3;
} else {
outputmode = 0;
}
@@ -874,7 +921,8 @@ int smallserver(T_SOC soc,char* url,char* method,char* data, char* path) {
}
} else if (strcmp(name, "if-project-file-exists") == 0) {
if (strstr(pos2, "..") == NULL) {
- if (!fexist(fconcat(catbuff, StringBuff(fspath), pos2))) {
+ if (!fexist
+ (fconcat(catbuff, StringBuff(fspath), pos2))) {
outputmode = -1;
}
}
@@ -886,106 +934,125 @@ int smallserver(T_SOC soc,char* url,char* method,char* data, char* path) {
}
} else if (strcmp(name, "if-not-empty") == 0) {
intptr_t adr = 0;
- if (!inthash_readptr(NewLangList, pos2, &adr) || *((char*)adr) == 0 ) {
+
+ if (!inthash_readptr(NewLangList, pos2, &adr)
+ || *((char *) adr) == 0) {
outputmode = -1;
}
} else if (strcmp(name, "if-empty") == 0) {
intptr_t adr = 0;
- if (inthash_readptr(NewLangList, pos2, &adr) && *((char*)adr) != 0 ) {
+
+ if (inthash_readptr(NewLangList, pos2, &adr)
+ && *((char *) adr) != 0) {
outputmode = -1;
}
} else if (strcmp(name, "end-if") == 0) {
outputmode = 0;
} else if (strcmp(name, "loadhash") == 0) {
intptr_t adr = 0;
+
if (inthash_readptr(NewLangList, "path", &adr)) {
- char* rpath = (char*) adr;
+ char *rpath = (char *) adr;
+
//find_handle h;
if (rpath[0]) {
- if (rpath[strlen(rpath)-1]=='/') {
- rpath[strlen(rpath)-1]='\0'; /* note: patching stored (inhash) value */
+ if (rpath[strlen(rpath) - 1] == '/') {
+ rpath[strlen(rpath) - 1] = '\0'; /* note: patching stored (inhash) value */
}
}
{
- const char* profiles = hts_getcategories(rpath, 0);
- const char* categ = hts_getcategories(rpath,1 );
- inthash_write(NewLangList, "winprofile", (intptr_t)profiles);
- inthash_write(NewLangList, "wincateg", (intptr_t)categ);
+ const char *profiles = hts_getcategories(rpath, 0);
+ const char *categ = hts_getcategories(rpath, 1);
+
+ inthash_write(NewLangList, "winprofile",
+ (intptr_t) profiles);
+ inthash_write(NewLangList, "wincateg",
+ (intptr_t) categ);
}
- }
+ }
} else if (strcmp(name, "copy") == 0) {
if (*pos2) {
- char* pos3 = strchr(pos2, ':');
- if ( pos3 && *(pos3 + 1) ) {
+ char *pos3 = strchr(pos2, ':');
+
+ if (pos3 && *(pos3 + 1)) {
intptr_t adr = 0;
+
*pos3++ = '\0';
if (inthash_readptr(NewLangList, pos2, &adr)) {
- inthash_write(NewLangList, pos3, (intptr_t)strdup((char*)adr));
- inthash_write(NewLangList, pos2, (intptr_t)NULL);
+ inthash_write(NewLangList, pos3,
+ (intptr_t) strdup((char *) adr));
+ inthash_write(NewLangList, pos2, (intptr_t) NULL);
}
}
}
} else if (strcmp(name, "set") == 0) {
if (*pos2) {
- char* pos3 = strchr(pos2, ':');
- if ( pos3 ) {
+ char *pos3 = strchr(pos2, ':');
+
+ if (pos3) {
*pos3++ = '\0';
- inthash_write(NewLangList, pos2, (intptr_t)strdup(pos3));
+ inthash_write(NewLangList, pos2,
+ (intptr_t) strdup(pos3));
} else {
- inthash_write(NewLangList, pos2, (intptr_t)NULL);
+ inthash_write(NewLangList, pos2, (intptr_t) NULL);
}
}
}
}
/*
- test:<if exist>
- test:<if ==0>:<if ==1>:<if == 2>..
- ztest:<if == 0 || !exist>:<if == 1>:<if == 2>..
- */
- else if ( ( p = strfield(name, "test:")) || ( p = strfield(name, "ztest:")) ) {
+ test:<if exist>
+ test:<if ==0>:<if ==1>:<if == 2>..
+ ztest:<if == 0 || !exist>:<if == 1>:<if == 2>..
+ */
+ else if ((p = strfield(name, "test:"))
+ || (p = strfield(name, "ztest:"))) {
intptr_t adr = 0;
- char* pos2;
+ char *pos2;
int ztest = (name[0] == 'z');
+
langstr = "";
name += p;
pos2 = strchr(name, ':');
if (pos2 != NULL) {
*pos2 = '\0';
if (inthash_readptr(NewLangList, name, &adr) || ztest) {
- char* newadr = (char*)adr;
+ char *newadr = (char *) adr;
+
if (!newadr)
newadr = "";
if (*newadr || ztest) {
int npos = 0;
+
name = pos2 + 1;
format = 4;
if (strchr(name, ':') == NULL) {
- npos = 0; /* first is good if only one : */
+ npos = 0; /* first is good if only one : */
format = 0;
} else {
if (sscanf(newadr, "%d", &npos) != 1) {
if (strfield(newadr, "on")) {
npos = 1;
} else {
- npos = 0; /* first one will be ok */
+ npos = 0; /* first one will be ok */
format = 0;
}
}
}
- while( *name && *name != '}' && npos >= 0) {
- int end=0;
- char* fpos = strchr(name, ':');
+ while(*name && *name != '}' && npos >= 0) {
+ int end = 0;
+ char *fpos = strchr(name, ':');
int n2;
+
if (fpos == NULL) {
fpos = name + strlen(name);
- end=1;
+ end = 1;
}
n2 = (int) (fpos - name);
if (npos == 0) {
langstr = name;
- *fpos='\0';
+ *fpos = '\0';
} else if (end) {
- npos=0;
+ npos = 0;
}
name += n2 + 1;
npos--;
@@ -993,30 +1060,32 @@ int smallserver(T_SOC soc,char* url,char* method,char* data, char* path) {
}
}
}
- }
- else if (( p = strfield(name, "listid:"))) {
- char* pos2;
+ } else if ((p = strfield(name, "listid:"))) {
+ char *pos2;
+
name += p;
format = 2;
pos2 = strchr(name, ':');
if (pos2) {
char dname[32];
int n2 = (int) (pos2 - name);
+
if (n2 > 0 && n2 < sizeof(dname) - 2) {
intptr_t adr = 0;
+
dname[0] = '\0';
strncatbuff(dname, name, n2);
if (inthash_readptr(NewLangList, dname, &adr)) {
int n = 0;
- if (sscanf((char*)adr, "%d", &n) == 1) {
+
+ if (sscanf((char *) adr, "%d", &n) == 1) {
listDefault = n;
}
}
name += n2 + 1;
}
}
- }
- else if (( p = strfield(name, "checked:"))) {
+ } else if ((p = strfield(name, "checked:"))) {
name += p;
format = 3;
}
@@ -1030,24 +1099,29 @@ int smallserver(T_SOC soc,char* url,char* method,char* data, char* path) {
langstr = LANGSEL(name);
if (langstr == NULL || *langstr == '\0') {
intptr_t adr = 0;
+
if (inthash_readptr(NewLangList, name, &adr)) {
- char* newadr = (char*)adr;
+ char *newadr = (char *) adr;
+
langstr = newadr;
}
}
}
}
if (langstr && outputmode != -1) {
- switch(format) {
+ switch (format) {
case 0:
{
- char* a = langstr;
+ char *a = langstr;
+
while(*a) {
- if (a[0] == '\\' && isxdigit(a[1]) && isxdigit(a[2])) {
+ if (a[0] == '\\' && isxdigit(a[1])
+ && isxdigit(a[2])) {
int n;
char c;
- if (sscanf(a+1, "%x", &n) == 1) {
- c = (char)n;
+
+ if (sscanf(a + 1, "%x", &n) == 1) {
+ c = (char) n;
StringMemcat(output, &c, 1);
}
a += 2;
@@ -1059,9 +1133,11 @@ int smallserver(T_SOC soc,char* url,char* method,char* data, char* path) {
StringCat(output, "&amp;");
} else if (outputmode == 3 && a[0] == ' ') {
StringCat(output, "%20");
- } else if (outputmode >= 2 && ((unsigned char)a[0]) < 32) {
+ } else if (outputmode >= 2
+ && ((unsigned char) a[0]) < 32) {
char tmp[32];
- sprintf(tmp, "%%%02x", (unsigned char)a[0]);
+
+ sprintf(tmp, "%%%02x", (unsigned char) a[0]);
StringCat(output, tmp);
} else if (outputmode == 2 && a[0] == '%') {
StringCat(output, "%%");
@@ -1079,10 +1155,11 @@ int smallserver(T_SOC soc,char* url,char* method,char* data, char* path) {
StringCat(output, "checked");
}
break;
- default:
+ default:
if (*langstr) {
- int id=1;
- char* fstr = langstr;
+ int id = 1;
+ char *fstr = langstr;
+
StringClear(tmpbuff);
if (format == 2) {
StringCat(output, "<option value=1>");
@@ -1090,8 +1167,9 @@ int smallserver(T_SOC soc,char* url,char* method,char* data, char* path) {
StringCat(output, "<option value=\"");
}
while(*fstr) {
- switch(*fstr) {
- case 13: break;
+ switch (*fstr) {
+ case 13:
+ break;
case 10:
if (format == 1) {
StringCat(output, StringBuff(tmpbuff));
@@ -1104,6 +1182,7 @@ int smallserver(T_SOC soc,char* url,char* method,char* data, char* path) {
StringCat(output, "<option value=\"");
} else {
char tmp[32];
+
sprintf(tmp, "%d", ++id);
StringCat(output, StringBuff(tmpbuff));
StringCat(output, "</option>\r\n");
@@ -1160,14 +1239,16 @@ int smallserver(T_SOC soc,char* url,char* method,char* data, char* path) {
}
#ifdef _DEBUG
{
- int len = (int)strlen((char*)StringBuff(output));
- assert(len == (int)StringLength(output));
+ int len = (int) strlen((char *) StringBuff(output));
+
+ assert(len == (int) StringLength(output));
}
#endif
} else if (is_text(file)) {
StringMemcat(headers, ok_text, sizeof(ok_text) - 1);
while(!feof(fp)) {
int n = (int) fread(line, 1, sizeof(line) - 2, fp);
+
if (n > 0) {
StringMemcat(output, line, n);
}
@@ -1176,6 +1257,7 @@ int smallserver(T_SOC soc,char* url,char* method,char* data, char* path) {
StringMemcat(headers, ok_img, sizeof(ok_img) - 1);
while(!feof(fp)) {
int n = (int) fread(line, 1, sizeof(line) - 2, fp);
+
if (n > 0) {
StringMemcat(output, line, n);
}
@@ -1183,11 +1265,11 @@ int smallserver(T_SOC soc,char* url,char* method,char* data, char* path) {
}
fclose(fp);
} else {
- char error_hdr[] = "HTTP/1.0 404 Not Found\r\n"
- "Server: httrack small server\r\n"
+ char error_hdr[] =
+ "HTTP/1.0 404 Not Found\r\n" "Server: httrack small server\r\n"
"Content-type: text/html\r\n";
- char error[] =
- "Page not found.\r\n";
+ char error[] = "Page not found.\r\n";
+
StringCat(headers, error_hdr);
StringCat(output, error);
//assert(file == NULL);
@@ -1195,25 +1277,27 @@ int smallserver(T_SOC soc,char* url,char* method,char* data, char* path) {
}
} else {
#ifdef _DEBUG
- char error_hdr[] = "HTTP/1.0 500 Server Error\r\n"
- "Server: httrack small server\r\n"
+ char error_hdr[] =
+ "HTTP/1.0 500 Server Error\r\n" "Server: httrack small server\r\n"
"Content-type: text/html\r\n";
- char error[] =
- "Server error.\r\n";
+ char error[] = "Server error.\r\n";
+
StringCat(headers, error_hdr);
StringCat(output, error);
#endif
}
{
char tmp[256];
+
sprintf(tmp, "Content-length: %d\r\n", (int) StringLength(output));
StringCat(headers, tmp);
}
StringCat(headers, "\r\n");
- if (
- (send(soc_c, StringBuff(headers), (int) StringLength(headers), 0) != StringLength(headers))
- ||
- ( (meth == 1) && (send(soc_c, StringBuff(output), (int) StringLength(output), 0) != StringLength(output)) )
+ if ((send(soc_c, StringBuff(headers), (int) StringLength(headers), 0) !=
+ StringLength(headers))
+ || ((meth == 1)
+ && (send(soc_c, StringBuff(output), (int) StringLength(output), 0)
+ != StringLength(output)))
) {
#ifdef _DEBUG
//assert(FALSE);
@@ -1224,17 +1308,18 @@ int smallserver(T_SOC soc,char* url,char* method,char* data, char* path) {
// assert(FALSE);
#endif
}
-
+
/* Shutdown (FIN) and wait until confirmed */
{
char c;
+
#ifdef _WIN32
shutdown(soc_c, SD_SEND);
#else
shutdown(soc_c, 1);
#endif
/* This is necessary as IE sometimes (!) sends an additional CRLF after POST data */
- while(recv(soc_c, ((char*)&c), 1, 0) > 0);
+ while(recv(soc_c, ((char *) &c), 1, 0) > 0) ;
}
#ifdef _WIN32
@@ -1274,110 +1359,116 @@ int smallserver(T_SOC soc,char* url,char* method,char* data, char* path) {
return retour;
}
-
-
/* Language files */
-
int htslang_init(void) {
- if (NewLangList==NULL) {
- NewLangList=inthash_new(NewLangListSz);
- if (NewLangList==NULL) {
+ if (NewLangList == NULL) {
+ NewLangList = inthash_new(NewLangListSz);
+ if (NewLangList == NULL) {
abortLog("Error in lang.h: not enough memory");
} else {
- inthash_value_is_malloc(NewLangList,1);
+ inthash_value_is_malloc(NewLangList, 1);
}
}
return 1;
}
int htslang_uninit(void) {
- if (NewLangList!=NULL) {
+ if (NewLangList != NULL) {
inthash_delete(&NewLangList);
}
return 1;
}
-int smallserver_setkey(char* key, char* value) {
- return inthash_write(NewLangList, key, (intptr_t)strdup(value));
+int smallserver_setkey(char *key, char *value) {
+ return inthash_write(NewLangList, key, (intptr_t) strdup(value));
}
-int smallserver_setkeyint(char* key, LLint value) {
+int smallserver_setkeyint(char *key, LLint value) {
char tmp[256];
+
sprintf(tmp, LLintP, value);
- return inthash_write(NewLangList, key, (intptr_t)strdup(tmp));
+ return inthash_write(NewLangList, key, (intptr_t) strdup(tmp));
}
-int smallserver_setkeyarr(char* key, int id, char* key2, char* value) {
+int smallserver_setkeyarr(char *key, int id, char *key2, char *value) {
char tmp[256];
+
sprintf(tmp, "%s%d%s", key, id, key2);
- return inthash_write(NewLangList, tmp, (intptr_t)strdup(value));
+ return inthash_write(NewLangList, tmp, (intptr_t) strdup(value));
}
-static int htslang_load(char* limit_to, char* path) {
- char* hashname;
- char catbuff[CATBUFF_SIZE];
+static int htslang_load(char *limit_to, char *path) {
+ char *hashname;
+ char catbuff[CATBUFF_SIZE];
+
//
- int selected_lang=LANG_T(path, -1);
+ int selected_lang = LANG_T(path, -1);
+
//
if (!limit_to) {
LANG_DELETE();
- NewLangStr=inthash_new(NewLangStrSz);
- NewLangStrKeys=inthash_new(NewLangStrKeysSz);
- if ((NewLangStr==NULL) || (NewLangStrKeys==NULL)) {
+ NewLangStr = inthash_new(NewLangStrSz);
+ NewLangStrKeys = inthash_new(NewLangStrKeysSz);
+ if ((NewLangStr == NULL) || (NewLangStrKeys == NULL)) {
abortLog("Error in lang.h: not enough memory");
} else {
- inthash_value_is_malloc(NewLangStr,1);
- inthash_value_is_malloc(NewLangStrKeys,1);
+ inthash_value_is_malloc(NewLangStr, 1);
+ inthash_value_is_malloc(NewLangStrKeys, 1);
}
}
/* Load master file (list of keys and internal keys) */
if (!limit_to) {
- char* mname = "lang.def";
- FILE* fp=fopen(fconcat(catbuff, path, mname),"rb");
+ char *mname = "lang.def";
+ FILE *fp = fopen(fconcat(catbuff, path, mname), "rb");
+
if (fp) {
char intkey[8192];
char key[8192];
+
while(!feof(fp)) {
- linput_cpp(fp,intkey,8000);
- linput_cpp(fp,key,8000);
+ linput_cpp(fp, intkey, 8000);
+ linput_cpp(fp, key, 8000);
if (strnotempty(intkey) && strnotempty(key)) {
- char* test=LANGINTKEY(key);
+ char *test = LANGINTKEY(key);
/* Increment for multiple definitions */
if (strnotempty(test)) {
- int increment=0;
+ int increment = 0;
size_t pos = strlen(key);
+
do {
increment++;
- sprintf(key+pos,"%d",increment);
- test=LANGINTKEY(key);
- } while (strnotempty(test));
+ sprintf(key + pos, "%d", increment);
+ test = LANGINTKEY(key);
+ } while(strnotempty(test));
}
- if (!strnotempty(test)) { // éviter doublons
+ if (!strnotempty(test)) { // éviter doublons
// conv_printf(key,key);
int len;
- char* buff;
+ char *buff;
+
len = (int) strlen(intkey);
- buff=(char*)malloc(len+2);
+ buff = (char *) malloc(len + 2);
if (buff) {
- strcpybuff(buff,intkey);
- inthash_add(NewLangStrKeys,key,(intptr_t)buff);
+ strcpybuff(buff, intkey);
+ inthash_add(NewLangStrKeys, key, (intptr_t) buff);
}
}
- } // if
- } // while
+ } // if
+ } // while
fclose(fp);
} else {
return 0;
}
}
-
+
/* Language Name? */
{
char name[256];
- sprintf(name,"LANGUAGE_%d",selected_lang+1);
- hashname=LANGINTKEY(name);
+
+ sprintf(name, "LANGUAGE_%d", selected_lang + 1);
+ hashname = LANGINTKEY(name);
}
/* Get only language name */
@@ -1396,50 +1487,56 @@ static int htslang_load(char* limit_to, char* path) {
/* Load specific language file */
{
int loops;
+
// 2nd loop: load undefined strings
- for(loops=0;loops<2;loops++) {
- FILE* fp;
+ for(loops = 0; loops < 2; loops++) {
+ FILE *fp;
char lbasename[1024];
+
{
char name[256];
- sprintf(name,"LANGUAGE_%d",(loops==0)?(selected_lang+1):1);
- hashname=LANGINTKEY(name);
+
+ sprintf(name, "LANGUAGE_%d", (loops == 0) ? (selected_lang + 1) : 1);
+ hashname = LANGINTKEY(name);
}
- sprintf(lbasename, "lang/%s.txt",hashname);
- fp=fopen(fconcat(catbuff, path, lbasename), "rb");
+ sprintf(lbasename, "lang/%s.txt", hashname);
+ fp = fopen(fconcat(catbuff, path, lbasename), "rb");
if (fp) {
char extkey[8192];
char value[8192];
+
while(!feof(fp)) {
- linput_cpp(fp,extkey,8000);
- linput_cpp(fp,value,8000);
+ linput_cpp(fp, extkey, 8000);
+ linput_cpp(fp, value, 8000);
if (strnotempty(extkey) && strnotempty(value)) {
int len;
- char* buff;
- char* intkey;
-
- intkey=LANGINTKEY(extkey);
-
+ char *buff;
+ char *intkey;
+
+ intkey = LANGINTKEY(extkey);
+
if (strnotempty(intkey)) {
-
+
/* Increment for multiple definitions */
{
- char* test=LANGSEL(intkey);
+ char *test = LANGSEL(intkey);
+
if (strnotempty(test)) {
if (loops == 0) {
- int increment=0;
- size_t pos=strlen(extkey);
+ int increment = 0;
+ size_t pos = strlen(extkey);
+
do {
increment++;
- sprintf(extkey+pos,"%d",increment);
- intkey=LANGINTKEY(extkey);
+ sprintf(extkey + pos, "%d", increment);
+ intkey = LANGINTKEY(extkey);
if (strnotempty(intkey))
- test=LANGSEL(intkey);
+ test = LANGSEL(intkey);
else
- test="";
- } while (strnotempty(test));
+ test = "";
+ } while(strnotempty(test));
} else
- intkey="";
+ intkey = "";
} else {
if (loops > 0) {
//err_msg += intkey;
@@ -1447,20 +1544,20 @@ static int htslang_load(char* limit_to, char* path) {
}
}
}
-
+
/* Add key */
if (strnotempty(intkey)) {
len = (int) strlen(value);
- buff=(char*)malloc(len+2);
+ buff = (char *) malloc(len + 2);
if (buff) {
- conv_printf(value,buff);
- inthash_add(NewLangStr,intkey,(intptr_t)buff);
+ conv_printf(value, buff);
+ inthash_add(NewLangStr, intkey, (intptr_t) buff);
}
}
-
+
}
- } // if
- } // while
+ } // if
+ } // while
fclose(fp);
} else {
return 0;
@@ -1470,45 +1567,71 @@ static int htslang_load(char* limit_to, char* path) {
// Control limit_to
if (limit_to)
- limit_to[0]='\0';
+ limit_to[0] = '\0';
return 1;
}
/* NOTE : also contains the "webhttrack" hack */
-static void conv_printf(char* from,char* to) {
- int i=0,j=0,len;
+static void conv_printf(char *from, char *to) {
+ int i = 0, j = 0, len;
+
len = (int) strlen(from);
- while(i<len) {
- switch(from[i]) {
- case '\\':
+ while(i < len) {
+ switch (from[i]) {
+ case '\\':
i++;
- switch(from[i]) {
- case 'a': to[j]='\a'; break;
- case 'b': to[j]='\b'; break;
- case 'f': to[j]='\f'; break;
- case 'n': to[j]='\n'; break;
- case 'r': to[j]='\r'; break;
- case 't': to[j]='\t'; break;
- case 'v': to[j]='\v'; break;
- case '\'': to[j]='\''; break;
- case '\"': to[j]='\"'; break;
- case '\\': to[j]='\\'; break;
- case '?': to[j]='\?'; break;
- default: to[j]=from[i]; break;
+ switch (from[i]) {
+ case 'a':
+ to[j] = '\a';
+ break;
+ case 'b':
+ to[j] = '\b';
+ break;
+ case 'f':
+ to[j] = '\f';
+ break;
+ case 'n':
+ to[j] = '\n';
+ break;
+ case 'r':
+ to[j] = '\r';
+ break;
+ case 't':
+ to[j] = '\t';
+ break;
+ case 'v':
+ to[j] = '\v';
+ break;
+ case '\'':
+ to[j] = '\'';
+ break;
+ case '\"':
+ to[j] = '\"';
+ break;
+ case '\\':
+ to[j] = '\\';
+ break;
+ case '?':
+ to[j] = '\?';
+ break;
+ default:
+ to[j] = from[i];
+ break;
}
break;
- default:
- to[j]=from[i];
- break;
+ default:
+ to[j] = from[i];
+ break;
}
i++;
j++;
}
- to[j++]='\0';
+ to[j++] = '\0';
/* Dirty hack */
{
- char * a = to;
+ char *a = to;
+
while((a = strstr(a, "WinHTTrack"))) {
a[0] = 'W';
a[1] = 'e';
@@ -1524,30 +1647,31 @@ static void LANG_DELETE(void) {
}
// sélection de la langue
-static void LANG_INIT(char* path) {
+static void LANG_INIT(char *path) {
//CWinApp* pApp = AfxGetApp();
//if (pApp) {
- /* pApp->GetProfileInt("Language","IntId",0); */
- LANG_T(path, 0 /*pApp->GetProfileInt("Language","IntId",0)*/ );
+ /* pApp->GetProfileInt("Language","IntId",0); */
+ LANG_T(path, 0 /*pApp->GetProfileInt("Language","IntId",0) */ );
//}
}
-static int LANG_T(char* path, int l) {
- if (l>=0) {
+static int LANG_T(char *path, int l) {
+ if (l >= 0) {
QLANG_T(l);
htslang_load(NULL, path);
}
- return QLANG_T(-1); // 0=default (english)
+ return QLANG_T(-1); // 0=default (english)
}
-static int LANG_SEARCH(char* path, char* iso) {
+static int LANG_SEARCH(char *path, char *iso) {
char lang_str[1024];
int i = 0;
- int curr_lng=LANG_T(path, -1);
+ int curr_lng = LANG_T(path, -1);
int found = 0;
+
do {
QLANG_T(i);
- strcpybuff(lang_str,"LANGUAGE_ISO");
+ strcpybuff(lang_str, "LANGUAGE_ISO");
htslang_load(lang_str, path);
if (strfield(iso, lang_str)) {
found = i;
@@ -1558,10 +1682,11 @@ static int LANG_SEARCH(char* path, char* iso) {
return found;
}
-static int LANG_LIST(char* path, char* buffer) {
+static int LANG_LIST(char *path, char *buffer) {
char lang_str[1024];
int i = 0;
- int curr_lng=LANG_T(path, -1);
+ int curr_lng = LANG_T(path, -1);
+
buffer[0] = '\0';
do {
QLANG_T(i);
@@ -1579,73 +1704,70 @@ static int LANG_LIST(char* path, char* buffer) {
}
static int QLANG_T(int l) {
- static int lng=0;
- if (l>=0) {
- lng=l;
+ static int lng = 0;
+
+ if (l >= 0) {
+ lng = l;
}
- return lng; // 0=default (english)
+ return lng; // 0=default (english)
}
-static char* LANGSEL(char* name) {
+static char *LANGSEL(char *name) {
intptr_t adr = 0;
+
if (NewLangStr)
- if (!inthash_read(NewLangStr,name,&adr))
- adr=0;
+ if (!inthash_read(NewLangStr, name, &adr))
+ adr = 0;
if (adr) {
- return (char*)adr;
+ return (char *) adr;
}
return "";
}
-static char* LANGINTKEY(char* name) {
- intptr_t adr=0;
+static char *LANGINTKEY(char *name) {
+ intptr_t adr = 0;
+
if (NewLangStrKeys)
- if (!inthash_read(NewLangStrKeys,name,&adr))
- adr=0;
+ if (!inthash_read(NewLangStrKeys, name, &adr))
+ adr = 0;
if (adr) {
- return (char*)adr;
+ return (char *) adr;
}
return "";
}
-
-
-
/* *** Various functions *** */
-
-
-
-
-static int recv_bl(T_SOC soc, void* buffer, size_t len, int timeout) {
+static int recv_bl(T_SOC soc, void *buffer, size_t len, int timeout) {
if (check_readinput_t(soc, timeout)) {
int n = 1;
size_t size = len;
size_t offs = 0;
+
while(n > 0 && size > 0) {
- n = recv(soc, ((char*)buffer) + offs, (int) size, 0);
+ n = recv(soc, ((char *) buffer) + offs, (int) size, 0);
if (n > 0) {
offs += n;
size -= n;
}
}
- return (int)offs;
+ return (int) offs;
}
return -1;
}
-
// check if data is available
-static int check_readinput(htsblk* r) {
+static int check_readinput(htsblk * r) {
if (r->soc != INVALID_SOCKET) {
- fd_set fds; // poll structures
+ fd_set fds; // poll structures
struct timeval tv; // structure for select
+
FD_ZERO(&fds);
- FD_SET(r->soc,&fds);
- tv.tv_sec=0;
- tv.tv_usec=0;
- select(r->soc + 1,&fds,NULL,NULL,&tv);
- if (FD_ISSET(r->soc,&fds))
+ FD_SET(r->soc, &fds);
+ tv.tv_sec = 0;
+ tv.tv_usec = 0;
+ select(r->soc + 1, &fds, NULL, NULL, &tv);
+ if (FD_ISSET(r->soc, &fds))
return 1;
else
return 0;
@@ -1653,7 +1775,6 @@ static int check_readinput(htsblk* r) {
return 0;
}
-
/*int strfield(const char* f,const char* s) {
int r=0;
while (streql(*f,*s) && ((*f)!=0) && ((*s)!=0)) { f++; s++; r++; }
@@ -1664,4 +1785,3 @@ static int check_readinput(htsblk* r) {
}*/
/* same, except + */
-