示例#1
0
//This function prepares the content of  stats context , ( stats.content )
void * control_callback(struct AmmServer_DynamicRequest  * rqst)
{
  char movementRequested[128]={0};
  if ( _GET(default_server,rqst,"walk",movementRequested,128) )
  {
     fprintf(stderr,"Start Called\n");
     externalCommand=1;
  } else
  if ( _GET(default_server,rqst,"stop",movementRequested,128) )
  {
     fprintf(stderr,"Stop Called\n");
     externalCommand=2;
  } else
  if ( _GET(default_server,rqst,"jump",movementRequested,128) )
  {
    externalCommand=3;
 } else
  {
     fprintf(stderr,"Incorrect Command\n");
  }


  snprintf(rqst->content,rqst->MAXcontentSize,"<html><body><a href=\"control.html?walk=1\">Walk</a><br>\
                                               <a href=\"control.html?stop=1\">Stop</a>\
                                               <a href=\"control.html?jump=1\">Jump</a> </body></html>");
  rqst->contentSize=strlen(rqst->content);
  return 0;
}
示例#2
0
void * index_control_page(struct AmmServer_DynamicRequest  * rqst)
{
  char command[MAX_WEB_COMMAND_SIZE]={0};

  //If we have the console argument set this means we dont want the html output enabled so we switch it off
  if ( _GET(flashy_server,rqst,(char*) "UP",command,MAX_WEB_COMMAND_SIZE) ) { Controls_Handle_Keyboard(1,0,0); }
  if ( _GET(flashy_server,rqst,(char*) "DOWN",command,MAX_WEB_COMMAND_SIZE) ) { Controls_Handle_Keyboard(2,0,0); }
  if ( _GET(flashy_server,rqst,(char*) "LEFT",command,MAX_WEB_COMMAND_SIZE) ) { Controls_Handle_Keyboard(3,0,0); }
  if ( _GET(flashy_server,rqst,(char*) "RIGHT",command,MAX_WEB_COMMAND_SIZE) ) { Controls_Handle_Keyboard(4,0,0); }
  if ( _GET(flashy_server,rqst,(char*) "PLAY",command,MAX_WEB_COMMAND_SIZE) ) { Controls_Handle_Keyboard(13,0,0); }
  if ( _GET(flashy_server,rqst,(char*) "ZOOM_OUT",command,MAX_WEB_COMMAND_SIZE) ) { int i=0; for(i=0; i<3; i++) { Controls_Handle_Keyboard('r',0,0); } }
  if ( _GET(flashy_server,rqst,(char*) "ZOOM_IN",command,MAX_WEB_COMMAND_SIZE) ) { int i=0; for(i=0; i<3; i++) { Controls_Handle_Keyboard('f',0,0); } }
  if ( _GET(flashy_server,rqst,(char*) "STARS",command,MAX_WEB_COMMAND_SIZE) ) { int i=0; for(i=0; i<3; i++) { Controls_Handle_Keyboard('u',0,0); } }
  if ( _GET(flashy_server,rqst,(char*) "HEARTS",command,MAX_WEB_COMMAND_SIZE) ) { int i=0; for(i=0; i<3; i++) { Controls_Handle_Keyboard('k',0,0); } }


  rqst->contentSize=0;
  if (rqst->content!=0)
    {
     strncpy(rqst->content,index_content,index_content_size);
      rqst->contentSize=index_content_size ;
    }

  return 0;
}
示例#3
0
//This function prepares the content of  stats context , ( stats.content )
void * serve_goto_url_page(struct AmmServer_DynamicRequest  * rqst)
{
  //The url , to Long , Short eetc conventions are shit.. :P I should really make them better :p
  memset(rqst->content,0,DYNAMIC_PAGES_MEMORY_COMMITED);

  if  ( rqst->GET_request != 0 )
    {
        char url[MAX_LONG_URL_SIZE]={0};
        char to[MAX_TO_SIZE]={0};
        char captchaReply[MAX_LONG_URL_SIZE]={0};
        char captchaIDStr[MAX_LONG_URL_SIZE]={0};
        //If both URL and NAME is set we want to assign a (short)to to a (long)url
        if ( _GET(myurl_server,rqst,"url",url,MAX_LONG_URL_SIZE) )
             {
               #if ENABLE_CAPTCHA_SYSTEM
               if ( _GET(myurl_server,rqst,"captchaID",captchaIDStr,MAX_LONG_URL_SIZE) )
                { fprintf(stderr,"Captcha ID submited %s \n",captchaIDStr); }
               if ( _GET(myurl_server,rqst,"captcha",captchaReply,MAX_LONG_URL_SIZE) )
                { fprintf(stderr,"Captcha submited %s \n",captchaReply); }

               unsigned int captchaID = atoi(captchaIDStr);
               if ( ! AmmCaptcha_isReplyCorrect(captchaID , captchaReply) )
                {
                 strncpy(rqst->content,"<html><head><meta http-equiv=\"refresh\" content=\"2;URL='index.html'\"></head><body><h2>Please solve the captcha and try again</h2></body></html>",rqst->MAXcontentSize);
                 AmmServer_SignalCountAsBadClientBehaviour(myurl_server,rqst);
                } else
               #endif

               if ( _GET(myurl_server,rqst,"to",to,MAX_TO_SIZE) )
                {
                  //Assigning a (short)to to a (long)url
                  if ( (is_an_unsafe_str(to,strlen(to))) || (is_an_unsafe_str(url,strlen(url)) ) ) //There should be an internal length of the get argument instead of strlen!
                    {
                      snprintf(rqst->content,rqst->MAXcontentSize,"<html><body>Bad Strings provided..</body></html>");
                    } else
                    {
                      Add_MyURL(url,to,1 /*We want to save it to disk..!*/);
                      snprintf(rqst->content,rqst->MAXcontentSize,"<html><head><title>MyURL has shortened your URL</title></head><body><br><br><center>Your link is ready \
                              <a target=\"_new\" href=\"%s%s\">%s%s</a> \
                              <br>Go on , make <a href=\"index.html\">another one</a></center></body></html>",service_root_withoutfilename,to,service_root_withoutfilename, to);
                    }
                } else
                {
                 //No Point in a url without a to , here we could probably generate a random to !
                 strncpy(rqst->content,"<html><head><meta http-equiv=\"refresh\" content=\"2;URL='index.html'\"></head><body><h2>Error creating a new url</h2></body></html>",rqst->MAXcontentSize);
                }
             } else
示例#4
0
// Takes the first request and responds as ACK.
// Assuming all the errors are checked at the coordinator-server
char * exec_rqst(char * request){
		printf("Executing Request : %s\n", request);
		/* code to validate the request*/
		const char s[2] = ":";
		char *token;
		/* get the first token */
		token = strtok(request, s);            
		char allTokens[3][26];             
		int i = 0;
		while( token != NULL && i < 3)   
		{ 
					 printf("%s\n", token);	
						strcpy(allTokens[i],token);
						token = strtok(NULL, s);
						i++;
		}
		if(strcmp(allTokens[0],"GET") == 0){ 
//					callLog("Called method GET \n", log_filename);
						printf("Called method GET\n");
						int key = atoi(allTokens[1]);
						char *getValue = _GET(key);
//					send(newsock, getValue, strlen(getValue), 0);    
						FILE *fp = fopen(GET_FILE, "w");
						fputs(getValue, fp);
						fclose(fp);
		} 
		else if(strcmp(allTokens[0],"PUT") == 0){
//					callLog("Called method PUT \n", log_filename);
						printf("Inside PUT %s %s\n", allTokens[1], allTokens[2]);
						bool putValue = _PUT(atoi(allTokens[1]), allTokens[2]); 
						if(putValue){
//							callLog("Successfully Updated\n", log_filename);
								return "COMMIT";
						}

						else{
//						callLog("Error in updating \n", log_filename);
							return "PUT_ERROR";
						}

		}
		else if(strcmp(allTokens[0],"DELETE") == 0){
						printf("Inside DELETE\n");
						bool delValue = _DELETE(atoi(allTokens[1]));
						if(delValue){
							return "COMMIT";
						}
						else{
							return "DELETE_ERROR";
						}                
		}
		return "UN_KNOWN_REQUEST";
}
示例#5
0
//This overrides serves back the captcha using AmmCaptch!
void * serve_captcha_page(struct AmmServer_DynamicRequest  * rqst)
{
  #if ENABLE_CAPTCHA_SYSTEM
  char captchaIDStr[MAX_LONG_URL_SIZE]={0};
  if ( _GET(myurl_server,rqst,"id",captchaIDStr,MAX_LONG_URL_SIZE) ) { fprintf(stderr,"Captcha ID for image requested %s \n",captchaIDStr); }
  unsigned int captchaID = atoi(captchaIDStr);

  rqst->contentSize=rqst->MAXcontentSize;
  AmmCaptcha_getCaptchaFrame(captchaID,rqst->content,&rqst->contentSize);
  #endif
  return 0;
}
示例#6
0
void * search_callback(struct AmmServer_DynamicRequest  * rqst)
{
  char query[512]={0};
  if ( _GET(default_server,rqst,"q",query,512) )
              {
               snprintf(rqst->content,rqst->MAXcontentSize,"<!DOCTYPE html>\n<html><head><meta http-equiv=\"refresh\" content=\"5;URL='index.html'\" /></head><body>Search query `%s`</body></html>",query);
              } else
              {
               snprintf(rqst->content,rqst->MAXcontentSize,"<!DOCTYPE html>\n<html><head><meta http-equiv=\"refresh\" content=\"0;URL='index.html'\" /></head><body>Search</body></html>");
              }

  rqst->contentSize=strlen(rqst->content);
  return 0;
}
示例#7
0
bool _PUT(int key, char *value){
	printf("Inside _PUT\n");
	if(key >= 0 && key < 100000 ){
		if(flag[key]){
			printf("Key exists\n");
			printf("%s\n",dict[key]);
			return false;
		}
		else{
			strcpy(dict[key],value);
			flag[key] = true;
			printf("%s\n",dict[key]);
			printf("KEYVAL:: %d:%s\n", key, _GET(key));
			return true;
		}
	}
	else{
		printf("Invalid Key\n");
		return false;
	}
}
示例#8
0
unsigned int _GETuint(struct AmmServer_Instance * instance,struct AmmServer_DynamicRequest * rqst,const char * var_id_IN)
{
    unsigned int uintToReturn=0;
    if  ( rqst->GET_request != 0 )
    {
      if ( strlen(rqst->GET_request)>0 )
       {
         char * bufferCommand = (char *) malloc ( 256 * sizeof(char) );
         if (bufferCommand!=0)
          {
            if ( _GET(rqst->instance,rqst,var_id_IN,bufferCommand,256) )
            {
             uintToReturn=atoi(bufferCommand);
            }
           free(bufferCommand);
          }
       }
    }


    return uintToReturn;
}
示例#9
0
/* START_HANDLER (simple, GET, "simple/\\(.*\\)", res, 2, matches) { */
void simple_func(stone_server_t *server){
	ngx_pool_t *pool;
    char *query, buf[200] = {'\0'}, *dest;
    int flag,t,len;
    app_sql_value query_value;
	ngx_command_t *cache_command;

	pool = server->pool;
    HEADER ( "content-type", "text/html" );
    //response_write(res, "hello world<br/>");
    //response_write(res, "wonder world!<br>");
	/*
    char *path = getenv("PATH_INFO");
    regmatch_t preg = matches[1];
    len = preg.rm_eo - preg.rm_so;
    //memset(dest, 0, 20);
    strncpy(dest, path+preg.rm_so, len);
    */
	dest = server->req->path[1];
    //response_write(res, dest);

//     query = "id = ";
    //query = ngx_palloc(pool, 6);
    //strncpy(query, "id = ", 6);
//     strncpy(buf, query, strlen(query));
//     strncpy(buf+strlen(query), dest, len);
	LIST_HEAD( wheres );
	main_add_variable ( pool, &wheres, "id", dest );
	LIST_HEAD( fields );
	main_add_variable ( pool, &fields, "category_id", ngx_strdup( pool, "211" ) );
	//sprintf(buf, "id = %d", *dest);
	//cache_command = {pool,	0,	cache_read,	cache_write,	NULL};
	//cache_command.run  = cache_read;
	//cache_command.type = 0;
	//cache_command.policy = &file_cache_cmd;
	//cache_command.post = cache_write;
	//cache_command.pool = pool;
    //cache_command.data = NULL;
    //response_write(res, buf);
    cache_command = command_create(pool, COMMAND_CACHE_REDIS);
    cache_command->resource = server->thread->redis;
    int rc = app_select(server, "article", "*", &wheres, 1, 0, cache_command);
    if (rc != 0) ECHO("error data");
	//app_update(globals_r.con, "article", &fields, &wheres, &cache_command);
	//ECHO(buf);
    //if (cache_command.data) response_write(pool, res, cache_command.data);
    if (cache_command->data) ECHO(cache_command->data);
    /*
	cache_command.policy = &node_mjson_command;
	char *str = tpl_load( &cache_command, "index.tpl");
	if ( !str ) return;
	stone_node_t *node;
	node = parse_tpl ( &cache_command, &str );
	if ( !node ) return;
	cache_command.data = node;
	ngx_command_t *dcommand = command_clone( cache_command.pool, &cache_command );
	ngx_buf_t *tplbuf = ngx_create_temp_buf( cache_command.pool, 4096 );
	if ( !tplbuf ) return;
	str = tpl_render( &cache_command, dcommand, tplbuf, server->tpl);
    */
    char *val = _GET( "act" );
    //TPL_ASSIGN ( ngx_strdup ( pool, "act" ), val );
    char *str = TPL_OUTPUT ( "index.tpl" );
	if ( str ) ECHO ( str );
	
	char *temp = _GET ( "act" );
	if (temp != NULL )
		ECHO ( temp );
}