コード例 #1
0
ファイル: message.c プロジェクト: AmesianX/baresip
/**
 * Send SIP instant MESSAGE to a peer
 *
 * @param ua    User-Agent object
 * @param peer  Peer SIP Address
 * @param msg   Message to send
 *
 * @return 0 if success, otherwise errorcode
 */
int message_send(struct ua *ua, const char *peer, const char *msg)
{
	struct sip_addr addr;
	struct pl pl;
	char *uri = NULL;
	int err = 0;

	if (!ua || !peer || !msg)
		return EINVAL;

	pl_set_str(&pl, peer);

	err = sip_addr_decode(&addr, &pl);
	if (err)
		return err;

	err = pl_strdup(&uri, &addr.auri);
	if (err)
		return err;

	err = sip_req_send(ua, "MESSAGE", uri, resp_handler, ua,
			   "Accept: text/plain\r\n"
			   "Content-Type: text/plain\r\n"
			   "Content-Length: %zu\r\n"
			   "\r\n%s",
			   str_len(msg), msg);

	mem_deref(uri);

	return err;
}
コード例 #2
0
ファイル: ua.c プロジェクト: pasichnichenko/baresip
/**
 * Send SIP OPTIONS message to a peer
 *
 * @param ua      User-Agent object
 * @param uri     Peer SIP Address
 * @param resph   Response handler
 * @param arg     Handler argument
 *
 * @return 0 if success, otherwise errorcode
 */
int ua_options_send(struct ua *ua, const char *uri,
		    options_resp_h *resph, void *arg)
{
	struct mbuf *dialbuf;
	int err = 0;

	(void)arg;

	if (!ua || !str_isset(uri))
		return EINVAL;

	dialbuf = mbuf_alloc(64);
	if (!dialbuf)
		return ENOMEM;

	err |= uri_complete(ua, dialbuf, uri);

	dialbuf->buf[dialbuf->end] = '\0';

	err = sip_req_send(ua, "OPTIONS", (char *)dialbuf->buf, resph, NULL,
			   "Accept: application/sdp\r\n"
			   "Content-Length: 0\r\n"
			   "\r\n");
	if (err) {
		warning("ua: send options: (%m)\n", err);
	}

	mem_deref(dialbuf);

	return err;
}
コード例 #3
0
ファイル: publisher.c プロジェクト: GGGO/baresip
static int publish(struct publisher *pub)
{
	int err;
	const char *aor = ua_aor(pub->ua);
	struct mbuf *mb;

	mb = mbuf_alloc(1024);
	if (!mb)
		return ENOMEM;

	if (pub->expires && !pub->refresh)
		err = mbuf_printf(mb,
	"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\r\n"
	"<presence xmlns=\"urn:ietf:params:xml:ns:pidf\"\r\n"
	"    xmlns:dm=\"urn:ietf:params:xml:ns:pidf:data-model\"\r\n"
	"    xmlns:rpid=\"urn:ietf:params:xml:ns:pidf:rpid\"\r\n"
	"    entity=\"%s\">\r\n"
	"  <dm:person id=\"p4159\"><rpid:activities/></dm:person>\r\n"
	"  <tuple id=\"t4109\">\r\n"
	"    <status>\r\n"
	"      <basic>%s</basic>\r\n"
	"    </status>\r\n"
	"    <contact>%s</contact>\r\n"
	"  </tuple>\r\n"
	"</presence>\r\n"
		  ,aor,
		  presence_status_str(ua_presence_status(pub->ua)), aor);
	else
		err = mbuf_printf(mb, "");
	if (err)
		goto out;

	mb->pos = 0;

	/* XXX: can be simplified with 1 function call, by adding a
	   print-handler that prints "SIP-If-Match: ETAG" */
	if (pub->etag)
		err = sip_req_send(pub->ua, "PUBLISH", aor,
				   pub->expires ? response_handler : NULL,
				   pub,
			   "%s"
			   "Event: presence\r\n"
			   "Expires: %u\r\n"
			   "SIP-If-Match: %s\r\n"
			   "Content-Length: %zu\r\n"
			   "\r\n"
			   "%b",
			   pub->expires
				   ? "Content-Type: application/pidf+xml\r\n"
				   : "",

			   pub->expires,
			   pub->etag,
			   mbuf_get_left(mb),
			   mbuf_buf(mb),
			   mbuf_get_left(mb));
	else
		err = sip_req_send(pub->ua, "PUBLISH", aor,
				   pub->expires ? response_handler : NULL,
				   pub,
			   "%s"
			   "Event: presence\r\n"
			   "Expires: %u\r\n"
			   "Content-Length: %zu\r\n"
			   "\r\n"
			   "%b",
			   pub->expires
				   ? "Content-Type: application/pidf+xml\r\n"
				   : "",
			   pub->expires,
			   mbuf_get_left(mb),
			   mbuf_buf(mb),
			   mbuf_get_left(mb));
	if (err) {
		warning("publisher: send PUBLISH: (%m)\n", err);
	}

out:
	mem_deref(mb);

	return err;
}