	GOOL	Alpha
	*************
	written by l0om	
	innate[@7]gmx.d3
	WWW.EXCLUDED.ORG
	*************

		0x1	data types
			0x11	goo_t
			0x12	cli_ans
		0x2	functions
			0x21	init_goo
			0x22	goo_cli
			0x23	goo_cli_set
			0x24	goo_cli_req
			0x25	goo_cli_cnt
			0x26	goo_results
			0x27	goo_prnt_er
			0x28	delete_goo
		0x3	notes
			0x31	about "goo_results"

------------]0x1	data types




0x11	goo_t :

	typedef struct _goo_t {
		u_char resultc;			//last received result code
		int goo_results;
		struct _goo_client *cli;	//the client list
	} goo_t;


	resultc: 	result-value
	goo_results: 	message queue to that the clients answers are sent
	cli:		concatenated list with client-informationen


0x12	cli_ans :

	typedef struct {
		long mtyp;
		u_char resultc;			//result code
		char data[10][URLLEN];		//the received urls
		char urls;			//have read this much results
		u_long	goo_res;		//results 
		char req[MAXREQ];
	} cli_ans;

	resultc:	result-value of the client which has sent the answer
	data:		if URLS were requested they are stored here
	urls:		if URLS were requested the number of URLS can be found here;
			maximal 10 per answer
	goo_res:	if RESULTS were requested you can find the number of Google
			Results here
	req:		the request-stirng which has been addressed to the client
			can be found here



------------]0x2	Funktionen




0x21	init_goo
goo_t	init_goo()

	function:
		all functions of "gool" need a initialized "goo_t" data type which
		will be supplied on succes with this function.
	returnvalue:
		success: initialized "goo_t" data type; result-value SUCCESS
		error: "goo_t" data type; result-value ALLOC_ERR or MQ_ERR.

0x22	goo_cli
int	goo_cli(int ncli, goo_t *ginf)

	parameter:
		ncli: number of clients you want to create
		ginf: successfully initialized "goo_t" data type
	function:
		all actions which are addressed to google are sent as orders to the
		clients. these clients are independently of each other and can be
		created with this fuction.
	returnvalue:
		success: returns the number of created clients
		error: returns 0; result-value FAILD, MQ_ERR or FORK_ERR
	note:
		- this function can only be called once jet and supplies on a second
		  call FAILD.
		- the first client gets the ID 1 the second the ID 2....

0x23	goo_cli_set
void	goo_cli_set(int cli, u_char opt, void *data, goo_t *ginf)

	parameter:
		cli: ID of the client which should be configured
		opt: desired option to be set
		data: parameters for certain options if needed
		ginf: successfully initialized "goo_t" data type
	function:
		all created clients can be constantly configured
	returnvalue:
		success: result-Wert SUCCESS
		error: result-Werte UNKNOWN or NO_SUCH_CLI
	note:
		options:
			GETRESLT	<no parameter>
			client supplies the number of Google Results as "long"

			GETURLS		<no parameter>
			client supplies X URLs of search results

			SETPRXY		<proxy:port>
			assign a proxy to a client
				zb:
				goo_cli_set(1, SETPRXY, "proxy.anony.net:1337", &goo);	

			NOPRXY		<no parameter>
			reject current proxy; use none

			QUIT		<no parameter>
			terminate the client

0x24	goo_cli_req
int	goo_cli_req(int cli, char *req, goo_t *ginf, u_int urls)

	parameter:
		cli: ID of the client which should be configured
		req: the request string which is sent to google
		ginf: successfully initialized "goo_t" data type
		urls: Number of desired URLs
	function:
		oders are sent to a created client for processing
	returnvalue:
		success: returns 1; resultvalue SUCCESS
		error: returns -1, fork() error; 
			liefert 0, client couldnt be found
			resultvalue FORK_ERR or NO_SUCH_CLI

0x25	goo_cli_cnt
int	goo_cli_cnt(goo_t *ginf)

	parameter:
		ginf: successfully initialized "goo_t" data type
	function:
		supplies the number of successfully produced clients
	returnvalue:
		success: supplies the number successfully created clients

