コード例 #1
0
ファイル: apache.c プロジェクト: marcolinoas/libres3
CAMLprim value
netcgi2_apache_request_print_char (value rv, value cv)
{
    CAMLparam2 (rv, cv);
    request_rec *r = Request_rec_val (rv);
    int c = Int_val (cv);
    if (ap_rputc (c, r) == EOF)
        raise_sys_error(copy_string("Netcgi_mod#out_channel#output_char"));
    CAMLreturn (Val_unit);
}
コード例 #2
0
void markdown_output(MMIOT *doc, request_rec *r)
{
    char *title;
    int ret;
    int size;
    char *p;
    markdown_conf *conf;
    list_t *css;

    conf = (markdown_conf *) ap_get_module_config(r->per_dir_config,
                                                  &markdown_module);
    ret = mkd_compile(doc, MKD_TOC|MKD_AUTOLINK);
    ap_rputs("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n", r);
    ap_rputs("<!DOCTYPE html PUBLIC \n"
             "          \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n"
             "          \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n",
             r);
    ap_rputs("<html xmlns=\"http://www.w3.org/1999/xhtml\">\n", r);
    ap_rputs("<head>\n", r);

    if (conf->css) {
        ap_rputs("<meta http-equiv=\"Content-Type\""
                 " content=\"text/html; charset=UTF-8\" />\n", r);
        ap_rputs("<meta http-equiv=\"Content-Style-Type\""
                 " content=\"text/css\" />\n", r);
		css = conf->css;
		do{
            ap_rprintf(r,
                       "<link rel=\"stylesheet\" href=\"%s\""
                       " type=\"text/css\" />\n",
                       (char *)css->data);
            css = (list_t *)css->next;
		}while(css);
    }
    title = mkd_doc_title(doc);
    if (title) {
        ap_rprintf(r, "<title>%s</title>\n", title);
    }
    ap_rputs("</head>\n", r);
    ap_rputs("<body>\n", r);
    if (title) {
        ap_rprintf(r, "<h1 class=\"title\">%s</h1>\n", title);
    }
    if ((size = mkd_document(doc, &p)) != EOF) {
        ap_rwrite(p, size, r);
    }
    ap_rputc('\n', r);
    ap_rputs("</body>\n", r);
    ap_rputs("</html>\n", r);
    mkd_cleanup(doc);
}
コード例 #3
0
static void jsonStartDocument( struct tabix_callback_t* handler)
	{
	if(handler->jsonp_callback!=NULL)
			{
			ap_set_content_type(handler->r, MIME_TYPE_JAVASCRIPT);
			ap_rputs(handler->jsonp_callback,handler->r);
			ap_rputc('(',handler->r);
			}
	else
			{
			ap_set_content_type(handler->r, MIME_TYPE_JSON);
			}
	ap_rputs("{",handler->r);
	}
