All pastes #1925818 Raw Edit

Azuolas - Faustas BAGDONAS

public c v1 · immutable
#1925818 ·published 2010-08-26 11:46 UTC
rendered paste body
/* =========================================================== * PROGRAM : Unknown Letters Solver * VERSION : 1.0 * COMPILER: Microsoft Visual Studio 2008 * ----------------------------------------------------------- * DESCRIPTION:  * Tekstineje (naud. ASCII ar UTF-8 koduote).csv duomenu baze- * je, kurioje surasyti vardai ir pavardes,  programa  suranda * irasus su trukstamais simboliais  (jie turi  buti  pazymeti * '?'), ir juos bando nuspeti.Pradzioje speja pagal salia nu- * rodyta e-mail adresa, o tada bando ieskoti  vardu/pavardziu * su spejamais simboliais internete (naudoja "Google") ir kai * spejimo budu suranda daugiausia rezultatu, tai  tas raides, * su kuriomis buvo suformuluota daugiausia  rezultatu  davusi * uzklausa, suraso i rezultatu faila. Jei niekaip  nepavyksta * nieko rasti per "Google",tai raides nuspejamos atsitiktinu- * mo budu.  * * .CSV DUOMENU BAZEJE TURI NEBUTI KLAIDU (PROGRAMA JU NETIKRI- * NA). ESANT KLAIDAI PASEKMES NEPROGNOZUOJAMOS. USE THIS PROG- * RAM AT YOUR OWN RISK! * * ----------------------------------------------------------- * (c)COPYLEFT 2010, Àþuolas - Faustas BAGDONAS * Programa leidziama visiems modifikuoti, tobulinti, taikyti * saviems tikslams. Tai tera Quick & Dirty  versija,  skirta * mano asmeninems poreikiams. * =========================================================== */ #include <stdio.h>#include <stdlib.h>#include <string.h>#include <time.h>#include <ctype.h>#include <winsock2.h>#include <winsock.h>#include <Mswsock.h>#define FALSE	0#define TRUE	1	typedef int		BOOL;BOOL create_log;FILE *flog;void info(FILE *out);void logging (char *logstr);BOOL ns_by_mail(char *name, char *sirname, char *email);void toasc(char *dst, char *src);BOOL solveq(char *qdata, char *search);unsigned char findq(char *str);BOOL ns_by_google(char *name, char *sirname, SOCKET sGoogle, float percent);void ns_by_random(char *name, char *sirname);BOOL store(FILE *fout, char *name, char *sirname, char *email);SOCKET prep_winsock(void);void conv4httpquery(char *dst, char *src);void removedocs(char *str);int main (void){	char  infname[256], outfname[256], logfname[256];	FILE *fin = NULL,  *fout = NULL;	char progress[80];	unsigned long int sbemail = 0, sbgoogle = 0, sbrandom = 0, ignored = 0;	SOCKET sGoogle;	srand((unsigned int)time(NULL)); //randomize();	create_log = FALSE;	flog = NULL;	info(stdout);	sGoogle = prep_winsock();	if (!sGoogle){		char ans;		logging("Cannot load WinSock! Google search will not available\n");		putchar('\a');		printf("Press ENTER to continue or Q and ENTER to exit. . . ");		fflush(stdin);		ans = getchar();		if((ans == 'q') || (ans == 'q'))			return 1;	}	printf("\nWARNING: if exist output and log files, then they will be overwritten!\a\n\n");    /* Failu paruosimas darbui */	do{		printf("Input file (INPUT.CSV): ");		fflush(stdin);		gets(infname);		if (!infname[0])			strcpy(infname, "INPUT.CSV");		/* Jei faila pavyko atidaryti, klausti kitu failu (isvesties ir log)*/		if ((fin = fopen(infname, "r")) != NULL){			printf("Output file (OUTPUT.CSV): ");			fflush(stdin);			gets(outfname);			if (!outfname[0])				strcpy(outfname, "OUTPUT.CSV");		    /* Jei faila pavyko atidaryti, klausti LOG failo */			if ((fout = fopen(outfname, "w+")) != NULL){				printf("Log file (none): ");				fflush(stdin);				gets(logfname);				if (!logfname[0])					strcpy(logfname, "none");				/* Jei nebuvo ivesta "none", t.y jei LOG reikalingas. */				if (stricmp(logfname, "none")){					create_log = TRUE;					flog = fopen(logfname, "w+");				}			}		}		if(!(fin && fout && (flog || (!create_log)))){			printf("Cannot ");			if (fin == NULL)				printf("open \"%s\".\n\a", infname);			else if(!(fout && (flog || (!create_log))))				printf("create \"%s\".\n\a", fout ? logfname : outfname);		}		putchar('\n');	}	while(!(fin && fout && (flog || (!create_log))));	/* Failus atidariau sekmingai, rasau duomenis i log'a */	info(flog);	logging("Files opened and created successfuly.\n");	logging("INPUT FILE: ");	logging(infname);	logging("\nOUTPUT FILE: ");	logging(outfname);	logging("\nLOG FILE: ");	logging(logfname);	logging("\n");	/* DIRBU SU DUOMENIMIS */	{		/* Cia butu geriau naudoti dinamini atminties rezervavima, bet del		   paprastumo tebunie bus statiskai. Vistiek cia tera Quick & Dirty. */		char name[256] = "";		char sirname[256] = "";		char email[256] = "";		unsigned char x, qnum;		char qnumascii[4];		unsigned long int records = 0, current = 0;		float percent;		/* Skaiciuojama, kiek yra irasu */		while(!feof(fin)){			if (fgetc(fin) == '\n')				records++;		}		if (fseek(fin, 0, SEEK_SET)){			logging ("\nSeeking failed!\n");			fclose(fin);			fclose(fout);			fclose(flog);			/* Baigiu rysi su Google, jei buvau prisijunges */			if (sGoogle){				closesocket(sGoogle);				WSACleanup();			}			return 1;		}		while (current < records /*(!feof(fin)) && records*/){			percent = ((float)current/(float)records)*100;			sprintf (progress, "\n--> Processing record %u of %u. %0.1f percent done. <--\n", current + 1, records, percent); 			logging (progress);			logging ("Searching quotes... ");			while(fgetc(fin) != '\"');			logging ("Found.\nCopying NAME to memory... ");			for(x = 0; name[x - 1] != '\"'; x++)				name[x] = fgetc(fin);			name[x - 1] = 0;			logging ("Got: ");			logging (name);			logging ("\n");			logging ("Searching comma... ");			while(fgetc(fin) != ';');			logging ("Found.\nCopying SIRNAME to memory... ");			if(fgetc(fin) == '\"'){				for(x = 0; sirname[x - 1] != '\"'; x++)					sirname[x] = fgetc(fin);				sirname[x - 1] = 0;				logging ("Got: ");				logging (sirname);			}			else{				sirname[0] = 0;				logging("Not found.");			}			logging ("\n");			logging ("Searching comma... ");			while(fgetc(fin) != ';');			logging ("Found.\nCopying EMAIL to memory... ");			if(fgetc(fin) == '\"'){				for(x = 0; email[x - 1] != '\"'; x++)					email[x] = fgetc(fin);				email[x - 1] = 0;				logging ("Got: ");				logging (email);			}			else{				email[0] = 0;				logging("Not found.");			}			logging ("\n");						/* --------------------------- */			logging("Trying to find unknown symbols (question marks)... \n");			qnum = findq(name) + findq(sirname);			itoa(qnum, qnumascii, 10);			if(qnum){				logging("Found: ");				logging(qnumascii);				if (qnum >= 5){					ignored++;					logging (" - too much. Ignoring.\n");					current++;					if (!store(fout, name, sirname, email)){						logging("\nCannot store data. Probably out of free space.\n\a");						/* Uzdarau failus */						if (fin)  fclose(fin);						if (fout) fclose(fout);						if (flog) fclose(flog);						/* Baigiu rysi su Google, jei buvau prisijunges */						if (sGoogle){							closesocket(sGoogle);							WSACleanup();						}						return 1;					}					continue;				}				logging("\n");			}			else{				logging("Not found. Ignoring.\n");				current++;				if (!store(fout, name, sirname, email)){					logging("\nCannot store data. Probably out of free space.\n\a");					/* Uzdarau failus */					if (fin)  fclose(fin);					if (fout) fclose(fout);					if (flog) fclose(flog);										/* Baigiu rysi su Google, jei buvau prisijunges */					if (sGoogle){						closesocket(sGoogle);						WSACleanup();					}					return 1;				}				continue;			}			logging("Trying to solve name/sirname by email...");			if (!ns_by_mail(name, sirname, email)){				logging(" - not solved.\nTrying to search the internet via Google...");				/* Va cia jau reikia prisijungti WinSock ir ieskoti internete*/				if (!ns_by_google(name, sirname, sGoogle, percent)){					logging(" - not solved.\nRandom values will be written. ");					ns_by_random(name, sirname);					logging("Random characters written.\n");					sbrandom++;				}				else sbgoogle++;			}			else sbemail++;			logging("\nRecord solved.\nNAME: ");			logging(name);			logging("\nSIRNAME: ");			logging(sirname);			logging("\n");						if (!store(fout, name, sirname, email)){				logging("\nCannot store data. Probably out of free space.\n\a");				/* Uzdarau failus */				if (fin)  fclose(fin);				if (fout) fclose(fout);				if (flog) fclose(flog);				/* Baigiu rysi su Google, jei buvau prisijunges */				if (sGoogle){					closesocket(sGoogle);					WSACleanup();				}				return 1;			}			current++;		}	}	logging("\n\nDONE!\n\n");    /* Rodau statistika */	logging("Statistic:\n\n");	printf("Solved by EMail: %u\n", sbemail);	printf("Solved by Google search: %u\n", sbgoogle);	printf("Random characters written: %u\n\n", sbrandom);	printf("Total solved: %u\nIgnored: %u\n", sbrandom+sbgoogle+sbemail, ignored);	if(flog){		fprintf(flog, "Solved by EMail: %u\n", sbemail);		fprintf(flog, "Solved by Google search: %u\n", sbgoogle);		fprintf(flog, "Random characters written: %u\n\n", sbrandom);		fprintf(flog, "Total solved: %u\nIgnored: %u\n", sbrandom+sbgoogle+sbemail, ignored);	}	/* Uzdarau failus */	if (fin)  fclose(fin);	if (fout) fclose(fout);	if (flog) fclose(flog);	/* Uzbaigiu rysi su Google, jei buvau prisijunges */	if (sGoogle){		closesocket(sGoogle);		WSACleanup();	}	puts("\a\a\a");	getchar();	return 0;}/* -------------------------------------------------   Function   : info()   Description: isveda informacija apie programa   ------------------------------------------------- */void info(FILE *out){	if (out){		fprintf(out, "Unknown Letters in Name/Sirname Solver v1.0\n");		fprintf(out, "(c)2010, Azuolas - Faustas Bagdonas\n");		fprintf(out, "===========================================\n\n");	}}/* -------------------------------------------------   Function   : logging()   Arguments  : 1. Log file pointer				2. Log string   Description: raso teksta i log'a.   ------------------------------------------------- */void logging (char *logstr){	printf (logstr);	if (create_log)		fprintf (flog, logstr);}/* -------------------------------------------------   Function   : ns_by_mail()   Arguments  : 1. Name				2. Sirname				3. EMail   Return     : TRUE, jei pavyko nuspeti varda/pavar-                de pagal email.Nuspetas vardas/pavar-				de issaugoma atitinkamai ten, kur rodo				argumentuai	name, sirname.   Description: raso teksta i log'a.   ------------------------------------------------- */BOOL ns_by_mail(char *name, char *sirname, char *email){	BOOL nameslv;	BOOL sirnameslv;	findq(name) ? (nameslv = solveq(name, email)):(nameslv = TRUE);	findq(sirname) ? (sirnameslv = solveq(sirname, email)):(sirnameslv = TRUE);	return (nameslv && sirnameslv);}/* -------------------------------------------------   Function   : toasc()   Arguments  : 1. Destination				2. Source   Description: Is UTF-8 konvertuoja i ASCII.   ------------------------------------------------- */void toasc(char *dst, char *src){	unsigned char x, y, z;	BOOL found = FALSE;	/* Is tiesu si lentele turetu buti daug didesne arba gal tam naudojamas	   koks nors algoritmas?                                                */	char conv[16][3] = {{0xC3, 0xA1, 0x61}, //a su desininiu --> a [LOTYNU CP]						{0xC3, 0xAD, 0x69}, //i su desininiu --> i						{0xC3, 0xA9, 0x65}, //e su desininiu --> e						{0xC4, 0x85, 0x61}, //a su nosine --> a [BALTU CP]						{0xC4, 0x8D, 0x63}, //c su varna --> c						{0xC5, 0xAB, 0x75}, //u ilgoji --> u						{0xC4, 0x97, 0x65}, //e su tasku --> e						{0xC5, 0xBE, 0x7A}, //z su pauksciu --> z						{0xC3, 0x81, 0x41}, //A su desininiu --> A						{0xC3, 0x8D, 0x49}, //I su desininiu --> I						{0xC3, 0x89, 0x45}, //E su desininiu --> E						{0xC4, 0x84, 0x41}, //A su nosine -> A						{0xC4, 0x8C, 0x43}, //C su varna --> C						{0xC5, 0xAA, 0x55}, //U su bruksniu --> U						{0xC4, 0x96, 0x45}, //E su tasku --> E						{0xC5, 0xBD, 0x5A}};//Z su varna --> Z	for (x = 0, z = 0; src[x]; x++, z++){		found = FALSE;		/* Jei MSB = 1, tai ne ASCII simbolis. Tikimasi UTF-8 */		if (src[x] & 0x80){			for (y = 0; y < 16; y++){				if ((conv[y][0] == src[x]) && (conv[y][1] == src[x + 1])){					dst[z] = conv[y][3];					x++;					found = TRUE;				}			}		}		if(!found)			dst[z] = src[x];	}	dst[z] = 0;}/* -------------------------------------------------   Function   : solveq()   Arguments  : 1. Duomenys su klaustukais (name arba                   sirname;				2. Kur galiu rasti trukstamus simbo-				   lius (email).   Return     : TRUE, jei pavyko isspresti.   Description: Randa trukstamus simbolius.   ------------------------------------------------- */BOOL solveq(char *qdata, char *search){	unsigned char qprad, qreplace[5], qn, x;	char fromemail[256];	char tempname[256], tempnamebkp[256];    /* Konvertuoju varda/pavarde (duomenis), kad butu naudojami tik ASCII simboliai */ 	toasc(tempname, qdata);	strcpy(tempnamebkp, tempname);	for(qprad = 0; qdata[qprad] == '?'; qprad++);	x = qprad;	while((search[x] != '@') && (x != strlen(search)) && (x != 255)){		qn = 0;		strcpy(tempname, tempnamebkp);		for(;(search[x] != tolower(tempname[qprad])); x++){			if((search[x] == '@') || (x == strlen(search))){				x = 255;				break;			}		}		if(x != 255){			unsigned char z;			memcpy(fromemail, &search[x - qprad], strlen(tempname));			fromemail[strlen(tempname)] = 0;			for(z = 0; z < strlen(tempname); z++){				if (tempname[z] == '?'){					tempname[z] = fromemail[z];					qreplace[qn++] = fromemail[z];				}			}						if(!stricmp(tempname, fromemail)){				unsigned char z;				/* Sutapo */				qn = 0;				for(z = 0; z < strlen(qdata); z++){					if (qdata[z] == '?')						qdata[z] = qreplace[qn++];				}				return TRUE;			}		}		if(x != 255) x++;	}	return FALSE;}/* -------------------------------------------------   Function   : findq()   Arguments  : 1. Stringas [su klaustukais]   Return     : Klaustuku skaicius   Description: Randa, kiek klaustuku yra string'e.   ------------------------------------------------- */unsigned char findq(char *str){	unsigned char x, q = 0;	for (x = 0; x < strlen(str); x++){		if (str[x] == '?')			q++;	}	return q;}/* -------------------------------------------------   Function   : ns_by_google()   Arguments  : 1. Vardas, UTF-8 [su klaustukais]                2. Pavarde,UTF-8 [su klaustukais]   Return     : TRUE, jei rasti pavyko   Description: Iesko vardo&pavardes per google su                spejamomis raidemis. Tinkama paren-				ka pagal rezultatu skaiciu.   ------------------------------------------------- */BOOL ns_by_google(char *name, char *sirname, SOCKET sGoogle, float percent){	unsigned int x, y, nameendpos;	unsigned char qpos[5], q, totalq, bkpq;	char query_start[] = "GET http://www.google.lt/search?q=";	char query_end[] = "&um=1&biw=1230&bih=533&ie=UTF-8&sa=N&tab=iw HTTP/1.1\r\nHost: www.google.lt\r\n\r\n";	const char result_div[] = "<div id=resultStats>";	const char no_results_str[] = " - neatitiko joki\xF8 dokument\xF8."; //Atsakyma is Google kazkodel gaunu Windows-1257.	char buf[8192];	char namesirname[512];	BOOL allz = TRUE;	BOOL incnext;	__int64 maxresults = 0, results;	char letters_max_res[5];	BOOL found = FALSE, noresults = FALSE;	unsigned int bytes_received;	/* Jei blogas socketas, nieko nedarau */	if(!sGoogle)		return FALSE;	/* Konvertuoju duomenis taip, kad itikciau HTTP protokolui */	conv4httpquery(namesirname, name);    strcat(namesirname, "%20");	conv4httpquery(&namesirname[strlen(namesirname)], sirname);	/* Surasau klaustuku pozicijas varde ir pavardeje,	   nustatau pradines raides vietoje klaustuku ('a') */	for (x = 0, q = 0; x < strlen(namesirname); x++){		if (namesirname[x] == '?'){			qpos[q++] = x;			namesirname[x] = 'a';		}	}	totalq = q;	q = 0;	/* Ieskau per Google rezultatu su spejamomis raidemis */	do{		/* Siunciu uzklausa */		send(sGoogle, query_start, strlen(query_start), 0);		send(sGoogle, namesirname, strlen(namesirname), 0);		send(sGoogle, query_end, strlen(query_end), 0);		/* Priimu atsakyma */		do{			bytes_received = recv(sGoogle, buf, 8192, MSG_WAITALL);			//Sleep(500);			for(x = 0; x < 8192; x++){				if (!memicmp(&buf[x], result_div, strlen(result_div))){					found = TRUE;					noresults = FALSE;					break;				}				else if (!memicmp(&buf[x], no_results_str, strlen(no_results_str))){					found = TRUE;					noresults = TRUE;					break;				}			}		}		while((bytes_received == 8192) && (!found));		/* Analizuoti atsakyma */		if (found && (!noresults)){			x += (strlen(result_div) + 5); //5 - "Apie "			for (y = 0; buf[x + y] != ' '; y++);			buf[x + y] = 0;			removedocs(&buf[x]);			results = _atoi64(&buf[x]);			if(results > maxresults){				maxresults = results;				/* Surasau spejamas raides i daugiausia rezultatu				   pelniusiu raidziu masyva.                      */				for(x = 0; x < totalq; x++)					letters_max_res[x] = namesirname[qpos[x]];			}		}		else if (found && noresults);		/* Jei atsakyme nebuvo rasta "<div id=resultStats>". Tai		   gali buti todel, kad Google paieskos sistemoje buvo		   padaryti pakeitimai. Sita dalyka butu galima bandyti		   daryti konfiguruojama, kad esant pakeitimams nesunku		   butu pakeisti, bet siandien del paprastumo tebunie		   taip.                                                 */		else if(!found){			logging("\nError solving: ");			puts(namesirname);			if (flog) fputs(namesirname, flog);			logging("ERROR: Cannot find \"");			logging((char*)result_div);			logging(" or \"");			logging((char*)no_results_str);			logging("\" in Google answer. Posible reasons: \n"				"- Bad connection e.g. package lost (if you see this error message once or sometimes)"				"- Connection lost (if you see this error message many times)\n" 				"- Bug in this program (probably need more complex algorithm) if this message you see only once or some times.\n"				"- Probably this program is too old. Google has been updated (if you see this error message many times)\n");		}		/* Pasalinami nebereikalingi duomenys is recv() eiles */		if (found){			struct fd_set fds = {				fds.fd_count = 1,				fds.fd_array[0] = sGoogle			};			struct timeval tv = {				tv.tv_sec = 0,    				tv.tv_usec = 100000  			};			do recv(sGoogle, buf, 8192, 0);			while(select(0, &fds, NULL, NULL, &tv));		}		found = FALSE;		printf("Guess: %s. Percent completed: %0.1f%%\n", namesirname, percent);		/* Tikrinu, ar ne visas raides isbandziau */		allz = TRUE;		for(x = 0; (x < totalq) && allz; x++){			if (namesirname[qpos[x]] != 'z')				allz = FALSE;		}		/* Kitas raidziu spejimas */		incnext = FALSE;		bkpq = q;		do{			if (namesirname[qpos[q]] != 'z'){ 				namesirname[qpos[q]]++;				incnext = FALSE;			}			else{				namesirname[qpos[q]] = 'a';				q++;				incnext = TRUE;			}		}		while(incnext && (q < totalq));		q = bkpq;	}	while (!allz);	/* Isbandziau visas galimas kombinacijas ir radau, su kuria	   kombinacija rezultatu yra daugiausia. Ruosiu atsakyma.   */	nameendpos = strlen(name);	for (q = 0; q < totalq; q++){		if(qpos[q] < nameendpos)			name[qpos[q]] = letters_max_res[q];		else			sirname[qpos[q] - nameendpos - 3] = letters_max_res[q];	}    if ((findq(name) == 0) && (findq(sirname) == 0) && (maxresults > 0)) 		return TRUE;		return FALSE;}/* -------------------------------------------------   Function   : ns_by_random()   Arguments  : 1. Stringas [su klaustukais]   Return     : Klaustuku skaicius   Description: Randa, kiek klaustuku yra string'e.   ------------------------------------------------- */void ns_by_random(char *name, char *sirname){	unsigned long int x;	char chr;	for (x = 0; x < strlen(name); x++){		if (name[x] == '?'){			do chr = (rand() % 25) + 0x61;			while((chr == 'x')||(chr == 'q')||(chr == 'w'));			name[x] = chr;		}	}	for (x = 0; x < strlen(sirname); x++){		if (sirname[x] == '?'){			do chr = (rand() % 25) + 0x61;			while((chr == 'x')||(chr == 'q')||(chr == 'w'));			sirname[x] = chr;		}	}}/* -------------------------------------------------   Function   : store()   Arguments  : 1. Isvesties failas				2. Vardas				3. Pavarde				4. EMail   Return     : TRUE, jei irasiau sekmingai   Description: Iraso nurodytus duomenis i faila   ------------------------------------------------- */BOOL store(FILE *fout, char *name, char *sirname, char *email){	return (fprintf(fout, "\"%s\";\"%s\";\"%s\"\n", name, sirname, email) >= 0);}/* -------------------------------------------------   Function   : prep_winsock()   Return     : Windows Socket, jei sekmingai. Ki-                taip FALSE (0).   Description: Paruosia WinSock ir prisijungia prie                Google web serverio.   ------------------------------------------------- */SOCKET prep_winsock(void){	WSADATA wsaData;	SOCKET sGoogleSrv;	struct hostent *GoogleHost;	struct sockaddr_in s_in;	char ipnum[4], x;	struct timeval tv = {		tv.tv_sec = 3,		tv.tv_usec = 0	};	/* Bandau ikrauti WinSock biblioteka */	if(WSAStartup(MAKEWORD(1, 0), &wsaData) != NO_ERROR){		logging("\nFailed to start WinSock!\n");		return FALSE;	}	logging("\nWinSock library loaded.\nCreating socket... ");	/* Sukuriu socketa bendravimui su Google serveriu */	sGoogleSrv = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);	if (sGoogleSrv == INVALID_SOCKET){		logging("[FAIL]\n");		printf("Error at socket(): 0x%0.8lX\n", WSAGetLastError());		if(flog) fprintf(flog, "Error at socket(): 0x%0.8lX\n", WSAGetLastError());		WSACleanup();		return FALSE;	}	logging ("[ OK ]\n");	/* Nustatau timeout'us */	if(setsockopt(sGoogleSrv, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv)) == SOCKET_ERROR)		logging("Cannot set timeouts. Timeouts can be too long.\n");	logging("Solving www.google.lt... ");	GoogleHost = gethostbyname("www.google.lt");	if(GoogleHost == NULL){		logging("[FAIL]\n\n--> Probably no network connection. <--\n\n");		printf("Error at gethostbyname(): 0x%0.8lX\n", WSAGetLastError());		if(flog) fprintf(flog, "Error at gethostbyname(): 0x%0.8lX\n", WSAGetLastError());		WSACleanup();		return FALSE;	}	logging("[ OK ]\n");	s_in.sin_port = htons(80);	s_in.sin_family = AF_INET;	s_in.sin_addr.S_un.S_addr = *(unsigned long*)(GoogleHost->h_addr_list[0]);	/* Isvedu gauta IP adresa */	logging("Got IP address: ");	for(x = 0; x < 4; x++){		itoa((unsigned char)((GoogleHost->h_addr_list[0]))[x], ipnum, 10);		logging(ipnum);		logging(".");	}	logging("\n");	/* Jungiuosi prie sukurto socketo */	logging("Connecting to server... ");	if (connect(sGoogleSrv, (struct sockaddr*)&s_in, sizeof(s_in)) == SOCKET_ERROR){		logging("[FAIL]\n");		printf("Error at connect(): 0x%0.8lX\n", WSAGetLastError());		if(flog) fprintf(flog, "Error at connect(): 0x%0.8lX\n", WSAGetLastError());		WSACleanup();		return FALSE;	}	logging("[ OK ]\n");	return sGoogleSrv;}/* -------------------------------------------------   Function   : conv4httpquery()   Arguments  : 1. Destination				2. Source   Description: Paruosia stringa taip, kad jis                itiktu HTTP protokolui. Klaustukams				darau isimti, nes jie bus veliau				keiciami spejamais ASCII simboliais.   ------------------------------------------------- */void conv4httpquery(char *dst, char *src){	unsigned int srcpos, dstpos;	char hexdigit[3];	for (srcpos = 0, dstpos = 0; srcpos < strlen(src); srcpos++){		if (((src[srcpos] >= '0') && (src[srcpos] <= '9'))||((src[srcpos] >= 'A') && 			 (src[srcpos] <= 'Z'))||((src[srcpos] >= 'a') && (src[srcpos] <= 'z'))||(src[srcpos] == '?'))			dst[dstpos++] = src[srcpos];		else{			dst[dstpos] = '%';			itoa((unsigned char)src[srcpos], hexdigit, 16);			strcpy(&dst[dstpos+1], hexdigit);			dstpos += (1 + strlen(hexdigit));		}	}	dst[dstpos] = 0;}void removedocs(char *str){	unsigned int len = strlen(str);	unsigned int x;	for (x = len; x; x--){		if(str[x] == '.'){			strcpy(&str[x], &str[x + 1]);			str[strlen(str)] = 0;		}	}}/* --------------------[ End of File ]-------------------- */