Ejemplo n.º 1
0
void
Opal::Presentity::edit_presentity ()
{
  boost::shared_ptr<Ekiga::FormRequestSimple> request =
    boost::shared_ptr<Ekiga::FormRequestSimple> (new Ekiga::FormRequestSimple (boost::bind (&Opal::Presentity::edit_presentity_form_submitted, this, _1, _2, _3)));

  /* Translators: This is Edit name of the contact
   * e.g. Editing Contact Claire Fleury.
   */
  char *title = g_strdup_printf (_("Editing Contact %s"), get_name ().c_str ());
  request->title (title);
  g_free (title);

  request->action (_("Done"));
  request->text ("name", _("Name"),
                 get_name (),
                 _("John Doe"),
                 Ekiga::FormVisitor::STANDARD,
                 false, false);
  request->text ("uri", _("URI"),
                 get_uri (),
                 _("sip:[email protected]"),
                 Ekiga::FormVisitor::URI,
                 false, false);

  request->editable_list ("groups", _("Groups"),
                          get_groups (), existing_groups ());

  questions (request);
}
Ejemplo n.º 2
0
static HRESULT WINAPI HTMLLocation_get_port(IHTMLLocation *iface, BSTR *p)
{
    HTMLLocation *This = impl_from_IHTMLLocation(iface);
    DWORD port;
    IUri *uri;
    HRESULT hres;

    TRACE("(%p)->(%p)\n", This, p);

    if(!p)
        return E_POINTER;

    if(!(uri = get_uri(This))) {
        FIXME("No current URI\n");
        return E_NOTIMPL;
    }

    hres = IUri_GetPort(uri, &port);
    if(FAILED(hres))
        return hres;

    if(hres == S_OK) {
        static const WCHAR formatW[] = {'%','u',0};
        WCHAR buf[12];

        sprintfW(buf, formatW, port);
        *p = SysAllocString(buf);
    }else {
        *p = SysAllocStringLen(NULL, 0);
    }

    if(!*p)
        return E_OUTOFMEMORY;
    return S_OK;
}
Ejemplo n.º 3
0
void
location_goto(struct document_view *doc_view, unsigned char *url)
{
	unsigned char *new_abs_url;
	struct uri *new_uri;
	struct delayed_goto *deg;

	/* Workaround for bug 611. Does not crash, but may lead to infinite loop.*/
	if (!doc_view) return;
	new_abs_url = join_urls(doc_view->document->uri,
	                        trim_chars(url, ' ', 0));
	if (!new_abs_url)
		return;
	new_uri = get_uri(new_abs_url, 0);
	mem_free(new_abs_url);
	if (!new_uri)
		return;
	deg = mem_calloc(1, sizeof(*deg));
	if (!deg) {
		done_uri(new_uri);
		return;
	}
	assert(doc_view->vs);
	deg->vs = doc_view->vs;
	deg->uri = new_uri;
	/* It does not seem to be very safe inside of frames to
	 * call goto_uri() right away. */
	register_bottom_half(delayed_goto, deg);
}
Ejemplo n.º 4
0
static HRESULT WINAPI HTMLLocation_get_hash(IHTMLLocation *iface, BSTR *p)
{
    HTMLLocation *This = impl_from_IHTMLLocation(iface);
    BSTR hash;
    IUri *uri;
    HRESULT hres;

    TRACE("(%p)->(%p)\n", This, p);

    if(!p)
        return E_POINTER;

    if(!(uri = get_uri(This))) {
        FIXME("No current URI\n");
        return E_NOTIMPL;
    }

    hres = IUri_GetFragment(uri, &hash);
    if(hres == S_OK) {
        *p = hash;
    }else if(hres == S_FALSE) {
        SysFreeString(hash);
        *p = NULL;
    }else {
        return hres;
    }

    return S_OK;
}
Ejemplo n.º 5
0
static struct uri *
proxy_uri(struct uri *uri, unsigned char *proxy,
          struct connection_state *error_state)
{
    struct string string;

