Exemplo n.º 1
0
static int htmlPrintBody(struct tabix_callback_t* handler,const kstring_t *line)
	{
	int i,prev=0,n_field=0;
	ap_rprintf(handler->r,"<tr class=\"row%d\">",(int)(handler->count%2));
	for(i=0;i<= line->l;++i)
		{
		if(line->s[i]=='\t' || i==line->l)
			{
			int len=i-prev;
			int only_digit=1,j;
			ap_rputs("<td",handler->r);
			if(n_field==0 && (handler->file_format==E_FORMAT_VCF || handler->file_format==E_FORMAT_BED))
				{
				ap_rputs(" class=\"tbxc\"",handler->r);
				}
			else if(n_field==1 && handler->file_format==E_FORMAT_VCF)
				{
				ap_rputs(" class=\"tbxp\"",handler->r);
				}
			else if(n_field==1 && handler->file_format==E_FORMAT_BED)
				{
				ap_rputs(" class=\"tbxs\"",handler->r);
				}
			else if(n_field==2 && handler->file_format==E_FORMAT_BED)
				{
				ap_rputs(" class=\"tbxe\"",handler->r);
				}
			ap_rputs(">",handler->r);
			for(j=2;j< len && line->l >2 ;++j)
				{
				if(!isdigit(line->s[i+j]))
					{
					only_digit=0;
					break;
					}
				}
			// ncbi rs ?
			if(line->l >2 && only_digit==1 && line->s[0]=='r' && line->s[1]=='s')
				{
				ap_rputs("<a href=\"http://www.ncbi.nlm.nih.gov/projects/SNP/snp_ref.cgi?rs=",handler->r);
				ap_rwrite((void*)&(line->s)[prev+2],len-2,handler->r);
				ap_rputs("\">",handler->r);
				ap_rwrite((void*)&(line->s)[prev],len,handler->r);
				ap_rputs("</a>",handler->r);
				}
			else
				{
				ap_xmlNPuts(&(line->s)[prev],len,handler->r);
				}
			
			ap_rputs("</td>",handler->r);
			if(i==line->l) break;
			++n_field;
			prev=i+1;
			}
		}
	return ap_rputs("</tr>\n",handler->r);
	}
Exemplo n.º 2
0
/**
 * Writes a response from srun to the client
 */
static int
cse_write_response(stream_t *s, int len, request_rec *r)
{
  while (len > 0) {
    int sublen;
    int writelen;
    int sentlen;

    if (s->read_length <= s->read_offset && cse_fill_buffer(s) < 0)
      return -1;

    sublen = s->read_length - s->read_offset;
    if (len < sublen)
      sublen = len;

    writelen = sublen;
    while (writelen > 0) {
      sentlen = ap_rwrite(s->read_buf + s->read_offset, writelen, r);
      /*
       * RSN-420.  If the client fails, should still read data from the
       * server and complete that side of the socket.
       */

      if (sentlen > 0)
	writelen -= sentlen;
      else
	writelen = 0;
    }
    
    s->read_offset += sublen;
    len -= sublen;
  }
  
  return 1;
}
Exemplo n.º 3
0
/**
 * Writes a response from srun to the client
 */