0x26	goo_results
cli_ans	goo_results(cli_ans *rcv, goo_t *ginf)

	parameter:
		rcv: "cli_ans" data type to store possible results
		ginf: successfully initialized "goo_t" data type
	function:
		reads the answer of the client
	returnvalue:
		success: (1) supplies cl_ans resultvalue is the resultvalue of 
			     the client which has sent this message. the resultvalue
			     is NOT NOANSWER
			 (2) supplies cl_ans; no client answer; resultvalue NOANSWER 
		error: 
			FATAL ERROR; Exit with 0
	Note:
		this function is none-blocking and returns immediately. its the 
		programmers task to read the clients answers depending on your
		requirements.
		!! !  !   !see examples in EXAMPLE*.txt!   !  ! !!

0x27	goo_prnt_er
void	goo_prnt_er(goo_t *ginf)

	parameter:
		ginf: successfully initialized "goo_t" data type
	function:
		examines the resultvalue and prints the appropriate string
		on the monitor
	returnvalue:
		none

0x28	delete_goo
int	delete_goo(goo_t *ginf);

	parameter:
		ginf: successfully initialized "goo_t" data type
	function:
		frees the mallocs, terminates the clients and deletes the
		message queues
	returnvalue:
		supplies 1



------------]0x3 notes



0x31	about "goo_results"

//	goo_results(cli_ans *rcv, goo_t *ginf)

to read the answers of the clients which worked on the desired inquiries 
you need this function. as mentioned on 0x26 the function is none-blocking
and returns immediately. some expamples are shown to make functionality more
understandable:

the following piece of code:

- returns received URLS if goo_results got deliverd results

[...]
	ans = goo_results(&goo);
	if(goo.resultc != NOANSWER)   {  // read answers for 10 seconds
		if(goo.resultc != SUCCESS) {
			goo_prnt_er(&goo);
			return;	//break loop, exit function - whatever...
		}
		for(i = 0; i < ans.urls; i++)
			printf("%s\n",ans.data[i]);
[...]

- returns received RESULTS if goo_results got deliverd results

[...]
	ans = goo_results(&goo);
	if(goo.resultc != NOANSWER)   {  // read answers for 10 seconds
		if(goo.resultc != SUCCESS) {
			goo_prnt_er(&goo); //no success - print error mess
			return;	//break loop, exit function - whatever...
		}
		printf("\t\t%s: %u results\n",ans.req,ans.goo_res);
		break;
	}
[...]

- waits 20 seconds for client answer and terminates

[...]
thetime = time(NULL);
while(1) {
	if(thetime < (time(NULL)-20)) break;
	ans = goo_results(&goo);
	if(goo.resultc != NOANSWER)   {  // read answers for 10 seconds
		if(goo.resultc != SUCCESS) {
			goo_prnt_er(&goo); //no success - print error mess
			return;	//break loop, exit function - whatever...
		}
		printf("\t\t%s: %u results\n",ans.req,ans.goo_res);
	}
	usleep(400000); //  <----  dont harm your cpu...
}
[...]

- waits 20 seconds for client answer or ends prematurely after five received answers.

[...]
max = 0;
max += goo_cli_req(1, "kant", &test, 10);
max += goo_cli_req(1, "rousseau", &test, 10);
max += goo_cli_req(1, "hume", &test, 10);
max += goo_cli_req(2, "schiller", &test, 10);*/
max += goo_cli_req(2, "goethe", &test, 10);

thetime = time(NULL);
while(max) {			//wait max 5 results 
	if(thetime < (time(NULL)-20)) break;	//or wait for max 5 results
	ans = goo_results(&goo);
	if(goo.resultc != NOANSWER)   {  // read answers for 10 seconds
		if(goo.resultc != SUCCESS) {
			goo_prnt_er(&goo); //no success - print error mess
			return;	//break loop, exit function - whatever...
		}
		printf("\t\t%s: %u results\n",ans.req,ans.goo_res);
	}
	usleep(400000); // <---- dont harm your cpu...
}
[...]