    if (init_string(&string)
            && string_concat(&string, "proxy://", proxy, "/",
                             (unsigned char *) NULL)
            && add_uri_to_string(&string, uri, URI_BASE)) {
        /* There is no need to use URI_BASE when calling get_uri()
         * because URI_BASE should not add any fragments in the first
         * place. */
        uri = get_uri(string.source, 0);
        /* XXX: Assume the problem is due to @proxy having bad format.
         * This is a lot faster easier than checking the format. */
        if (!uri)
            *error_state = connection_state(S_PROXY_ERROR);
    } else {
        uri = NULL;
        *error_state = connection_state(S_OUT_OF_MEM);
    }

    done_string(&string);
    return uri;
}
Ejemplo n.º 6
0
void
Local::Presentity::edit_presentity ()
{
  ClusterPtr cluster = local_cluster.lock ();

  if (!cluster)
    return;

  boost::shared_ptr<Ekiga::FormRequestSimple> request = boost::shared_ptr<Ekiga::FormRequestSimple> (new Ekiga::FormRequestSimple (boost::bind (&Local::Presentity::edit_presentity_form_submitted, this, _1, _2)));

  std::string name = get_name ();
  std::string uri = get_uri ();
  std::set<std::string> groups = get_groups ();
  std::set<std::string> all_groups = cluster->existing_groups ();

  request->title (_("Edit roster element"));
  request->instructions (_("Please fill in this form to change an existing "
			   "element of ekiga's internal roster"));
  request->text ("name", _("Name:"), name, _("Name of the contact, as shown in your roster"));
  request->text ("uri", _("Address:"), uri, _("Address, e.g. sip:[email protected]; if you do not specify the host part, e.g. sip:xyz, then you can choose it by right-clicking on the contact in roster"));
  request->boolean ("preferred", _("Is a preferred contact"), is_preferred ());

  request->editable_set ("groups", _("Choose groups:"),
			 groups, all_groups);

  questions (request);
}
Ejemplo n.º 7
0
Glib::ustring genericFilechooserWindow::getURIToFile
(
	void
)
{
	return get_uri();
}
Ejemplo n.º 8
0
struct uri *
get_proxied_uri(struct uri *uri)
{
    if (uri->protocol == PROTOCOL_PROXY)
        return get_uri(uri->data, URI_BASE);

    return get_composed_uri(uri, URI_BASE);
}
Ejemplo n.º 9
0
static int setup_http_build_200(http_cb_t * phttp, mime_header_t * presponse_hdr)
{
	char buf[128];
	const char *data;
	const char * type;
        const cooked_data_types_t *pckd;
        int dlen;
	mime_hdr_datatype_t dtype;
	int len;

	// Setup content length
	if (!get_cooked_known_header_data(presponse_hdr,
                                        MIME_HDR_CONTENT_LENGTH, &pckd, &dlen,
                                        &dtype)) {
		if (dtype == DT_SIZE) {
			phttp->content_length = pckd->u.dt_size.ll;
		}
		if( !CHECK_HTTP_FLAG(phttp, HRF_TRANSCODE_CHUNKED) ) {
			len = snprintf(buf, sizeof(buf), "%ld", 
				CHECK_HTTP_FLAG(phttp, HRF_MULTIPART_RESPONSE) ?
					phttp->pseudo_content_length : 
					phttp->content_length);
			add_known_header(presponse_hdr, MIME_HDR_CONTENT_LENGTH, buf, len);
		}
	}


	glob_http_tot_content_length ++;

	if (!is_known_header_present(presponse_hdr, MIME_HDR_CONTENT_TYPE)) {
		const namespace_config_t *nsc;
		/* Only fill up content_type when it is NFS OM */
		nsc = phttp->nsconf;
		if(nsc && nsc->http_config) {
		    if((nsc->http_config->origin.select_method == OSS_NFS_CONFIG) ||
		       (nsc->http_config->origin.select_method == OSS_NFS_SERVER_MAP)) {
			get_uri(phttp, &data, &len);
			type = get_http_content_type(data, len);
			add_known_header(presponse_hdr, MIME_HDR_CONTENT_TYPE, type, strlen(type));
		    }
		}
	}
        delete_known_header(presponse_hdr, MIME_HDR_CONNECTION) ;
	if( CHECK_HTTP_FLAG(phttp, HRF_CONNECTION_KEEP_ALIVE) ) {
		add_known_header(presponse_hdr, MIME_HDR_CONNECTION, "Keep-Alive", 10);
		SET_HTTP_FLAG(phttp, HRF_CONNECTION_KEEP_ALIVE);
	}
	else {
		add_known_header(presponse_hdr, MIME_HDR_CONNECTION, "Close", 5);
		CLEAR_HTTP_FLAG(phttp, HRF_CONNECTION_KEEP_ALIVE);
	}

#if 0
	add_known_header(presponse_hdr, MIME_HDR_CACHE_CONTROL, "no-cache", 8);
#endif

        return 1;
}
Ejemplo n.º 10
0
int
add_favorite(struct tab *t, struct karg *args)
{
	char			file[PATH_MAX];
	FILE			*f;
	char			*line = NULL;
	size_t			urilen, linelen;
	const gchar		*uri, *title;

	if (t == NULL)
		return (1);

	/* don't allow adding of xtp pages to favorites */
	if (t->xtp_meaning != XT_XTP_TAB_MEANING_NORMAL) {
		show_oops(t, "%s: can't add xtp pages to favorites", __func__);
		return (1);
	}

	snprintf(file, sizeof file, "%s" PS "%s", work_dir, XT_FAVS_FILE);
	if ((f = fopen(file, "r+")) == NULL) {
		show_oops(t, "Can't open favorites file: %s", strerror(errno));
		return (1);
	}

	title = get_title(t, FALSE);
	uri = get_uri(t);

	if (title == NULL || uri == NULL) {
		show_oops(t, "can't add page to favorites");
		goto done;
	}

	urilen = strlen(uri);

	for (;;) {
		if ((line = fparseln(f, &linelen, NULL, NULL, 0)) == NULL)
			if (feof(f) || ferror(f))
				break;

		if (linelen == urilen && !strcmp(line, uri))
			goto done;

		free(line);
		line = NULL;
	}

	fprintf(f, "\n%s\n%s", title, uri);
done:
	if (line)
		free(line);
	fclose(f);

	update_favorite_tabs(NULL);

	return (0);
}
Ejemplo n.º 11
0
char * zurl(const char * url, char * opt){
		const char * host = get_host(url);
		const char * uri = get_uri(url);
		unsigned int m,n;
		m = n = 0;
		struct field * data = get_data(uri,&m);
		struct field * params = get_params(uri,&n);
		char * buffer = http_request("GET", host, uri, HTTP_EDITION,
				params, m, data, n,1);
		free_kv(data,m);
		free_kv(params,n);
		return buffer;
}
Ejemplo n.º 12
0
void
Local::Presentity::remove ()
{
  boost::shared_ptr<Ekiga::PresenceCore> pcore = presence_core.lock ();
  if (pcore)
    pcore->unfetch_presence (get_uri ());

  xmlUnlinkNode (node);
  xmlFreeNode (node);

  trigger_saving ();
  removed ();
}
Ejemplo n.º 13
0
static JSBool
smjs_load_uri(JSContext *ctx, uintN argc, jsval *rval)
{
	jsval *argv = JS_ARGV(ctx, rval);
	struct smjs_load_uri_hop *hop;
	struct download *download;
	JSString *jsstr;
	unsigned char *uri_string;
	struct uri *uri;

	if (argc < 2) return JS_FALSE;

	jsstr = JS_ValueToString(smjs_ctx, argv[0]);
	uri_string = JS_EncodeString(smjs_ctx, jsstr);

	uri = get_uri(uri_string, 0);
	if (!uri) return JS_FALSE;

	download = mem_alloc(sizeof(*download));
	if (!download) {
		done_uri(uri);
		return JS_FALSE;
	}

	hop = mem_alloc(sizeof(*hop));
	if (!hop) {
		mem_free(download);
		done_uri(uri);
		return JS_FALSE;
	}

	hop->callback = argv[1];
	hop->ses = smjs_ses;
	if (!JS_AddNamedValueRoot(smjs_ctx, &hop->callback,
			     "smjs_load_uri_hop.callback")) {
		mem_free(hop);
		mem_free(download);
		done_uri(uri);
		return JS_FALSE;
	}

	download->data = hop;
	download->callback = (download_callback_T *) smjs_loading_callback;

	load_uri(uri, NULL, download, PRI_MAIN, CACHE_MODE_NORMAL, -1);

	done_uri(uri);

	return JS_TRUE;
}
Ejemplo n.º 14
0
    lib::error_code process_handshake(request_type const & req,
        std::string const & subprotocol, response_type & res) const
    {
        std::array<char, 16> key_final;

        // copy key1 into final key
        decode_client_key(req.get_header("Sec-WebSocket-Key1"), &key_final[0]);

        // copy key2 into final key
        decode_client_key(req.get_header("Sec-WebSocket-Key2"), &key_final[4]);

        // copy key3 into final key
        // key3 should be exactly 8 bytes. If it is more it will be truncated
        // if it is less the final key will almost certainly be wrong.
        // TODO: decide if it is best to silently fail here or produce some sort
        //       of warning or exception.
        const std::string& key3 = req.get_header("Sec-WebSocket-Key3");
        auto sz = std::min(size_t(8), key3.size());
        std::copy(key3.begin(),
                  key3.begin() + sz,
                  key_final.begin() + 8);

        res.append_header(
            "Sec-WebSocket-Key3",
            md5::md5_hash_string(std::string(key_final.begin(), key_final.end()))
        );

        res.append_header("Upgrade","WebSocket");
        res.append_header("Connection","Upgrade");

        // Echo back client's origin unless our local application set a
        // more restrictive one.
        if (res.get_header("Sec-WebSocket-Origin") == "") {
            res.append_header("Sec-WebSocket-Origin",req.get_header("Origin"));
        }

        // Echo back the client's request host unless our local application
        // set a different one.
        if (res.get_header("Sec-WebSocket-Location") == "") {
            uri_ptr uri = get_uri(req);
            res.append_header("Sec-WebSocket-Location",uri->str());
        }

        if (subprotocol != "") {
            res.replace_header("Sec-WebSocket-Protocol",subprotocol);
        }

        return lib::error_code();
    }