static int
cse_write_response(stream_t *s, int len, request_rec *r)
{
  while (len > 0) {
    int writelen;
    int sentlen;

    if (s->read_length <= s->read_offset && cse_fill_buffer(s) < 0)
      return -1;

    writelen = s->read_length - s->read_offset;
    if (len < writelen)
      writelen = len;

    while (writelen > 0) {
      sentlen = ap_rwrite(s->read_buf + s->read_offset, writelen, r);
      if (sentlen < 0) {
	cse_close(s, "write");
	return -1;
      }

      writelen -= sentlen;
      s->read_offset += sentlen;
      len -= sentlen;
    }
  }
  
  return 1;
}
Exemplo n.º 4
0
static void
output(sl_vm_t* vm, char* buff, size_t len)
{
    slash_context_t* ctx = vm->data;
    flush_headers(ctx);
    ap_rwrite(buff, len, ctx->r);
}
Exemplo n.º 5
0
static int write_http_response(mapcache_context_apache_request *ctx, mapcache_http_response *response) {
   request_rec *r = ctx->request;
   int rc;

   if(response->mtime) {
      ap_update_mtime(r, response->mtime);
      if((rc = ap_meets_conditions(r)) != OK) {
         return rc;
      }
      char *timestr = apr_palloc(r->pool, APR_RFC822_DATE_LEN);
      apr_rfc822_date(timestr, response->mtime);
      apr_table_setn(r->headers_out, "Last-Modified", timestr);
   }
   if(response->headers && !apr_is_empty_table(response->headers)) {
      const apr_array_header_t *elts = apr_table_elts(response->headers);
      int i;
      for(i=0;i<elts->nelts;i++) {
         apr_table_entry_t entry = APR_ARRAY_IDX(elts,i,apr_table_entry_t);
         if(!strcasecmp(entry.key,"Content-Type")) {
            ap_set_content_type(r,entry.val);
         } else {
            apr_table_set(r->headers_out, entry.key, entry.val);
         }
      }
   }
   if(response->data) {
      ap_set_content_length(r,response->data->size);
      ap_rwrite((void*)response->data->buf, response->data->size, r);
   }

   r->status = response->code;
   return OK;

}
Exemplo n.º 6
0
static int do_print( void *_c, const char *buf, int len ) {
	mcontext *c = (mcontext*)_c;
	ap_soft_timeout("Client Timeout",c->r);
	send_headers(c);
	ap_rwrite(buf,len,c->r);
	ap_kill_timeout(c->r);
	return c->r->connection->aborted == 0;
}
Exemplo n.º 7
0
int callback_write(const void *buf, int nbyte, void *xtData){
    callback_data *cdata;
    cdata = (callback_data*)xtData;
    if ( cdata->type == HANDLER ) return ap_rwrite(buf,nbyte,cdata->r);
    
    if ( cdata->type == FILTER ) return filter_write((char *)buf,nbyte,cdata);
        else return 0;
}
Exemplo n.º 8
0
static void request_print( const char *data, int size, void *_c ) {
	mcontext *c = (mcontext *)_c;
	if( c == NULL ) c = CONTEXT();
	if( size == -1 ) size = (int)strlen(data);
	ap_soft_timeout("Client Timeout",c->r);
	send_headers(c);
	ap_rwrite(data,size,c->r);
	ap_kill_timeout(c->r);
}
Exemplo n.º 9
0
CAMLprim value
netcgi2_apache_request_output(value rv, value bufv, value ofsv, value lenv)
{
    CAMLparam4(rv, bufv, ofsv, lenv);
    request_rec *r = Request_rec_val(rv);
    int ofs = Int_val(ofsv);
    int len = Int_val(lenv);
    int i = ap_rwrite(String_val(bufv) + ofs, len, r);
    CAMLreturn(Val_int (i));
}
Exemplo n.º 10
0
static int document_select(request_rec *r, softbot_handler_rec *s)
{
    int rv = 0;
    uint32_t docid = 0;
    char* OID = 0;
    char* DID = 0;
    char content_type[SHORT_STRING_SIZE+1];

    OID = apr_pstrdup(r->pool, apr_table_get(s->parameters_in, "OID"));
    DID = apr_pstrdup(r->pool, apr_table_get(s->parameters_in, "DID"));

    if( (OID == NULL || strlen(OID) == 0) &&
        (DID == NULL || strlen(DID) == 0) ) {
        MSG_RECORD(&s->msg, error, "oid, did is null, get parameter exist with oid or did.");
        return FAIL;
    }

    if (canned_doc == NULL) {
        canned_doc = (char *)sb_malloc(DOCUMENT_SIZE);
        if (canned_doc == NULL) {
            MSG_RECORD(&s->msg, crit, "out of memory: %s", strerror(errno));
            return FAIL;
        }
    }
    
    if(OID != NULL) decodencpy(OID, OID, strlen(OID));

	if(DID == NULL) {
		rv = sb_run_get_docid(did_db, OID, &docid);
		if ( rv < 0 ) {                                 
			MSG_RECORD(&s->msg, error, "cannot get docid of OID[%s]", OID);
			return FAIL;
		}  

		if( rv == DOCID_NOT_REGISTERED ) {
			MSG_RECORD(&s->msg, error, "not registerd OID[%s]", OID);
			return FAIL;
		}
	} else {
		docid = atoi(DID);
	}

	rv = sb_run_cdm_get_xmldoc(cdm_db, docid, canned_doc, DOCUMENT_SIZE);
	if ( rv < 0 ) {
		MSG_RECORD(&s->msg, error, "cannot get document[%u]", docid);
		return FAIL;
	}

    snprintf( content_type, SHORT_STRING_SIZE, "text/xml; charset=%s", default_charset);
    ap_set_content_type(r, content_type);
    ap_rprintf(r, "<?xml version=\"1.0\" encoding=\"%s\"?>\n", default_charset);
    ap_rwrite(canned_doc, strlen(canned_doc), r);

    return SUCCESS;
}
Exemplo n.º 11
0
static void
s_write_gif_data(request_rec *r)
{
  DBG(r, "REQ[%X] start %s()", TO_ADDR(r),__func__);
  apr_table_setn(r->headers_out, "Content-Type", "image/gif");
  apr_table_setn(r->headers_out, "Cache-Control","private, no-cache, no-cache=Set-Cookie, proxy-revalidate");
  apr_table_setn(r->headers_out, "Pragma",       "no-cache");
  apr_table_setn(r->headers_out, "Expires",      "Wed, 17 Sep 1975 21:32:10 GMT");
  apr_table_setn(r->headers_out, "Content-Length", "35");
  ap_rwrite(v_GIF_DATA, 35, r);
  DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
}
Exemplo n.º 12
0
void raw_output(FILE * fp, request_rec * r)
{
    char buf[1024];
    size_t len;
    while (1) {
        len = fread(buf, 1, 1024, fp);
        if (len <= 0) {
            break;
        }
        ap_rwrite(buf, len, r);
    }
}
Exemplo n.º 13
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);
}
Exemplo n.º 14
0
static BOOL SendResponseHeaderEx(isapi_cid *cid, const char *stat,
                                 const char *head, DWORD statlen,
                                 DWORD headlen)
{
    int termarg;
    char *termch;

    if (!stat || statlen == 0 || !*stat) {
        stat = "Status: 200 OK";
    }
    else {
        char *newstat;
        newstat = ap_palloc(cid->r->pool, statlen + 9);
        strcpy(newstat, "Status: ");
        ap_cpystrn(newstat + 8, stat, statlen + 1);
        stat = newstat;
    }

    if (!head || headlen == 0 || !*head) {
        head = "\r\n";
    }
    else
    {
        if (head[headlen]) {
            /* Whoops... not NULL terminated */
            head = ap_pstrndup(cid->r->pool, head, headlen);
        }
    }

    /* Parse them out, or die trying */
    cid->status = ap_scan_script_header_err_strs(cid->r, NULL, &termch,
                                                 &termarg, stat, head, NULL);
    cid->ecb->dwHttpStatusCode = cid->r->status;

    /* All the headers should be set now */
    ap_send_http_header(cid->r);

    /* Any data left should now be sent directly,
     * it may be raw if headlen was provided.
     */
    if (termch && (termarg == 1)) {
        if (headlen == -1 && *termch)
            ap_rputs(termch, cid->r);
        else if (headlen > (size_t) (termch - head))
            ap_rwrite(termch, headlen - (termch - head), cid->r);
    }

    if (cid->status == HTTP_INTERNAL_SERVER_ERROR)
        return FALSE;
    return TRUE;
}
Exemplo n.º 15
0
static int
svc_simulator_256b_process_request(
    request_rec * request)
{
    char *http_version = NULL;
    int content_length = -1;
    unsigned int body_string_len = 0;
    int send_status = DECLINED;
    char *content_type = NULL;
    /*char request_url[128];*/

    /*sprintf(request_url, "http://%s:%d%s", request->hostname, request->parsed_uri.port, request->unparsed_uri);
    if(!request_url)
    {
        ap_log_rerror(APLOG_MARK, APLOG_EMERG, 0, request, "[svc_simulator_256b] request url:%s", request_url);
    }*/
    content_length = (int)request->remaining;
    /* We are sure that the difference lies within the int range */
    http_version = request->protocol;

    content_type = (char *)apr_table_get(request->headers_in,
        SVC_SIMULATOR_HTTP_HEADER_CONTENT_TYPE);
    if(!content_type)
    {
        content_type = SVC_SIMULATOR_HTTP_HEADER_ACCEPT_TEXT_PLAIN;
    }
    request->content_type = content_type;

    if(request->read_chunked == 1 && 0 == content_length)
    {
        content_length = -1;
        request->chunked = 1;
    }
    if(!http_version)
    {
        return DECLINED;
    }

    /*request->content_type = SVC_SIMULATOR_HTTP_HEADER_ACCEPT_TEXT_XML;*/


    /*ap_log_rerror(APLOG_MARK, APLOG_EMERG, 0, request, "[svc_simulator_256b] path:%s", request->unparsed_uri);*/
    send_status = OK;

    /*ap_log_rerror(APLOG_MARK, APLOG_EMERG, 0, request, "[svc_simulator_256b] bodystring:%s", simulator_worker->bodystring);*/
    ap_rwrite((char *) simulator_worker->bodystring, simulator_worker->bodystring_len, request);

    return send_status;
}
Exemplo n.º 16
0
static int
php_apache_sapi_ub_write(const char *str, uint str_length TSRMLS_DC)
{
	request_rec *r;
	php_struct *ctx;

	ctx = SG(server_context);
	r = ctx->r;

	if (ap_rwrite(str, str_length, r) < 0) {
		php_handle_aborted_connection();
	}

	return str_length; /* we always consume all the data passed to us. */
}
Exemplo n.º 17
0
static int output_body_obj(request_rec *r, SV *obj, int type)
{
    dTHX;
    SV *buf_sv;
    apr_off_t clen = 0;
    STRLEN len;
    dSP;
    char *buf;
    int count;

    if (type == SVt_PVMG && !respond_to(obj, "getline")) {
        server_error(r, "response body object must be able to getline");
        return HTTP_INTERNAL_SERVER_ERROR;
    }

    ENTER;
    SAVETMPS;
    SAVESPTR(PL_rs);
    PL_rs = newRV_inc(newSViv(AP_IOBUFSIZE));
    while (1) {
        PUSHMARK(SP);
        XPUSHs(obj);
        PUTBACK;
        count = call_method("getline", G_SCALAR);
        if (count != 1) croak("Big trouble\n");
        SPAGAIN;
        buf_sv = POPs;
        if (SvOK(buf_sv)) {
            buf = SvPV(buf_sv, len);
            clen += len;
            ap_rwrite(buf, len, r);
        } else {
            break;
        }
    }
    if (clen > 0) {
        ap_set_content_length(r, clen);
    }
    PUSHMARK(SP);
    XPUSHs(obj);
    PUTBACK;
    call_method("close", G_DISCARD);
    SPAGAIN;
    PUTBACK;
    FREETMPS;
    LEAVE;
    return OK;
}
Exemplo n.º 18
0
static int
write_client_data (request_rec * r, const char * data, unsigned int n_bytes)
{
  while (n_bytes > 0)
    {
      int n = (ap_rwrite (data, n_bytes, r));
      if (n < 0)
	{
	  ML_LOG_PERROR (r, "error writing to client");
	  return (0);
	}
      n_bytes -= n;
      data += n;
    }
  return (1);
}
Exemplo n.º 19
0
static int req_print (lua_State *L)
{
  int i = 0;
  int status = 1;
  int n = lua_gettop(L);
  request_rec *r = CHECK_REQUEST_OBJECT(1);
  size_t l;
  const char *s;

  for (i = 2; i <= n && status; i++)
  {
    s = luaL_checklstring(L, i, &l);
    status =  (ap_rwrite(s, l, r) == (int)l) ? 1 : 0;
  }
  return pushresult(L, status, r->filename);
}
Exemplo n.º 20
0
static int lua_ap_send(lua_State *L)
{
  request_rec *r = CHECK_REQUEST_OBJECT(1);
  size_t len;
  const char* dat = luaL_checklstring(L, 2, &len);
  int flush = lua_isnone(L, 3) ? 1 : lua_toboolean(L, 3);
  int s = ap_rwrite(dat, len, r);
  if (s == len)
  {
    s = flush ? ap_rflush(r) : 0;
  }

  lua_pushboolean(L, s == 0);
  lua_pushinteger(L, s);
  return 2;
}
Exemplo n.º 21
0
static ssize_t
write_data(void *fd, void *buf, size_t siz)
{
	ssize_t len_written;
	request_rec *ap_r = (request_rec *)fd;

#ifndef APACHE2
	ap_reset_timeout(ap_r);
#endif
#ifdef DEBUG
	dump_buffer(stderr, "write_data:", buf, siz);
#endif
	len_written = ap_rwrite(buf, siz, ap_r);

	return (len_written);
}
Exemplo n.º 22
0
static am_status_t set_custom_response(am_request_t *rq, const char *text, const char *cont_type) {
    request_rec *r = (request_rec *) (rq != NULL ? rq->ctx : NULL);
    if (r == NULL || !ISVALID(text)) return AM_EINVAL;
    if (rq->status == AM_INTERNAL_REDIRECT) {
        ap_internal_redirect(text, r);
        rq->status = AM_DONE;
    } else if (rq->status == AM_REDIRECT) {
        apr_table_add(r->headers_out, "Location", text);
        ap_custom_response(r, HTTP_MOVED_TEMPORARILY, text);
    } else {
        if (rq->status == AM_PDP_DONE) {
            request_rec *sr = ap_sub_req_method_uri(am_method_num_to_str(rq->method),
                    rq->post_data_url, r, NULL);

            sr->headers_in = r->headers_in;
            sr->notes = r->notes;

            am_log_debug(rq->instance_id, "set_custom_response(): issuing sub-request %s to %s",
                    sr->method, rq->post_data_url);

            ap_run_sub_req(sr);
            ap_destroy_sub_req(sr);
            rq->status = AM_DONE;

        } else {
            size_t tl = strlen(text);
            if (ISVALID(cont_type)) {
                ap_set_content_type(r, cont_type);
            }
            ap_set_content_length(r, tl);
            ap_rwrite(text, (int) tl, r);
            ap_custom_response(r,
                    am_status_value(rq->status == AM_SUCCESS ||
                    rq->status == AM_DONE ? AM_SUCCESS : rq->status), text);
            ap_rflush(r);
        }
    }
    am_log_info(rq->instance_id, "set_custom_response(): status: %s", am_strerror(rq->status));
    return AM_SUCCESS;
}
Exemplo n.º 23
0
BOOL WINAPI WriteClient (HCONN ConnID, LPVOID Buffer, LPDWORD lpwdwBytes,
                         DWORD dwReserved) {
    request_rec *r = ((isapi_cid *)ConnID)->r;

    /* We only support synchronous writing */
    if (dwReserved && dwReserved != HSE_IO_SYNC) {
        if (LogNotSupported)
            ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING, r,
                          "ISAPI asynchronous I/O not supported: %s", 
                          r->filename);
        SetLastError(ERROR_INVALID_PARAMETER);
        return FALSE;
    }

    if ((*lpwdwBytes = ap_rwrite(Buffer, *lpwdwBytes, r)) <= 0) {
        if (!GetLastError())
            SetLastError(ERROR); /* XXX: Find the right error code */
        return FALSE;
    }

    return TRUE;
}
Exemplo n.º 24
0
apr_status_t jxr_process_response_body(jaxer_connection *ac, request_rec *r)
{
	apr_status_t rv = APR_SUCCESS;
	apr_size_t pos;
	char type;
	unsigned char *buf;

	//Read Body, build bb
	while (1)
	{
		apr_size_t datalen;
		
		rv = jxr_receive_message(ac, &buf);
		if ( rv != APR_SUCCESS)
		{
			compat_log_rerror(APLOG_MARK, APLOG_WARNING, rv, r, "mod_jaxer: received document data failed");
			return rv;
		}


		type = jxr_msg_get_type(buf);
		datalen = jxr_msg_get_length(buf,  &pos);

		if (type == BLOCKTYPE_ENDREQUEST)
		{
			// Done
			break;
		}else if ( type != BLOCKTYPE_DOCUMENT)
		{
			// Error
			compat_log_error(APLOG_MARK, APLOG_WARNING, rv, r->server, "mod_jaxer: invalid data type (%c) received, while expecting a body (%d)", type, BLOCKTYPE_DOCUMENT);
			return HTTP_INTERNAL_SERVER_ERROR;
		}

		ap_rwrite(buf + sizeof (Jaxer_Header), datalen, r);
	}

	return rv;
}
Exemplo n.º 25
0
static int
fsend(struct soap *psoap, const char *pBuf, apr_size_t len)
{
    int nRet = SOAP_OK;
    gsoapRequestConfiguration *pRqConf = getRequestConfiguration(psoap);

    if (NULL != pRqConf)
    {
        request_rec *r = pRqConf->r;

        if (!pRqConf->headers_sent)
        {
            /*          ap_send_http_header(r); */
            pRqConf->headers_sent = TRUE;
        }
        nRet = ap_rwrite(pBuf, len, r) == len ? SOAP_OK : SOAP_FAULT;
    }
    else
    {
        nRet = SOAP_FAULT;
    }
    return nRet;
}
Exemplo n.º 26
0
static PyObject * req_write(requestobject *self, PyObject *args)
{
    int len;
    int rc;
    char *buff;

    if (! PyArg_ParseTuple(args, "s#", &buff, &len))
	return NULL;  /* bad args */

    Py_BEGIN_ALLOW_THREADS
    ap_rwrite(buff, len, self->request_rec);
    rc = ap_rflush(self->request_rec);
    Py_END_ALLOW_THREADS
    if (rc == EOF) {
	PyErr_SetString(PyExc_IOError, "Write failed, client closed connection.");
	return NULL;
    }


    Py_INCREF(Py_None);
    return Py_None;

}
Exemplo n.º 27
0
static int output_body_ary(request_rec *r, AV *bodys)
{
    dTHX;
    SV **body;
    I32 i;
    I32 lastidx;
    char *buf;
    STRLEN len;
    apr_off_t clen = 0;

    lastidx = av_len(bodys);
    for (i = 0; i <= lastidx; i++) {
        body = av_fetch(bodys, i, 0);
        if (SvOK(*body)) {
            buf = SvPV(*body, len);
            ap_rwrite(buf, len, r);
            clen += len;
        }
    }
    if (clen > 0) {
        ap_set_content_length(r, clen);
    }
    return OK;
}
Exemplo n.º 28
0
static int abstract_search_handler(request_rec *r, softbot_handler_rec *s)
{
    int rv = 0;
    int i = 0;
	int recv_pos = 0;
    memfile *buf = NULL;
	virtual_document_t* vd = NULL;
    int max_doc_hits_size = 0;

    sb_run_qp_get_max_doc_hits_size( &max_doc_hits_size );

    init_server(r, s);

	set_con_config(r->server);
	msg_record_init(&s->msg);

	rv = sb_run_qp_init();
    if(rv != SUCCESS && rv != DECLINE) {
	    MSG_RECORD(&s->msg, error, "qp init failed");
        return FAIL;
    }

	if(apr_table_get(s->parameters_in, "q") == NULL ||
			strlen(apr_table_get(s->parameters_in, "q")) == 0) {
	    MSG_RECORD(&s->msg, error, "query is null, must use http get method");
        return FAIL;
	}

	ap_unescape_url((char *)apr_table_get(s->parameters_in, "q"));

    rv = sb_run_qp_init_request(&qp_request, 
                                (char *)apr_table_get(s->parameters_in, "q"));
    if(rv != SUCCESS) {
	    s->msg = qp_request.msg;
        error("can not init request");
        return FAIL;
    }

    rv = sb_run_qp_init_response(&qp_response);
    if(rv != SUCCESS) {
	    s->msg = qp_request.msg;
        error("can not init request");
        return FAIL;
    }

	/* 수신할 doc_hit 를 assign */
	qp_response.vdl->cnt = 1;
	vd = &(qp_response.vdl->data[0]);

	if(g_dochits_buffer == NULL) {
		g_dochits_buffer = (doc_hit_t*)sb_calloc(max_doc_hits_size, sizeof(doc_hit_t));
	}

    vd->dochits = g_dochits_buffer; 

	/* comment를 추출할 virtual document 정보 받기 */
	CHECK_REQUEST_CONTENT_TYPE(r, "x-softbotd/binary");

	if (sb_run_sbhandler_make_memfile(r, &buf) != SUCCESS) {
	    MSG_RECORD(&s->msg, error, "make_memfile_from_postdata failed");
        if(buf != NULL) memfile_free(buf);
		return FAIL;
	}

    vd->dochit_cnt = memfile_getSize(buf) / (sizeof(doc_hit_t) + sizeof(uint32_t));
    for (i = 0; i < vd->dochit_cnt; i++) {
		uint32_t node_id = 0;
		uint32_t recv_data_size = 0;

        recv_data_size = sizeof(doc_hit_t);
        if ( memfile_read(buf, (char*)&(vd->dochits[recv_pos]), recv_data_size)
                != recv_data_size ) {
			MSG_RECORD(&s->msg, error, "incomplete result at [%d]th node: doc_hits ", i);
            if(buf != NULL) memfile_free(buf);
            return FAIL;
        }

		// 2. node_id 수신
		recv_data_size = sizeof(uint32_t);
		if ( memfile_read(buf, (char*)&node_id, recv_data_size)
				!= recv_data_size ) {
			MSG_RECORD(&s->msg, error, "incomplete result at [%d]th node: node_id ", i);
            if(buf != NULL) memfile_free(buf);
			return FAIL;
		}

		// 자신의 node_id가 아니면 error
		if(get_node_id(node_id) != this_node_id) {
			MSG_RECORD(&s->msg, 
			              error, "node_id[%u] not equals this_node_id[%0X]",
						  get_node_id(node_id),
						  this_node_id);
            if(buf != NULL) memfile_free(buf);
			return FAIL;
		}

		debug("did[%u], node_id[%0X]", vd->dochits[recv_pos].id, node_id);

        // 자신의 node_id pop
        node_id = pop_node_id(node_id);
		recv_pos++;
    }
	vd->dochit_cnt = recv_pos;


	/* comment 추출 */
	timelog("sb_run_qp_abstract_search start");
	rv = sb_run_qp_abstract_search(&qp_request, &qp_response);
	timelog("sb_run_qp_abstract_search finish");
	if (rv != SUCCESS) {
	    s->msg = qp_request.msg;
		error("sb_run_qp_abstract_search failed: query[%s]", qp_request.query);
        if(buf != NULL) memfile_free(buf);
		return FAIL;
	}

    /////////// abstarct search 결과 전송 ////////////////////////////////////////
    ap_set_content_type(r, "x-softbotd/binary");

    // 1. 전송건수.
    ap_rwrite(&vd->comment_cnt, sizeof(uint32_t), r);
	
	// 2. doc_hits 전송.
    for (i = 0; i < vd->comment_cnt; i++ ) {
        // 2.1 doc_id 전송.
        ap_rwrite(&vd->dochits[i].id, sizeof(uint32_t), r);
        // 2.2 node_id 전송.
        ap_rwrite(&this_node_id, sizeof(uint32_t), r);
        // 2.3. comment
        ap_rwrite(qp_response.comments[i].s, LONG_LONG_STRING_SIZE, r);
		debug("comments[%s]", qp_response.comments[i].s);
    }

    // log를 위하여 setting 해준다.
    qp_response.search_result = vd->comment_cnt;

	s->msg = qp_request.msg;

    if(buf != NULL) memfile_free(buf);
	return SUCCESS;
}
Exemplo n.º 29
0
static int light_search_handler(request_rec *r, softbot_handler_rec *s)
{
    int rv = 0;
    int i = 0;

    init_server(r, s);

	set_con_config(r->server);
	msg_record_init(&s->msg);

	rv = sb_run_qp_init();
    if(rv != SUCCESS && rv != DECLINE) {
	    MSG_RECORD(&s->msg, error, "qp init failed");
        return FAIL;
    }

	if(apr_table_get(s->parameters_in, "q") == NULL ||
			strlen(apr_table_get(s->parameters_in, "q")) == 0) {
	    MSG_RECORD(&s->msg, error, "query is null, must use http get method");
        return FAIL;
	}

	ap_unescape_url((char *)apr_table_get(s->parameters_in, "q"));

    rv = sb_run_qp_init_request(&qp_request, 
                                (char *)apr_table_get(s->parameters_in, "q"));
    if(rv != SUCCESS) {
	    s->msg = qp_request.msg;
        error("can not init request");
        return FAIL;
    }

    rv = sb_run_qp_init_response(&qp_response);
    if(rv != SUCCESS) {
	    s->msg = qp_request.msg;
        error("can not init request");
        return FAIL;
    }

	timelog("sb_run_qp_light_search start");
	rv = sb_run_qp_light_search(&qp_request, &qp_response);
	timelog("sb_run_qp_light_search finish");
	if (rv != SUCCESS) {
	    s->msg = qp_request.msg;
		error("sb_run_qp_light_search failed: query[%s]", qp_request.query);
		return FAIL;
	}

	ap_set_content_type(r, "x-softbotd/binary");

	timelog("send_result_start");

	// 0. node id - 0 ~ 16 
	ap_rwrite(&(this_node_id), sizeof(uint32_t), r);

	// 1. 총 검색건수 
	ap_rwrite(&(qp_response.search_result), sizeof(uint32_t), r);

	// 2. 전송 검색건수
	ap_rwrite(&(qp_response.vdl->cnt), sizeof(uint32_t), r);

	// 3. 검색 단어 리스트
	ap_rwrite(qp_response.parsed_query, sizeof(qp_response.parsed_query), r);

	debug("search_result[%u], send_cnt[%u], parsed_query[%s]", 
			qp_response.search_result,
			qp_response.vdl->cnt,
			qp_response.parsed_query);

    // 4. 검색결과 전송
    for(i = 0; i < qp_response.vdl->cnt; i++) {
		virtual_document_t* vd = &(qp_response.vdl->data[i]);
   
        print_virtual_document(vd);

		ap_rwrite((void*)&vd->id, sizeof(uint32_t), r);

		ap_rwrite((void*)&vd->relevance, sizeof(uint32_t), r);

		ap_rwrite((void*)&vd->dochit_cnt, sizeof(uint32_t), r);

		ap_rwrite((void*)vd->dochits, sizeof(doc_hit_t)*vd->dochit_cnt, r);

		ap_rwrite(&(this_node_id), sizeof(uint32_t), r);
		debug("send node_id[%0X]", this_node_id);
    
	    ap_rwrite((void*)vd->docattr, sizeof(docattr_t), r);
    }

    timelog("send_result_finish");

	s->msg = qp_request.msg;
	sb_run_qp_finalize_search(&qp_request, &qp_response);
	timelog("qp_finalize");

	return SUCCESS;
}
Exemplo n.º 30
0
/* The wiki handler */
static int wiki_handler(request_rec *r)
{
    wiki_conf *conf;
    git_repository *repo;
    const git_oid *tree_oid;
    char *path;

    const git_oid *oid;
    char hash[41];
    hash[40] = '\0';
    int ret;
    int type;

    MMIOT *doc;

    if (strcmp(r->handler, "wiki")) {
        return DECLINED;
    }

    if (r->header_only) {
        return OK;
    }

    conf =
        (wiki_conf *) ap_get_module_config(r->per_dir_config,
                                           &wiki_module);

    ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "filename=%s",
                  r->filename);
    if (conf->basepath) {
        path = ltrim(conf->basepath, r->parsed_uri.path);
    } else {
        path = r->parsed_uri.path + 1;
    }

    ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "path=%s", path);
    ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
                  "r->content_type=%s", r->content_type);

    if (conf->repo == NULL) {
        ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
                      "WikiRepository is not set.");
        return HTTP_INTERNAL_SERVER_ERROR;
    }
    ret = git_repository_open(&repo, conf->repo);
    if (ret) {
        ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
                      "Cannot open git repository.(%s)", conf->repo);
        return HTTP_INTERNAL_SERVER_ERROR;
    }

    tree_oid = lookup_master_tree(repo);
    if (tree_oid == NULL) {
        ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
                      "Not found master tree.");
        git_repository_free(repo);
    }

    type = lookup_object_oid(r, repo, tree_oid, path, &oid);
    if (type == WIKI_NOTFOUND) {
        ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
                      "Object is not found.");
        git_repository_free(repo);
        return HTTP_NOT_FOUND;
    } else if(type == WIKI_DIR) {
        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
                      "Directory listing is not implement yet.");
        git_repository_free(repo);
        return HTTP_FORBIDDEN;
    } else if(type == WIKI_ERROR) {
        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
                      "Error at lookup.");
        git_repository_free(repo);
        return HTTP_NOT_FOUND;
    }

    git_oid_fmt(hash, oid);
    ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "object hash=%s", hash);

    const char *data;
    size_t size;

    git_odb *odb;
    ret = git_repository_odb(&odb, repo);
    git_odb_object *odb_object;
    ret = git_odb_read(&odb_object, odb, oid);
    data = git_odb_object_data(odb_object);
    size = git_odb_object_size(odb_object);

    git_odb_object_free(odb_object);	// is this safe?

    if (type == WIKI_FOUND) {
        ap_rwrite(data, size, r);
    } else if(type == WIKI_MARKDOWN) {
        r->content_type = "text/html";
        doc = mkd_string(data, size, 0);
        if (doc == NULL) {
            ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
                          "mkd_string() returned NULL\n");
            git_repository_free(repo);
            return HTTP_INTERNAL_SERVER_ERROR;
        }
        wiki_output(doc, r);
        mkd_cleanup(doc);
    } else {
        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
                      "Unknown Error.\n");
        git_repository_free(repo);
        return HTTP_INTERNAL_SERVER_ERROR;
    }

    git_repository_free(repo);
    return OK;
}