コード例 #4
0
ファイル: mod_hello.c プロジェクト: bdumitriu/playground
static int hello_handler(request_rec *r)
{
	char *filename = r->filename;
	FILE *f;
	char c;
	int test = 1;
	
	f = fopen(filename, "r");
	
	if (f == NULL)
	{
		return HTTP_NOT_FOUND;
	}
	
	r->content_type = "text/html";
	ap_send_http_header(r);
	
	if (!r->header_only)
	{
		c = fgetc(f);
		while (!feof(f))
		{
			if (c == '#')
			{
				test = 0;
			}
			if (c == '\n')
			{
				test = 1;
			}
			if (test)
			{
				ap_rputc(c, r);
			}
			c = fgetc(f);
		}
	}
	
	fclose(f);
	
	return OK;
}
コード例 #5
0
ファイル: callback.c プロジェクト: vrthra/mod-scheme
int callback_putc(int c,void *xtData){
    callback_data *cdata;
    cdata = (callback_data*)xtData;
    if ( cdata->type == HANDLER ) return    ap_rputc(c,cdata->r);
        else return 0;
}
コード例 #6
0
ファイル: mod_femto.c プロジェクト: femto-dev/femto
// dbuf is the request text
static int femto_do_request(request_rec* r, char* dbuf)
{
  int i;
  int rc;
  femto_request_t *femto_request = NULL;
  int zero;
  struct timespec start;
  struct timespec now;

  r->content_type = "text/plain";      

  if (!r->header_only) {
    char* index_path = NULL;
    int index_path_len = 0;

    index_path = apr_pstrdup(r->pool, r->filename);
    index_path_len = strlen(index_path);

    // Make a new version of the filename without the /r.
    while( index_path_len >= 0 &&
           index_path[index_path_len-1] != '/' &&
           index_path[index_path_len-1] == 'r' ) {
      index_path[index_path_len-1] = '\0';
      index_path_len--;
    }

    //printf("FEMTO got request for %s: %s\n", index_path, dbuf);

    // Look to break out of.
    for( zero = 0; zero < 1; zero++ ) {
      // Start going!
      rc = femto_create_generic_request(&femto_request,
                                       &femto_server,
                                       index_path,
                                       dbuf);
      if( rc ) {
        ap_log_rerror(APLOG_MARK, APLOG_ERR, rc, r,
                      "FEMTO could not create request");
        return HTTP_INTERNAL_SERVER_ERROR;
      }

      rc = femto_begin_request(&femto_server, femto_request);
      if( rc ) {
        ap_log_rerror(APLOG_MARK, APLOG_ERR, rc, r,
                      "FEMTO could not begin request");
        return HTTP_INTERNAL_SERVER_ERROR;
      }


      start.tv_sec = 0;
      start.tv_nsec = 0;
      now.tv_sec = 0;
      now.tv_nsec = 0;

      for( i = 0; ! r->connection->aborted; i++ ) {
        int completed = 0;
        struct timeval tv;
        struct timespec ts;

        rc = gettimeofday(&tv, NULL);
        ts.tv_sec = tv.tv_sec;
        ts.tv_nsec = 1000 * tv.tv_usec;
        //rc = clock_gettime(CLOCK_REALTIME, &ts);
        if( rc ) {
          ap_log_rerror(APLOG_MARK, APLOG_ERR, rc, r,
                        "FEMTO could not gettime");
          return HTTP_INTERNAL_SERVER_ERROR;
        }

        ts.tv_sec += 2;

        rc = femto_timedwait_request(&femto_server, femto_request, &ts, &completed);
        if( rc ) {
          ap_log_rerror(APLOG_MARK, APLOG_ERR, rc, r,
                        "FEMTO could not wait for request");
          return HTTP_INTERNAL_SERVER_ERROR;
        }
        if( completed ) break;

        rc = gettimeofday(&tv, NULL);
        now.tv_sec = tv.tv_sec;
        now.tv_nsec = 1000 * tv.tv_usec;
        //rc = clock_gettime(CLOCK_REALTIME, &now);
        if( rc ) {
          ap_log_rerror(APLOG_MARK, APLOG_ERR, rc, r,
                        "FEMTO clock_gettime failed");
          return HTTP_INTERNAL_SERVER_ERROR;
        }

        if( now.tv_sec > start.tv_sec ) {
          // This is dopey.. but also the best way to check for
          // an aborted connection... just send a byte every second.
          ap_rputc(' ', r);
          ap_rflush(r);

          start = now;
        }
      }
    }

    if( ! r->connection->aborted ) {
      char* response;

      rc = femto_response_for_generic_request(femto_request, &femto_server, &response);
      if( rc ) {
        ap_log_rerror(APLOG_MARK, APLOG_ERR, rc, r,
                        "FEMTO response_for_generic_request failed");
        return HTTP_INTERNAL_SERVER_ERROR;
      }

      //printf("FEMTO sending response %s\n", response);
      ap_rputc('\n', r);
      ap_rputs(response, r);
      free(response);
    } else {
      rc = femto_cancel_request(&femto_server, femto_request);
      if( rc ) {
        ap_log_rerror(APLOG_MARK, APLOG_ERR, rc, r,
                      "FEMTO could not cancel request");
        return HTTP_INTERNAL_SERVER_ERROR;
      }
    }

    femto_destroy_request(femto_request);
  }

  return OK;
}
コード例 #7
0
static int jsonDirectory( struct listngs_callback_t* handler,DIR *dir)
	{
	int count=0;
	struct dirent *entry;
	
	if(handler->jsonp_callback!=NULL)
			{
			ap_set_content_type(handler->r, MIME_TYPE_JAVASCRIPT);
			ap_rputs(handler->jsonp_callback,handler->r);
			ap_rputc('(',handler->r);
			}
	else
			{
			ap_set_content_type(handler->r, MIME_TYPE_JSON);
			}
	ap_rputs("{\"git-version\":",handler->r);
	ap_jsonQuote(MOD_BIO_VERSION,handler->r);
	ap_rputs(",\"content\":[",handler->r);
	
	
	
	while((entry = readdir(dir))!=NULL)
		{
		char* concatpath=NULL;
		struct stat statbuf;
		//skip hidden files
		if(entry->d_name[0]=='.') continue;
		
		concatpath=(char*)malloc(
			strlen(handler->basedir)+
			strlen(entry->d_name)+2);
		if(concatpath==NULL) break;
		sprintf(concatpath,"%s/%s",handler->basedir,entry->d_name);
		
		if(lstat(concatpath,&statbuf)!=0)
			{
			free(concatpath);
			break;
			}
		
		
		
		if(S_ISDIR(statbuf.st_mode))
			{
			size_t i,n=strlen(entry->d_name);
			 
			if(count>0) ap_rputc(',',handler->r);
			ap_rputc('\"',handler->r);
			for(i=0;i< n;++i)
				{
				ap_jsonEscapeC(entry->d_name[i],handler->r);
				}
			ap_rputs("/\"",handler->r);/* append '/' at end of directory */
			++count;
			}
		else if(S_ISREG(statbuf.st_mode) && is_ngs_file(concatpath))
			{
			if(count>0) ap_rputc(',',handler->r);
			ap_jsonQuote(entry->d_name,handler->r);
			++count;
			}
	
		free(concatpath);
		concatpath=NULL;
		}
	
	
	ap_rputs("]}",handler->r);
	if(handler->jsonp_callback!=NULL)
		{
		ap_rputs(");\n",handler->r);
		}
	return 0;
	}