Ejemplo n.º 15
0
/* Establish connection to a peer. As a backend, it uses the internal and more
 * generic connection creater which takes care of DNS querying etc. */
enum bittorrent_state
make_bittorrent_peer_connection(struct bittorrent_connection *bittorrent,
				struct bittorrent_peer *peer_info)
{
	enum bittorrent_state result = BITTORRENT_STATE_OUT_OF_MEM;
	struct uri *uri = NULL;
	struct string uri_string = NULL_STRING;
	struct bittorrent_peer_connection *peer;

	peer = init_bittorrent_peer_connection(-1);
	if (!peer) goto out;

	peer->local.initiater = 1;

	add_to_list(bittorrent->peers, peer);
	peer->bittorrent = bittorrent;

	peer->bitfield = init_bitfield(bittorrent->meta.pieces);
	if (!peer->bitfield) goto out;

	memcpy(peer->id, peer_info->id, sizeof(peer->id));

	/* XXX: Very hacky; construct a fake URI from which make_connection()
	 * can extract the IP address and port number. */
	/* FIXME: Rather change the make_connection() interface. This is an ugly
	 * hack. */
	if (!init_string(&uri_string)) goto out;
	if (!add_format_to_string(&uri_string,
#ifdef CONFIG_IPV6
				  strchr((const char *)peer_info->ip, ':') ?
				  "bittorrent-peer://[%s]:%u/" :
#endif
				  "bittorrent-peer://%s:%u/",
				  peer_info->ip, (unsigned) peer_info->port))
		goto out;
	uri = get_uri(uri_string.source, 0);
	if (!uri) goto out;

