Hello,

I am new to apache module development and need some help.

I have a search application which runs on port 8100. My C Socket client
connects to this port, writes query to server, reads result from server and
displays it on the console as given in desired_output.txt.

Now I have written an apache module to do the same task (mod_helloworld.c).
But it displays the output in the format as given in current_output.html. In
this output every 4th character starting from first matches the desired
output and rest is some special character. I have tried reading output via
wide characters (wchar_t) too, but with same result. Is there any function
in apache module by which we can directly write wide characters to html or
is there some other solution to this problem. Any help in this regard will
be higly appreciated.

Regards

--
Himadri
#include <httpd.h>
#include <http_protocol.h>
#include <http_config.h>

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdio.h>
#include <unistd.h>
#include <strings.h>
#include <arpa/inet.h>

#include <stdlib.h>
#include <stdio.h>

#define MAXLINE 1024
#define HOST "127.0.0.1"
#define PORT 8100

void
str_cli(char * sendline, int sockfd, request_rec * r)
{
	char ch;
	//write query to server
	write(sockfd, sendline, strlen(sendline));
    	int n, i;
	//receive results of query
	while ( n = read(sockfd, &ch, 1) != 0)
    	{
		ap_rprintf(r, "%lc\n", ch);
	}
}

int
connect_server(request_rec * r, char * query)
{
  int			sockfd;
  struct sockaddr_in	servaddr;
  int 			retval;
  
  sockfd = socket(AF_INET, SOCK_STREAM, 0);
  if (sockfd == -1) {
     printf("socket() failed.\n");
     exit(-1);
  }
  bzero(&servaddr, sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  servaddr.sin_port = htons(PORT);
  servaddr.sin_addr.s_addr = inet_addr(HOST);

  retval = connect(sockfd, (struct sockaddr *) &servaddr, sizeof(servaddr));
  if (retval == -1) {
     printf("connect() failed.\n");
     exit(-1);
  }

  str_cli(query, sockfd, r);

  exit(0);
}

static int helloworld_handler(request_rec* r)
{
	if (!r->handler || strcmp(r->handler, "helloworld"))
		return DECLINED;

	if (r->method_number != M_GET)
		return HTTP_METHOD_NOT_ALLOWED;

	char *args = r->args;
	ap_set_content_type(r, "text/html;charset=ascii");
	ap_rputs("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">\n", r);
	//ap_rputs("<meta http-equiv=\"Content-Type\" content=\"text/html; \
	//	 charset=utf-8\">", r);
	ap_rputs("<html><body>", r);
	if(args != NULL) {

		connect_server(r, args);
	}	
	ap_rputs("</body></html>", r);
	return OK;
}

static void register_hooks(apr_pool_t* pool)
{
	ap_hook_handler(helloworld_handler, NULL, NULL, APR_HOOK_MIDDLE);
}

module AP_MODULE_DECLARE_DATA helloworld_module = {
	STANDARD20_MODULE_STUFF,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	register_hooks
};
Searching for: contents:sonia sonia meta:sonia


0.  Sonia hints at more concessions for farmers


1.  Sonia backs duty cut in fuel price


2.  Ambani vs Ambani: Mukesh to meet Sonia Gandhi today


3.  Sonia asks, Sonia gets oil price cut


4.  Fuel price cut | On Sonia's order?


5.  Sonia cheers Indian contingent at Olympic opening ceremony-


6.  I&#226;&#8364;&#8482;ve quit, waiting for Sonia word: Rane-


7.  Mukesh Ambani meets PM as calls for windfall tax grow


8.  No easy solutions to inflation: Kamal Nath


9.  Sonia, Rahul, Priyanka arrive in Beijing- Hindustan Times


10.  UPA government is in an ICU, says LK Advani - Hindustan Times


11.  Doing it again- Hindustan Times


12.  With politicians like these...- Hindustan Times


13.  How to recover- Hindustan Times


14.  NDTV.com: Ball in govt's court: Yechury


15.  NDTV.com: Ramadoss for ban on junk food in DU


16.  NDTV.com: Ramadoss for ban on junk food in DU


17.  NDTV.com: Seat in DU doubtful despite OBC quota


18.  NDTV.com: Girls excel in ICSE, ISC results


19.  Pune BPO employee gangraped- Hindustan Times


20.  The golden mile- Hindustan Times


21.  Post Trust Vote, Cong puts trust back in Manmohan



Search took: 3 ms.
Screen dump took: 20 ms.

Reply via email to