コード例 #8
0
static int plainPrintBody( struct tabix_callback_t* handler,const kstring_t *line)
	{
	if(line!=NULL && line->s!=NULL) ap_rputs(line->s,handler->r);
	return ap_rputc('\n',handler->r);
	}
コード例 #9
0
static int jsonPrintBody(struct tabix_callback_t* handler,const kstring_t *line)
	{
	int i,prev=0,n_fields=0;
	if(handler->count>0) ap_rputs(",\n",handler->r);
	ap_rputs("[",handler->r);

	for(i=0;i<= line->l;++i)
		{
		if(line->s[i]=='\t' || i==line->l)
			{
			if(n_fields>0) ap_rputc(',',handler->r);
			if(handler->file_format==E_FORMAT_VCF)
				{
				switch(n_fields)
					{
					case 1: ap_rwrite(&(line->s)[prev],i-prev,handler->r);break;
					case 5: {
						if(i-prev==1 && (line->s)[prev]=='.')
							{
							ap_rputs("null",handler->r);
							}
						else
							{
							ap_rwrite((void*)&(line->s)[prev],i-prev,handler->r);
							}
						break;
						}
					default:
						{
						if(i-prev==1 && (line->s)[prev]=='.')
							{
							ap_rputs("null",handler->r);
							}
						else
							{
							ap_jsonNQuote(&(line->s)[prev],i-prev,handler->r);
							}
						break;
						}
					}
				}
			else if(handler->file_format==E_FORMAT_BED)
				{
				switch(n_fields)
					{
					case 1:
					case 2: ap_rwrite(&(line->s)[prev],i-prev,handler->r);
						break;
					default:
						ap_jsonNQuote(&(line->s)[prev],i-prev,handler->r);
						break;
						
					}
				}
			else
				{
				ap_jsonNQuote(&(line->s)[prev],i-prev,handler->r);
				}
			
			if(i==line->l) break;
			prev=i+1;
			++n_fields;
			}
		}
	return ap_rputs("]",handler->r);
	}