	make_connection(peer->socket, uri, send_bittorrent_peer_handshake, 1);
	result = BITTORRENT_STATE_OK;

out:
	if (uri)
		done_uri(uri);
	done_string(&uri_string);
	if (peer && result != BITTORRENT_STATE_OK)
		done_bittorrent_peer_connection(peer);
	return result;
}
Ejemplo n.º 16
0
void file_uri_replace(SessionId sessionId, const char * pJoiner, std::string & data)
{
	qcc::String p;
	vRecvFiles::iterator iter;
	size_t start_pos = 0;
	size_t end_pos;

	while ((start_pos = data.find("file://", start_pos)) != std::string::npos) {
		if ((end_pos = data.find("\'", start_pos)) != std::string::npos) {
			if ((iter = std::find_if(gRecvFiles.begin(), gRecvFiles.end(), find_uri(sessionId, pJoiner, data.substr(start_pos, end_pos - start_pos).data()))) != gRecvFiles.end())
				data.replace(start_pos, end_pos - start_pos, get_uri((*iter)->path.data()).data());
		}
		start_pos++;
	}
}
Ejemplo n.º 17
0
bool
RL::Entry::populate_menu (Ekiga::MenuBuilder& builder)
{
  bool populated = false;
  boost::shared_ptr<Ekiga::PresenceCore> presence_core = core.get<Ekiga::PresenceCore> ("presence-core");
  std::string uri(get_uri ());

  builder.add_action ("refresh", _("_Refresh"),
		      boost::bind (&RL::Entry::refresh, this));

  if ( !uri.empty ())
    populated = presence_core->populate_presentity_menu (Ekiga::PresentityPtr (this, null_deleter ()), uri, builder);

  return populated;
}
Ejemplo n.º 18
0
char *
join(char *baseuri, char *reluri){

  URI *uri;
  char *res;
  int r;

  uri = parseuris(baseuri,reluri);

  if(!uri) return NULL;
  
  res = get_uri(uri);
  uri_destroy(uri);

  return res;
}
Ejemplo n.º 19
0
void
Opal::Presentity::add_actions ()
{
  /* Pull actions */
  boost::shared_ptr<Ekiga::PresenceCore> pcore = presence_core.lock ();
  if (pcore)
    pcore->pull_actions (*this, get_name (), get_uri ());

  add_action (Ekiga::ActionPtr (new Ekiga::Action ("edit", _("_Edit"),
                                                   boost::bind (&Opal::Presentity::edit_presentity, this))));
  add_action (Ekiga::ActionPtr (new Ekiga::Action ("remove", _("_Remove"),
                                                   boost::bind (&Opal::Presentity::remove, this))));
  add_action (Ekiga::ActionPtr (new Ekiga::Action ("rename", _("Rename _Groups"),
                                                   boost::bind (&Opal::Account::on_rename_group,
                                                                (Opal::Account *) &account, get_groups ()))));
}
Ejemplo n.º 20
0
ret_code_t fumi_block_setsource(void)
{
    SaHpiBankNumT banknum;
    SaHpiTextBufferT uri;

    if ( get_banknum( &banknum) != HPI_SHELL_OK ) {
        return HPI_SHELL_PARM_ERROR;
    }
    if ( get_uri( &uri) != HPI_SHELL_OK ) {
        return HPI_SHELL_PARM_ERROR;
    }

    return set_source( Domain->sessionId,
                       fumi_block_env.rptid,
                       fumi_block_env.fuminum,
                       banknum,
                       &uri
                     );
}
Ejemplo n.º 21
0
 void handshake_response(const http::parser::request& request,http::parser::response& response) {
     char key_final[16];
     
     // copy key1 into final key
     decode_client_key(request.header("Sec-WebSocket-Key1"), &key_final[0]);
             
     // copy key2 into final key
     decode_client_key(request.header("Sec-WebSocket-Key2"), &key_final[4]);
             
     // copy key3 into final key
     // key3 should be exactly 8 bytes. If it is more it will be truncated
     // if it is less the final key will almost certainly be wrong.
     // TODO: decide if it is best to silently fail here or produce some sort
     //       of warning or exception.
     const std::string& key3 = request.header("Sec-WebSocket-Key3");
     std::copy(key3.c_str(),
               key3.c_str()+std::min(static_cast<size_t>(8), key3.size()),
               &key_final[8]);
     
     m_key3 = md5_hash_string(std::string(key_final,16));
     
     response.add_header("Upgrade","websocket");
     response.add_header("Connection","Upgrade");
     
     // TODO: require headers that need application specific information?
     
     // Echo back client's origin unless our local application set a
     // more restrictive one.
     if (response.header("Sec-WebSocket-Origin") == "") {
         response.add_header("Sec-WebSocket-Origin",request.header("Origin"));
     }
     
     // Echo back the client's request host unless our local application
     // set a different one.
     if (response.header("Sec-WebSocket-Location") == "") {
         // TODO: extract from host header rather than hard code
         uri_ptr uri = get_uri(request);
         response.add_header("Sec-WebSocket-Location",uri->str());
     }
 }
