/**
 * Returns a new HttpRequest object wrapping the client request
 */
static HttpRequest create_HttpRequest(Socket_T S) {
  HttpRequest req= NULL;
  char url[REQ_STRLEN];
  char line[REQ_STRLEN];
  char protocol[STRLEN]; 
  char method[REQ_STRLEN];

  if(socket_readln(S, line, REQ_STRLEN) == NULL) {
    internal_error(S, SC_BAD_REQUEST, "No request found");
    return NULL;
  }
  Str_chomp(line);
  if(sscanf(line, "%1023s %1023s HTTP/%3[1.0]", method, url, protocol) != 3) {
    internal_error(S, SC_BAD_REQUEST, "Cannot parse request");
    return NULL;
  }
  if(strlen(url) >= MAX_URL_LENGTH) {
    internal_error(S, SC_BAD_REQUEST, "[error] URL too long");
    return NULL;
  }
  NEW(req);
  req->S= S;
  Util_urlDecode(url);
  req->url= Str_dup(url);
  req->method= Str_dup(method);
  req->protocol= Str_dup(protocol); 
  create_headers(req);
  if(!create_parameters(req)) {
    destroy_HttpRequest(req);
    internal_error(S, SC_BAD_REQUEST, "Cannot parse Request parameters");
    return NULL;
  }
  return req;
}
Example #2
0
static int send_xcap_change_notify(struct presentity* _p, struct watcher* _w)
{
	int len = 0;
	int presence_list_changed = _p->flags & PFLAG_PRESENCE_LISTS_CHANGED;
	int watcherinfo_changed = _p->flags & PFLAG_WATCHERINFO_CHANGED;

	
	LOG(L_ERR, "  send_xcap_change flags=%x\n", _p->flags);

	len += sprintf(body.s + len, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n");
	len += sprintf(body.s + len, "<documents xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\r\n");
	if (presence_list_changed) { 
		len += sprintf(body.s + len, "  <document uri=\"http://%.*s/presence-lists/users/%.*s/presence.xml\">\r\n",
			       pa_domain.len, pa_domain.s, _p->uri.len, _p->uri.s);
		len += sprintf(body.s + len, "    <change method=\"PUT\">[email protected]</change>\r\n");
		len += sprintf(body.s + len, "  </document>\r\n");
	}
	if (watcherinfo_changed) {
		len += sprintf(body.s + len, "  <document uri=\"http://%.*s/watcherinfo/users/%.*s/watcherinfo.xml\">\r\n",
			       pa_domain.len, pa_domain.s, _p->uri.len, _p->uri.s);
		len += sprintf(body.s + len, "    <change method=\"PUT\">[email protected]</change>\r\n");
		len += sprintf(body.s + len, "  </document>\r\n");
	}
	len += sprintf(body.s + len, "</documents>\r\n");
	body.len = len;

	if (create_headers(_w) < 0) {
		LOG(L_ERR, "send_location_notify(): Error while adding headers\n");
		return -7;
	}

	tmb.t_request_within(&method, &headers, &body, _w->dialog, 0, 0);
	return 0;
}
Example #3
0
static int send_lpidf_notify(struct presentity* _p, struct watcher* _w)
{
	lpidf_status_t st;
	presence_tuple_t *tuple = _p->tuples;

	if (lpidf_add_presentity(&body, BUF_LEN - body.len, &_p->uri) < 0) {
		LOG(L_ERR, "send_lpidf_notify(): Error in lpidf_add_presentity\n");
		return -2;
	}

	while (tuple) {
		switch(tuple->state) {
		case PS_OFFLINE: st = LPIDF_ST_CLOSED; break;
		default: st = LPIDF_ST_OPEN; break;
		}

		if (lpidf_add_address(&body, BUF_LEN - body.len, &_p->uri, st) < 0) {
			LOG(L_ERR, "send_lpidf_notify(): lpidf_add_address failed\n");
			return -3;
		}

		tuple = tuple->next;
	}

	if (create_headers(_w) < 0) {
		LOG(L_ERR, "send_lpidf_notify(): Error while adding headers\n");
		return -4;
	}

	tmb.t_request_within(&method, &headers, &body, _w->dialog, 0, 0);
	return 0;
}
Example #4
0
static int send_xpidf_notify(struct presentity* _p, struct watcher* _w)
{
	xpidf_status_t st;
	presence_tuple_t *tuple = _p->tuples;

	/* Send a notify, saved Contact will be put in
	 * Request-URI, To will be put in from and new tag
	 * will be generated, callid will be callid,
	 * from will be put in to including tag
	 */

	if (start_xpidf_doc(&body, BUF_LEN) < 0) {
		LOG(L_ERR, "send_xpidf_notify(): start_xpidf_doc failed\n");
		return -1;
	}

	if (xpidf_add_presentity(&body, BUF_LEN - body.len, &_p->uri) < 0) {
		LOG(L_ERR, "send_xpidf_notify(): xpidf_add_presentity failed\n");
		return -3;
	}
	if (!tuple) {
		 LOG(L_ERR, "send_xpidf_notify() NO TUPLE\n");
		 st = XPIDF_ST_CLOSED;
		 if (xpidf_add_address(&body, BUF_LEN - body.len, &_p->uri, st) < 0) {
             LOG(L_ERR, "send_xpidf_notify(): xpidf_add_address failed\n");
             return -3;
         }
	}
	while (tuple) {

		switch(tuple->state) {
		case PS_ONLINE: st = XPIDF_ST_OPEN; break;
		default: st = XPIDF_ST_CLOSED; break;
		}

		if (xpidf_add_address(&body, BUF_LEN - body.len, &_p->uri, st) < 0) {
			LOG(L_ERR, "send_xpidf_notify(): xpidf_add_address failed\n");
			return -3;
		}

		tuple = tuple->next;
	}
	if (end_xpidf_doc(&body, BUF_LEN - body.len) < 0) {
		LOG(L_ERR, "send_xpidf_notify(): end_xpidf_doc failed\n");
		return -5;
	}

	if (create_headers(_w) < 0) {
		LOG(L_ERR, "send_xpidf_notify(): Error while adding headers\n");
		return -6;
	}

	tmb.t_request_within(&method, &headers, &body, _w->dialog, 0, 0);
	return 0;

}
Example #5
0
static int prepare_winfo_notify(struct retr_buf **dst,
                                struct presentity* _p, struct watcher* _w,
                                pa_notify_cb_param_t *cbd)
{
    str doc = STR_NULL;
    str content_type = STR_NULL;
    str headers = STR_NULL;
    int res = 0;
    str body = STR_STATIC_INIT("");
    uac_req_t	uac_r;

    switch (_w->preferred_mimetype) {
    case DOC_WINFO:
        create_winfo_document(_p, _w, &doc, &content_type);
        DEBUG("winfo document created\n");
        break;
    /* other formats ? */
    default:
        ERR("unknow doctype\n");
        return -1;
    }

    if (create_headers(_w, &headers, &content_type) < 0) {
        ERR("Error while adding headers\n");
        str_free_content(&doc);
        str_free_content(&content_type);
        return -7;
    }

    if (!is_str_empty(&doc)) body = doc;
    /* res = tmb.t_request_within(&notify, &headers, &body, _w->dialog, 0, 0); */
    set_uac_req(&uac_r,
                &notify,
                &headers,
                &body,
                _w->dialog,
                TMCB_LOCAL_COMPLETED,
                pa_notify_cb,
                cbd
               );
    res = tmb.prepare_request_within(&uac_r, dst);
    if (res < 0) {
        ERR("Can't send watcherinfo notification (%d)\n", res);
    }
    else {
        _w->document_index++; /* increment index for next document */
    }

    str_free_content(&doc);
    str_free_content(&headers);
    str_free_content(&content_type);

    return res;
}
Example #6
0
void initBucket_nw(Bucket *bucket, unsigned long seed, int symblen,
                   unsigned int k, unsigned int w, unsigned int s, double lt_delta,
                   double lt_c, double eps, unsigned int N, DegDistr code, unsigned int nw, unsigned int Ns) {

    unsigned int i;

    bucket->matrix.seed = seed;
    bucket->symbLen = symblen;
    bucket->matrix.codetype = code;

    bucket->matrix.conf.k = k;
    bucket->matrix.conf.w = w;
    bucket->matrix.conf.s = s;
    bucket->matrix.conf.N = N;
    bucket->matrix.conf.delta = lt_delta;
    bucket->matrix.conf.c = lt_c;
    bucket->matrix.conf.epsShok = eps;

    if (bucket->matrix.symbols != NULL) {

        for (i=0; i<N; i++) {
            if (bucket->matrix.symbols[i].header != NULL)
                free(bucket->matrix.symbols[i].header);
        }

        free(bucket->matrix.symbols);
    }

    bucket->matrix.symbols = (Symbol *) chk_calloc(N, sizeof(Symbol));

    if (bucket->matrix.cumulative != NULL)
        free(bucket->matrix.cumulative);
    bucket->matrix.cumulative = (double *) chk_calloc(w, sizeof(double));

    switch (code) {
    case Luby:
        rubust_soliton_distribution(&bucket->matrix);
        break;
    case Shokrollahi:
        shokrollahi_distribution(&bucket->matrix);
        break;
    default:
        print_error("ERROR: currently only p2p and streaming applications can be used.\n");
        exit(EXIT_FAILURE);
        break;
    }

    if (nw == 0)
        create_headers(&bucket->matrix);
    else
        create_headers_nw(&bucket->matrix, nw, Ns);

    return;
}
Example #7
0
int send_winfo_notify_offline(struct presentity* _p,
                              struct watcher* _w,
                              offline_winfo_t *info,
                              transaction_cb completion_cb, void* cbp)
{
    str doc = STR_NULL;
    str content_type = STR_NULL;
    str headers = STR_NULL;
    str body = STR_STATIC_INIT("");
    uac_req_t	uac_r;

    switch (_w->preferred_mimetype) {
    case DOC_WINFO:
        create_winfo_document_offline(_p, _w, info, &doc, &content_type);
        break;
    /* other formats ? */
    default:
        ERR("send_winfo_notify: unknow doctype\n");
        return -1;
    }

    if (create_headers(_w, &headers, &content_type) < 0) {
        ERR("send_winfo_notify(): Error while adding headers\n");
        str_free_content(&doc);
        str_free_content(&content_type);
        return -7;
    }

    if (!is_str_empty(&doc)) body = doc;
    set_uac_req(&uac_r,
                &notify,
                &headers,
                &body,
                _w->dialog,
                TMCB_LOCAL_COMPLETED,
                completion_cb,
                cbp
               );
    tmb.t_request_within(&uac_r);

    str_free_content(&doc);
    str_free_content(&headers);
    str_free_content(&content_type);

    _w->document_index++; /* increment index for next document */

    if (use_db) db_update_watcher(_p, _w); /* dialog and index have changed */

    return 0;
}
Example #8
0
void reSeedBucket(Bucket *bucket, unsigned long seed) {
    unsigned int i;

    bucket->matrix.seed = seed;

    for (i=0; i<bucket->matrix.conf.N; i++) {
        if (bucket->matrix.symbols[i].header != NULL)
            free(bucket->matrix.symbols[i].header);
    }

    create_headers(&bucket->matrix);

    return;
}
Example #9
0
void reSeedBucket_nw(Bucket *bucket, unsigned long seed, unsigned int nw, unsigned int Ns) {
    unsigned int i;

    bucket->matrix.seed = seed;

    for (i=0; i<bucket->matrix.conf.N; i++) {
        if (bucket->matrix.symbols[i].header != NULL)
            free(bucket->matrix.symbols[i].header);
    }

    if (nw == 0)
        create_headers(&bucket->matrix);
    else
        create_headers_nw(&bucket->matrix, nw, Ns);

    return;
}
Example #10
0
int send_location_notify(struct presentity* _p, struct watcher* _w)
{
	resource_list_t *user = _p->location_package.users;

	LOG(L_ERR, "send_location_notify to watcher %.*s\n", _w->uri.len, _w->uri.s);

	if (location_doc_start(&body, BUF_LEN) < 0) {
		LOG(L_ERR, "send_location_notify(): start_location_doc failed\n");
		return -1;
	}

	if (location_doc_start_userlist(&body, BUF_LEN - body.len, &_p->uri) < 0) {
		LOG(L_ERR, "send_location_notify(): location_add_uri failed\n");
		return -3;
	}

	while (user) {
		if (location_doc_add_user(&body, BUF_LEN - body.len, &user->uri) < 0) {
			LOG(L_ERR, "send_location_notify(): location_add_watcher failed\n");
			return -3;
		}

		user = user->next;
	}

	if (location_doc_end_resource(&body, BUF_LEN - body.len) < 0) {
		LOG(L_ERR, "send_location_notify(): location_add_resource failed\n");
		return -5;
	}

	if (location_doc_end(&body, BUF_LEN - body.len) < 0) {
		LOG(L_ERR, "send_location_notify(): end_xlocation_doc failed\n");
		return -6;
	}

	if (create_headers(_w) < 0) {
		LOG(L_ERR, "send_location_notify(): Error while adding headers\n");
		return -7;
	}

	tmb.t_request_within(&method, &headers, &body, _w->dialog, 0, 0);
	return 0;
}
Example #11
0
static int send_winfo_notify(struct presentity* _p, struct watcher* _w)
{
	watcher_t *watcher = _p->watchers;

	LOG(L_INFO, "send_winfo_notify: watcher=%p winfo_watcher=%p\n", watcher, _w);
	if (start_winfo_doc(&body, BUF_LEN) < 0) {
		LOG(L_ERR, "send_winfo_notify(): start_winfo_doc failed\n");
		return -1;
	}

	if (winfo_start_resource(&body, BUF_LEN - body.len, &_p->uri, _w) < 0) {
		LOG(L_ERR, "send_winfo_notify(): winfo_add_resource failed\n");
		return -3;
	}

	while (watcher) {
		if (winfo_add_watcher(&body, BUF_LEN - body.len, watcher) < 0) {
			LOG(L_ERR, "send_winfo_notify(): winfo_add_watcher failed\n");
			return -3;
		}

		watcher = watcher->next;
	}

	if (winfo_end_resource(&body, BUF_LEN - body.len) < 0) {
		LOG(L_ERR, "send_winfo_notify(): winfo_add_resource failed\n");
		return -5;
	}

	if (end_winfo_doc(&body, BUF_LEN - body.len) < 0) {
		LOG(L_ERR, "send_winfo_notify(): end_xwinfo_doc failed\n");
		return -6;
	}

	if (create_headers(_w) < 0) {
		LOG(L_ERR, "send_winfo_notify(): Error while adding headers\n");
		return -7;
	}

	tmb.t_request_within(&method, &headers, &body, _w->dialog, 0, 0);
	return 0;
}
Example #12
0
int prepare_unauthorized_notify(struct retr_buf **dst,
                                struct presentity* _p, struct watcher* _w,
                                pa_notify_cb_param_t *cbd)
{
    str headers = STR_NULL;
    str body = STR_STATIC_INIT("");
    int res;
    unc_req_t	uac_r;

    /* send notifications to unauthorized (pending) watchers */
    if (create_headers(_w, &headers, NULL) < 0) {
        LOG(L_ERR, "notify_unauthorized_watcher(): Error while adding headers\n");
        return -7;
    }

    set_uac_req(&uac_r,
                &notify,
                &headers,
                &body,
                _w->dialog,
                TMCB_LOCAL_COMPLETED,
                pa_notify_cb,
                cbd
               );
    res = tmb.prepare_request_within(&uac_r, dst);
    if (res < 0) {
        ERR("Can't send NOTIFY (%d) in dlg %.*s, %.*s, %.*s\n", res,
            FMT_STR(_w->dialog->id.call_id),
            FMT_STR(_w->dialog->id.rem_tag),
            FMT_STR(_w->dialog->id.loc_tag));
    }

    str_free_content(&headers);


    return res;
}
Example #13
0
static GimpPDBStatusType
save_image (const gchar *filename,
            gint32       image_ID,
            gint32       drawable_ID,
            gint32       run_mode)
{
  GimpPDBStatusType  status = GIMP_PDB_SUCCESS;
  gchar             *ext;
  gchar             *tmpname;
  gchar             *mailcmd[3];
  GPid               mailpid;
  FILE              *mailpipe;
  GError            *error = NULL;

  ext = find_extension (filename);

  if (ext == NULL)
    return GIMP_PDB_CALLING_ERROR;

  /* get a temp name with the right extension and save into it. */
  tmpname = gimp_temp_name (ext + 1);

  /* construct the "sendmail user@location" line */
  mailcmd[0] = SENDMAIL;
  mailcmd[1] = mail_info.receipt;
  mailcmd[2] = NULL;

  /* create a pipe to sendmail */
  mailpipe = sendmail_pipe (mailcmd, &mailpid);

  if (mailpipe == NULL)
    return GIMP_PDB_EXECUTION_ERROR;

  create_headers (mailpipe);

  fflush (mailpipe);

  if (! (gimp_file_save (run_mode,
                         image_ID,
                         drawable_ID,
                         tmpname,
                         tmpname) && valid_file (tmpname)))
    {
      goto error;
    }

  if (! to64 (tmpname, mailpipe, &error))
    {
      g_message ("%s", error->message);
      g_error_free (error);
      goto error;
    }

  fprintf (mailpipe, "\n--GUMP-MIME-boundary--\n");

  goto cleanup;

error:
  /* stop sendmail from doing anything */
  kill (mailpid, SIGINT);
  status = GIMP_PDB_EXECUTION_ERROR;

cleanup:
  /* close out the sendmail process */
  fclose (mailpipe);
  waitpid (mailpid, NULL, 0);
  g_spawn_close_pid (mailpid);

  /* delete the tmpfile that was generated */
  g_unlink (tmpname);
  g_free (tmpname);

  return status;
}
Example #14
0
static int prepare_presence_notify(struct retr_buf **dst,
                                   struct presentity* _p, struct watcher* _w,
                                   pa_notify_cb_param_t *cbd)
{
    /* Send a notify, saved Contact will be put in
     * Request-URI, To will be put in from and new tag
     * will be generated, callid will be callid,
     * from will be put in to including tag
     */
    str doc = STR_NULL;
    str content_type = STR_NULL;
    str headers = STR_NULL;
    str body = STR_STATIC_INIT("");
    int res = 0;
    uac_req_t	uac_r;

    switch(_w->preferred_mimetype) {
    case DOC_XPIDF:
        res = create_xpidf_document(&_p->data, &doc, &content_type);
        break;

    case DOC_LPIDF:
        res = create_lpidf_document(&_p->data, &doc, &content_type);
        break;

    case DOC_CPIM_PIDF:
        res = create_cpim_pidf_document(&_p->data, &doc, &content_type);
        break;

    case DOC_MSRTC_PIDF:
    case DOC_PIDF:
    default:
        res = create_pidf_document(&_p->data, &doc, &content_type);
    }

    if (res != 0) {
        LOG(L_ERR, "can't create presence document (%d)\n", _w->preferred_mimetype);
        return -2;
    }

    if (create_headers(_w, &headers, &content_type) < 0) {
        LOG(L_ERR, "send_presence_notify(): Error while adding headers\n");
        str_free_content(&doc);
        str_free_content(&content_type);

        return -7;
    }

    if (!is_str_empty(&doc)) body = doc;
    /*	res = tmb.t_request_within(&notify, &headers, &body,
    			_w->dialog, pa_notify_cb, cbd);*/
    set_uac_req(&uac_r,
                &notify,
                &headers,
                &body,
                _w->dialog,
                TMCB_LOCAL_COMPLETED,
                pa_notify_cb,
                cbd
               );
    res = tmb.prepare_request_within(&uac_r, dst);
    if (res < 0) {
        ERR("Can't send NOTIFY (%d) in dlg %.*s, %.*s, %.*s\n", res,
            FMT_STR(_w->dialog->id.call_id),
            FMT_STR(_w->dialog->id.rem_tag),
            FMT_STR(_w->dialog->id.loc_tag));
    }

    str_free_content(&doc);
    str_free_content(&headers);
    str_free_content(&content_type);

    return res;
}
Example #15
0
static int send_pidf_notify(struct presentity* _p, struct watcher* _w)
{
	xpidf_status_t st;
	presence_tuple_t *tuple = _p->tuples;

	/* Send a notify, saved Contact will be put in
	 * Request-URI, To will be put in from and new tag
	 * will be generated, callid will be callid,
	 * from will be put in to including tag
	 */

	LOG(L_ERR, "  send_pidf_notify\n");

	if (start_pidf_doc(&body, BUF_LEN) < 0) {
		LOG(L_ERR, "send_pidf_notify(): start_pidf_doc failed\n");
		return -1;
	}

	if (pidf_add_presentity(&body, BUF_LEN - body.len, &_p->uri) < 0) {
		LOG(L_ERR, "send_pidf_notify(): pidf_add_presentity failed\n");
		return -3;
	}
	/* XXX add !tuple handler */
	if (tuple) {
		while (tuple) {
			if (pidf_start_tuple(&body, &tuple->id, BUF_LEN - body.len) < 0) {
				LOG(L_ERR, "send_pidf_notify(): start_pidf_tuple failed\n");
				return -4;
			}

			switch(tuple->state) {
			case PS_ONLINE: st = XPIDF_ST_OPEN; break;
			default: st = XPIDF_ST_CLOSED; break;
			}

			if (pidf_add_contact(&body, BUF_LEN - body.len, &tuple->contact, tuple->priority) < 0) {
				LOG(L_ERR, "send_pidf_notify(): pidf_add_contact failed\n");
				return -3;
			}

			if (pidf_start_status(&body, BUF_LEN - body.len, st) < 0) {
				LOG(L_ERR, "send_pidf_notify(): pidf_start_status failed\n");
				return -3;
			}

			if (pidf_add_location(&body, BUF_LEN - body.len,
					      &tuple->location.loc,
					      &tuple->location.site, &tuple->location.floor, &tuple->location.room,
					      tuple->location.x, tuple->location.y, tuple->location.radius, 
					      tuple->prescaps) < 0) {
				LOG(L_ERR, "send_pidf_notify(): pidf_add_location failed\n");
				return -4;
			}

			if (pidf_end_status(&body, BUF_LEN - body.len) < 0) {
				LOG(L_ERR, "send_pidf_notify(): pidf_end_status failed\n");
				return -5;
			}

			if (pidf_end_tuple(&body, BUF_LEN - body.len) < 0) {
				LOG(L_ERR, "send_pidf_notify(): end_pidf_tuple failed\n");
				return -5;
			}
			tuple = tuple->next;
		}
	} else {
		str id = { "ser", 3 };
		str contact = { NULL, 0 };
		float priority = 0.8;
		st = XPIDF_ST_CLOSED;
		if (pidf_start_tuple(&body, &id, BUF_LEN - body.len) < 0) {
			LOG(L_ERR, "send_pidf_notify(): start_pidf_tuple failed\n");
			return -4;
		}

		if (pidf_add_contact(&body, BUF_LEN - body.len, &contact, priority) < 0) {
			LOG(L_ERR, "send_pidf_notify(): pidf_add_contact failed\n");
			return -3;
		}

		if (pidf_start_status(&body, BUF_LEN - body.len, st) < 0) {
			LOG(L_ERR, "send_pidf_notify(): pidf_start_status failed\n");
			return -3;
		}

		if (pidf_end_status(&body, BUF_LEN - body.len) < 0) {
			LOG(L_ERR, "send_pidf_notify(): pidf_end_status failed\n");
			return -5;
		}

		if (pidf_end_tuple(&body, BUF_LEN - body.len) < 0) {
			LOG(L_ERR, "send_pidf_notify(): end_pidf_tuple failed\n");
			return -5;
		}
	}

	if (end_pidf_doc(&body, BUF_LEN - body.len) < 0) {
		LOG(L_ERR, "send_pidf_notify(): end_xpidf_doc failed\n");
		return -6;
	}

	if (create_headers(_w) < 0) {
		LOG(L_ERR, "send_pidf_notify(): Error while adding headers\n");
		return -7;
	}

	tmb.t_request_within(&method, &headers, &body, _w->dialog, 0, 0);
	return 0;
}