Ejemplo n.º 1
0
onion_connection_status oterm_uuid(void *data, onion_request *req, onion_response *res){
  const char *path=onion_request_get_path(req);
  
  ONION_DEBUG("Ask path %s (%p)", path, data);
  // split id / function
  int l=strlen(path)+1;
  char *id=alloca(l);
  char *function=NULL;
  
  int i;
  memcpy(id,path,l);
  int func_pos=0;
  for (i=0;i<l;i++){
    if (id[i]=='/'){
      if (!function && id[i+1]!='\0')
        function=id+i+1;
      id[i]=0;
      func_pos=i;
      break;
    }
  }
  ONION_DEBUG("Id %s, function %s", id, function);
  process *term=oterm_get_process_by_uuid(data, id);
  if (!term)
    return OCS_INTERNAL_ERROR;
  
  if (!function)
    return onion_shortcut_internal_redirect("static/oterm.html", req, res);
  // do it
  onion_request_advance_path(req, func_pos);

  return oterm_process(data, term, function, req, res);
}
Ejemplo n.º 2
0
Archivo: url.c Proyecto: cemonds/onion
/**
 * @short Performs the real request: checks if its for me, and then calls the inside level.
 */
int onion_url_handler(onion_url_data **dd, onion_request *request, onion_response *response){
	onion_url_data *next=*dd;
	regmatch_t match[16];
	int i;
	
	const char *path=onion_request_get_path(request);
	while (next){
		ONION_DEBUG0("Check %s against %s", onion_request_get_path(request), next->orig);
		if (next->flags&OUD_STRCMP){
			if (strcmp(path, next->str)==0){
				ONION_DEBUG0("Ok, simple match.");

				onion_request_advance_path(request, strlen(next->str));
				return onion_handler_handle(next->inside, request, response);
			}
		}
		else if (regexec(&next->regexp, onion_request_get_path(request), 16, match, 0)==0){
			//ONION_DEBUG("Ok,match");
			onion_dict *reqheader=request->GET;
			for (i=1;i<16;i++){
				regmatch_t *rm=&match[i];
				if (rm->rm_so!=-1){
					char *tmp=malloc(rm->rm_eo-rm->rm_so);
					memcpy(tmp, &path[rm->rm_so], rm->rm_eo-rm->rm_so);
					char tmpn[4];
					snprintf(tmpn,sizeof(tmpn),"%d",i);
					onion_dict_add(reqheader, tmpn, tmp, OD_DUP_KEY|OD_FREE_VALUE);
					ONION_DEBUG("Add group %d: %s (%d-%d)", i, tmp, rm->rm_so, rm->rm_eo);
				}
				else
					break;
			}
			onion_request_advance_path(request, match[0].rm_eo);
			ONION_DEBUG0("Ok, regexp match.");

			
			return onion_handler_handle(next->inside, request, response);
		}
		
		next=next->next;
	}
	return 0;
}