Ejemplo n.º 22
0
static GFile *
get_download_location (BuilderSourceFile *self,
                       gboolean *is_inline,
                       BuilderContext *context,
                       GError **error)
{
  g_autoptr(SoupURI) uri = NULL;
  const char *path;
  g_autofree char *base_name = NULL;
  GFile *download_dir = NULL;
  g_autoptr(GFile) sha256_dir = NULL;
  g_autoptr(GFile) file = NULL;

  uri = get_uri (self, error);
  if (uri == NULL)
    return FALSE;

  path = soup_uri_get_path (uri);

  if (g_str_has_prefix (self->url, "data:"))
    {
      *is_inline = TRUE;
      return g_file_new_for_path ("inline data");
    }

  base_name = g_path_get_basename (path);

  if (self->sha256 == NULL || *self->sha256 == 0)
    {
      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Sha256 not specified");
      return FALSE;
    }

  download_dir = builder_context_get_download_dir (context);
  sha256_dir = g_file_get_child (download_dir, self->sha256);
  file = g_file_get_child (sha256_dir, base_name);

  *is_inline = FALSE;
  return g_steal_pointer (&file);
}
Ejemplo n.º 23
0
void
html_base(struct html_context *html_context, unsigned char *a,
          unsigned char *xxx3, unsigned char *xxx4, unsigned char **xxx5)
{
	unsigned char *al;

	al = get_url_val(a, (unsigned char *)"href", html_context->doc_cp);
	if (al) {
		unsigned char *base = join_urls(html_context->base_href, al);
		struct uri *uri = base ? get_uri(base, 0) : NULL;

		mem_free(al);
		mem_free_if(base);

		if (uri) {
			done_uri(html_context->base_href);
			html_context->base_href = uri;
		}
	}

	al = get_target(html_context->options, a);
	if (al) mem_free_set(&html_context->base_target, al);
}
Ejemplo n.º 24
0
bool
Local::Presentity::populate_menu (Ekiga::MenuBuilder &builder)
{
  bool populated = false;
  boost::shared_ptr<Ekiga::PresenceCore> pcore = presence_core.lock ();

  if (!pcore)
    return false;

  populated
    = pcore->populate_presentity_menu (PresentityPtr(this, null_deleter ()),
				       get_uri (), builder);

  if (populated)
    builder.add_separator ();

  builder.add_action ("edit", _("_Edit"),
		      boost::bind (&Local::Presentity::edit_presentity, this));
  builder.add_action ("remove", _("_Remove"),
		      boost::bind (&Local::Presentity::remove, this));

  return true;
}
Ejemplo n.º 25
0
static HRESULT WINAPI HTMLLocation_get_protocol(IHTMLLocation *iface, BSTR *p)
{
    HTMLLocation *This = impl_from_IHTMLLocation(iface);
    BSTR protocol, ret;
    unsigned len;
    IUri *uri;
    HRESULT hres;

    TRACE("(%p)->(%p)\n", This, p);

    if(!p)
        return E_POINTER;

    if(!(uri = get_uri(This))) {
        FIXME("No current URI\n");
        return E_NOTIMPL;
    }

    hres = IUri_GetSchemeName(uri, &protocol);
    if(FAILED(hres))
        return hres;
    if(hres == S_FALSE) {
        SysFreeString(protocol);
        *p = NULL;
        return S_OK;
    }

    len = SysStringLen(protocol);
    ret = SysAllocStringLen(protocol, len+1);
    SysFreeString(protocol);
    if(!ret)
        return E_OUTOFMEMORY;

    ret[len] = ':';
    *p = ret;
    return S_OK;
}
Ejemplo n.º 26
0
void Pane::save_state(QSettings *s) {
  s->setValue("path", get_uri());
}
Ejemplo n.º 27
0
int http_session(int* connect_fd,struct sockaddr_in * client_addr)
{
	char recv_buf[RECV_BUFFER_SIZE+1];
	unsigned char send_buf[SEND_BUFFER_SIZE+1];
	unsigned char file_buf[FILE_MAX_SIZE+1];
	memset(recv_buf,'\0',sizeof(recv_buf));
	memset(send_buf,'\0',sizeof(send_buf));
	memset(file_buf,'\0',sizeof(file_buf));
	char uri_buf[URI_SIZE+1];
	memset(uri_buf,'\0',sizeof(uri_buf));
	int maxfd=*connect_fd+1;
	fd_set read_set;
	FD_ZERO(&read_set);
	struct timeval timeout;
	timeout.tv_sec=TIME_OUT_SEC;
	timeout.tv_usec=TIME_OUT_USEC;
	int flag=1;
	int res=0;
	int read_bytes=0;
	int send_bytes=0;
	int file_size=0;
	char * mime_type;
	int uri_status;
	FD_SET(*connect_fd,&read_set);
	while(flag)
	{
		res=select(maxfd,&read_set,NULL,NULL,&timeout);
		switch(res)
		{
			case -1:
				perror("select () error ,in http_session.c");
				close(*connect_fd);
				return -1;
				break;
			case 0:
				continue;
				break;
			default:
				if(FD_ISSET(*connect_fd,&read_set))
				{
					memset(recv_buf,'\0',sizeof(recv_buf));
					if((read_bytes=recv(*connect_fd,recv_buf,RECV_BUFFER_SIZE,0))==0)
					{
						return 0;
					}else if(read_bytes>0)
					{
						if(is_http_protocol(recv_buf)==0)
						{
							fprintf(stderr,"not httlp protocol \n");
							close(*connect_fd);
							return -1;
						}else
						{
							memset(uri_buf,'\0',sizeof(uri_buf));
							if(get_uri(recv_buf,uri_buf)==NULL)
							{
								uri_status=URI_TOO_LONG;
							}
							else
							{
								printf("URI:%s\n",uri_buf);
								uri_status=get_uri_status(uri_buf);
								switch(uri_status)
								{
									case FILE_OK:
										printf("file ok\n");
										mime_type=get_mime_type(uri_buf);
										printf("mime type :%s\n",mime_type);
										file_size=get_file_disk(uri_buf,file_buf);
										send_bytes=reply_normal_information(send_buf,file_buf,file_size,mime_type);
										break;

									case FILE_NOT_FOUND:
										printf("in switch on case FILE_NOT_FOUND\n");
										send_bytes=set_error_information(send_buf,FILE_NOT_FOUND);
										break;
									case FILE_FORBIDEN:
										break;
									default:
										break;

								}
								send(*connect_fd,send_buf,send_bytes,0);
							}
						}


					}
				}
		}
	}
	return 0;
}
Ejemplo n.º 28
0
bool
Local::Presentity::has_uri (const std::string uri) const
{
  return uri == get_uri ();
}
Ejemplo n.º 29
0
/* Authorize digest credentials */
int authorize(struct sip_msg* msg, str* realm, int hftype)
{
	auth_result_t ret;
	struct hdr_field* h;
	auth_body_t* cred = NULL;
	str* uri;
	struct sip_uri puri;
	str  domain;

	domain = *realm;

	/* see what is to do after a first look at the message */
	ret = pre_auth(msg, &domain, hftype, &h);
	
	switch(ret) 
	{
		case ERROR:            return 0;
			   
		case AUTHORIZED:       return 1;

		case NO_CREDENTIALS:   cred = NULL;
							   break;

		case DO_AUTHORIZATION: cred = (auth_body_t*)h->parsed;
							   break;
	}

	if (get_uri(msg, &uri) < 0) 
	{
		LOG(L_ERR, M_NAME":authorize(): From/To URI not found\n");
		return -1;
	}
	
	if (parse_uri(uri->s, uri->len, &puri) < 0) 
	{
		LOG(L_ERR, M_NAME":authorize(): Error while parsing From/To URI\n");
		return -1;
	}
//	user.s = (char *)pkg_malloc(puri.user.len);
//	un_escape(&(puri.user), &user);
	
	/* parse the ruri, if not yet */
	if(msg->parsed_uri_ok==0 && parse_sip_msg_uri(msg)<0)
	{
		LOG(L_ERR,M_NAME":authorize(): ERROR while parsing the Request-URI\n");
		return -1;
	}
	
	/* preliminary check */
	if(cred)
	{
		if (puri.host.len != cred->digest.realm.len) 
		{
			DBG(M_NAME":authorize(): Credentials realm and URI host do not "
				"match\n");  
			return -1;
		}
	
		if (strncasecmp(puri.host.s, cred->digest.realm.s, puri.host.len) != 0) 
		{
			DBG(M_NAME":authorize(): Credentials realm and URI host do not "
				"match\n");
			return -1;
		}
	}
	
	if( diameter_authorize(cred?h:NULL, &msg->first_line.u.request.method,
					puri, msg->parsed_uri, msg->id, rb) != 1)
	{
		send_resp(msg, 500, "Internal Server Error", NULL, 0);	
		return -1;
	}
	
	if( srv_response(msg, rb, hftype) != 1 )
		return -1;

	mark_authorized_cred(msg, h);

	return 1;
}
Ejemplo n.º 30
0
void
Local::Presentity::edit_presentity_form_submitted (bool submitted,
						   Ekiga::Form &result)
{
  if (!submitted)
    return;

  const std::string new_name = result.text ("name");
  const std::set<std::string> groups = get_groups ();
  const std::set<std::string> new_groups = result.editable_set ("groups");
  std::string new_uri = result.text ("uri");
  const std::string uri = get_uri ();
  bool preferred = result.boolean ("preferred");
  std::set<xmlNodePtr> nodes_to_remove;

  new_uri = canonize_uri (new_uri);

  for (xmlNodePtr child = node->children ;
       child != NULL ;
       child = child->next) {

    if (child->type == XML_ELEMENT_NODE
        && child->name != NULL) {

      if (xmlStrEqual (BAD_CAST ("name"), child->name)) {

	robust_xmlNodeSetContent (node, &child, "name", new_name);
      }
    }
  }

  if (uri != new_uri) {

    boost::shared_ptr<Ekiga::PresenceCore> pcore = presence_core.lock ();
    if (pcore) {
      pcore->unfetch_presence (uri);
      pcore->fetch_presence (new_uri);
    }
    presence = "unknown";
    xmlSetProp (node, (const xmlChar*)"uri", (const xmlChar*)new_uri.c_str ());
  }

  // the first loop looks at groups we were in : are we still in ?
  for (xmlNodePtr child = node->children ;
       child != NULL ;
       child = child->next) {

    if (child->type == XML_ELEMENT_NODE
        && child->name != NULL) {

      if (xmlStrEqual (BAD_CAST ("group"), child->name)) {

	xmlChar* xml_str = xmlNodeGetContent (child);

	if (xml_str != NULL) {

	  if (new_groups.find ((const char*) xml_str) == new_groups.end ()) {

	    nodes_to_remove.insert (child); // don't free what we loop on!
	  }
	  xmlFree (xml_str);
	}
      }
    }
  }

  // ok, now we can clean up!
  for (std::set<xmlNodePtr>::iterator iter = nodes_to_remove.begin ();
       iter != nodes_to_remove.end ();
       ++iter) {

    xmlUnlinkNode (*iter);
    xmlFreeNode (*iter);
  }

  // the second loop looking for groups we weren't in but are now
  for (std::set<std::string>::const_iterator iter = new_groups.begin ();
       iter != new_groups.end ();
       iter++) {

    if (std::find (groups.begin (), groups.end (), *iter) == groups.end ()) {
      xmlNewChild (node, NULL,
		   BAD_CAST "group",
		   BAD_CAST robust_xmlEscape (node->doc, *iter).c_str ());
    }
  }

  if (preferred) {

    xmlSetProp (node, BAD_CAST "preferred", BAD_CAST "true");
  } else {

    xmlSetProp (node, BAD_CAST "preferred", BAD_CAST "false");
  }

  updated ();
  trigger_saving ();
}