示例#1
0
/**
 * Construct an NLSML result for digit match
 * @param digits the matching digits
 * @return the NLSML <result>
 */
iks *nlsml_create_dtmf_match(const char *digits)
{
	iks *result = iks_new("result");
	iks_insert_attrib(result, "xmlns", NLSML_NS);
	iks_insert_attrib(result, "xmlns:xf", "http://www.w3.org/2000/xforms");
	if (!zstr(digits)) {
		int first = 1;
		int i;
		int num_digits = strlen(digits);
		switch_stream_handle_t stream = { 0 };

		iks *interpretation = iks_insert(result, "interpretation");
		iks *input = iks_insert(interpretation, "input");
		input = iks_insert(input, "input");
		iks_insert_attrib(input, "mode", "dtmf");
		iks_insert_attrib(input, "confidence", "100");

		SWITCH_STANDARD_STREAM(stream);
		for (i = 0; i < num_digits; i++) {
			if (isdigit(digits[i])) {
				if (first) {
					stream.write_function(&stream, "%c", digits[i]);
					first = 0;
				} else {
					stream.write_function(&stream, " %c", digits[i]);
				}
			}
		}
		iks_insert_cdata(input, stream.data, strlen(stream.data));
		switch_safe_free(stream.data);
	}
	return result;
}
示例#2
0
iks *
iks_make_auth (iksid *id, const char *pass, const char *sid)
{
	iks *x, *y;

	x = iks_new ("iq");
	iks_insert_attrib (x, "type", "set");
	y = iks_insert (x, "query");
	iks_insert_attrib (y, "xmlns", IKS_NS_AUTH);
	iks_insert_cdata (iks_insert (y, "username"), id->user, 0);
	iks_insert_cdata (iks_insert (y, "resource"), id->resource, 0);
	if(sid) {
		char buf[41];
		iksha *sha;
		sha = iks_sha_new ();
		iks_sha_hash (sha, sid, strlen (sid), 0);
		iks_sha_hash (sha, pass, strlen (pass), 1);
		iks_sha_print (sha, buf);
		iks_sha_delete (sha);
		iks_insert_cdata (iks_insert (y, "digest"), buf, 40);
	} else {
		iks_insert_cdata (iks_insert (y, "password"), pass, 0);
	}
	return x;
}
示例#3
0
iks *
iks_make_resource_bind (iksid *id)
{
	iks *x, *y, *z;

	x = iks_new("iq");
	iks_insert_attrib(x, "type", "set");
	y = iks_insert(x, "bind");
	iks_insert_attrib(y, "xmlns", IKS_NS_XMPP_BIND);
	if (id->resource && iks_strcmp(id->resource, "")) {
		z = iks_insert(y, "resource");
		iks_insert_cdata(z, id->resource, 0);
	}
	return x;
}
示例#4
0
文件: data.c 项目: Tayyib/uludag
char *
db_dump_profile(void)
{
	struct databases db;
	struct pack *p;
	DBC *cursor = NULL;
	DBT pair[2];
	int e;
	iks *xml = NULL, *item, *x;
	char *ret = NULL;

	memset(&pair[0], 0, sizeof(DBT) * 2);
	pair[1].flags = DB_DBT_MALLOC;

	if (open_env(&db, PROFILE_DB)) goto out;

	db.profile->cursor(db.profile, NULL, &cursor, 0);

	xml = iks_new("comarProfile");
	iks_insert_cdata(xml, "\n", 1);
	while ((e = cursor->c_get(cursor, &pair[0], &pair[1], DB_NEXT)) == 0) {
		char *t;
		size_t ts;
		item = iks_insert(xml, "item");
		iks_insert_cdata(iks_insert(item, "key"), pair[0].data, pair[0].size);
		p = pack_wrap(pair[1].data, pair[1].size);
		while (pack_get(p, &t, &ts)) {
			iks_insert_cdata(item, "\n", 1);
			x = iks_insert(item, "data");
			iks_insert_attrib(x, "key", t);
			pack_get(p, &t, &ts);
			iks_insert_cdata(iks_insert(x, "value"), t, ts);
		}
		pack_delete(p);
		iks_insert_cdata(xml, "\n", 1);
	}
	if (e != DB_NOTFOUND) {
		goto out;
	}

	ret = iks_string(NULL, xml);
out:
	if (cursor) cursor->c_close(cursor);
	close_env(&db);
	if (xml) iks_delete(xml);
	return ret;
}
示例#5
0
/**
 * Send component start reply
 * @param component the component
 * @param iq the start request
 */
void rayo_component_send_start(struct rayo_component *component, iks *iq)
{
	iks *response = iks_new_iq_result(iq);
	iks *ref = iks_insert(response, "ref");
	iks_insert_attrib(ref, "xmlns", RAYO_NS);
	iks_insert_attrib_printf(ref, "uri", "xmpp:%s", RAYO_JID(component));
	RAYO_SEND_REPLY(component, iks_find_attrib(response, "to"), response);
}
示例#6
0
/**
 * Send input-timers-started event
 */
void rayo_component_send_input_timers_started_event(struct rayo_component *component)
{
	iks *event = iks_new("presence");
	iks *x;
	iks_insert_attrib(event, "from", RAYO_JID(component));
	iks_insert_attrib(event, "to", component->client_jid);
	x = iks_insert(event, "input-timers-started");
	iks_insert_attrib(x, "xmlns", RAYO_PROMPT_NS);
	RAYO_SEND_REPLY(component, component->client_jid, event);
}
示例#7
0
iks *
iks_make_session (void)
{
	iks *x, *y;

	x = iks_new ("iq");
	iks_insert_attrib (x, "type", "set");
	y = iks_insert (x, "session");
	iks_insert_attrib (y, "xmlns", IKS_NS_XMPP_SESSION);
	return x;
}
/**
 * Start input component timers
 */
static void start_input_timers(struct prompt_component *prompt)
{
	iks *x;
	iks *iq = iks_new("iq");
	iks_insert_attrib(iq, "from", RAYO_JID(prompt));
	iks_insert_attrib(iq, "to", prompt->input_jid);
	iks_insert_attrib(iq, "type", "set");
	iks_insert_attrib_printf(iq, "id", "mod_rayo-prompt-%d", RAYO_SEQ_NEXT(prompt));
	x = iks_insert(iq, "start-timers");
	iks_insert_attrib(x, "xmlns", RAYO_INPUT_NS);
	RAYO_SEND_MESSAGE(prompt, prompt->input_jid, iq);
}
/**
 * Send stop to component
 */
static void rayo_component_send_stop(struct rayo_actor *from, const char *to)
{
	iks *stop = iks_new("iq");
	iks *x;
	iks_insert_attrib(stop, "from", RAYO_JID(from));
	iks_insert_attrib(stop, "to", to);
	iks_insert_attrib(stop, "type", "set");
	iks_insert_attrib_printf(stop, "id", "mod_rayo-prompt-%d", RAYO_SEQ_NEXT(from));
	x = iks_insert(stop, "stop");
	iks_insert_attrib(x, "xmlns", RAYO_EXT_NS);
	RAYO_SEND_MESSAGE(from, to, stop);
}
示例#10
0
文件: packet.c 项目: hustwcw/packet
// 服务器端组装发给客户端的协商包
char* pkg_talk_rtn(const packet_parser_t *pkg)
{
	char *r;
	unsigned char *encrypted_key;// 使用公钥加密过的临时密钥
	char *output;
	iks *x, *tmp;
	int dest_len;

	x = iks_new ("connection");
	if(NULL == x) return NULL;

	iks_insert_attrib(x, "xmlns", TALK_XMLNS);
	iks_insert_attrib(x, "type", "result");
	tmp = iks_insert(x, "encryption");
	iks_insert_attrib(tmp, "type", pkg->curr_ert.transfer_ert_type);
	// 使用公钥对临时密钥进行加密
	if (pkg->asym_encrypt_hook == NULL)
	{
		encrypted_key = rsa_encrypt((unsigned char *)get_transfer_crt_key(pkg), strlen(get_transfer_crt_key(pkg)), &dest_len, (char *)(pkg->curr_ert.ert_keys[0]), CRYPT_TYPE_ENCRYPT);
	}
	else
	{
		encrypted_key = pkg->asym_encrypt_hook((unsigned char *)get_transfer_crt_key(pkg), strlen(get_transfer_crt_key(pkg)), &dest_len, (char *)(pkg->curr_ert.ert_keys[0]), CRYPT_TYPE_ENCRYPT);
	}
	output = (char *)calloc(dest_len*2+1, 1);
	byte2hex(encrypted_key, dest_len, output);
	iks_insert_cdata(tmp, output, 0);
	free(output);
	free(encrypted_key);

	iks_insert_cdata(iks_insert(x, "compression"), pkg->cps_type, 0);
	tmp = iks_insert(x, "heartbeat");
	// TODO:在初始化服务器端包解析器的时候应该设置心跳参数
	iks_insert_attrib(tmp, "sponsor", "server");
	iks_insert_attrib(tmp, "seconds", "60");

	r = iks_string(NULL, x);
	iks_delete(x);
	return r;
}
示例#11
0
iks *
iks_make_pres (enum ikshowtype show, const char *status)
{
	iks *x;
	char *t;

	x = iks_new ("presence");
	switch (show) {
		case IKS_SHOW_CHAT: t = "chat"; break;
		case IKS_SHOW_AWAY: t = "away"; break;
		case IKS_SHOW_XA: t = "xa"; break;
		case IKS_SHOW_DND: t = "dnd"; break;
		case IKS_SHOW_UNAVAILABLE:
			t = NULL;
			iks_insert_attrib (x, "type", "unavailable");
			break;
		default: t = NULL; break;
	}
	if (t) iks_insert_cdata (iks_insert (x, "show"), t, 0);
	if (status) iks_insert_cdata(iks_insert (x, "status"), status, 0);
	return x;
}
示例#12
0
/**
 * Add fax metadata to result
 * @param event source of metadata
 * @param name of metadata
 * @param result to add metadata to
 */
static void insert_fax_metadata(switch_event_t *event, const char *name, iks *result)
{
	char actual_name[256];
	const char *value;
	snprintf(actual_name, sizeof(actual_name), "variable_%s", name);
	actual_name[sizeof(actual_name) - 1] = '\0';
	value = switch_event_get_header(event, actual_name);
	if (!zstr(value)) {
		iks *metadata = iks_insert(result, "metadata");
		iks_insert_attrib(metadata, "xmlns", RAYO_FAX_COMPLETE_NS);
		iks_insert_attrib(metadata, "name", name);
		iks_insert_attrib(metadata, "value", value);
	}
}
示例#13
0
/**
 * Create component complete event
 * @param component the component
 * @param reason_str the completion reason
 * @param reason_namespace the completion reason namespace
 * @param meta metadata to add as child
 * @param child_of_complete if true metadata is child of complete instead of reason
 * @return the event
 */
iks *rayo_component_create_complete_event_with_metadata(struct rayo_component *component, const char *reason_str, const char *reason_namespace, iks *meta, int child_of_complete)
{
	iks *response = iks_new("presence");
	iks *complete;
	iks *reason;
	iks_insert_attrib(response, "from", RAYO_JID(component));
	iks_insert_attrib(response, "to", component->client_jid);
	iks_insert_attrib(response, "type", "unavailable");
	complete = iks_insert(response, "complete");
	iks_insert_attrib(complete, "xmlns", RAYO_EXT_NS);
	reason = iks_insert(complete, reason_str);
	iks_insert_attrib(reason, "xmlns", reason_namespace);
	if (meta) {
		meta = iks_copy_within(meta, iks_stack(response));
		if (child_of_complete) {
			iks_insert_node(complete, meta);
		} else {
			iks_insert_node(reason, meta);
		}
	}

	return response;
}
示例#14
0
void
prefs_setup (void)
{
	iks *x;

	memset (&prefs, 0, sizeof (struct prefs_struct));

	prefs_chdir (".ulubot");

	if (iks_load ("ayarlar.xml", &x) == IKS_OK) {
		if (iks_strcmp (iks_name (x), "ulubot") == 0) {
			prefs.jid = iks_strdup (iks_find_cdata (x, "id"));
			prefs.pass = iks_strdup (iks_find_cdata (x, "password"));
			prefs.admin_jid = iks_strdup (iks_find_cdata (x, "admin_id"));
			iks_delete (x);
			if (prefs.jid && prefs.pass && prefs.admin_jid) return;
		}
	}

	puts (PACKAGE" v"VERSION" sözlük sunucusuna hoşgeldiniz!");
	puts ("Hemen bir kaç ayar yapalım:");

	prefs.jid = iks_strdup (input ("Botun Jabber hesabı"));
	prefs.pass = iks_strdup (input ("Botun Jabber şifresi"));
	prefs.admin_jid = iks_strdup (input ("Yöneticinin Jabber hesabı"));

	x = iks_new ("ulubot");
	iks_insert_cdata (iks_insert (x, "id"), prefs.jid, 0);
	iks_insert_cdata (iks_insert (x, "password"), prefs.pass, 0);
	iks_insert_cdata (iks_insert (x, "admin_id"), prefs.admin_jid, 0);
	if (iks_save ("ayarlar.xml", x) != IKS_OK) {
		puts ("Hata: ayarları kaydedemedim!");
	}
	iks_delete (x);

	puts ("Ayarlar tamam.");
}
示例#15
0
文件: packet.c 项目: hustwcw/packet
/// 客户端组装发给服务器端的协商包。
char* pkg_talk_make(const packet_parser_t *pkg)
{
	char *r;
	iks *x, *tmp;
	x = iks_new ("connection");
	if(NULL == x) return NULL;

	iks_insert_attrib(x, "xmlns", TALK_XMLNS);
	iks_insert_attrib(x, "type", "create");
	tmp = iks_insert(x, "client-id");
	if(NULL != tmp) {
		iks_insert_cdata(tmp, pkg->client_cert.client_id, 0);
	}
	
	tmp = iks_insert(x, "public-key");
	if(NULL != tmp) {
		iks_insert_cdata(tmp, pkg->curr_ert.ert_keys[0], 0);
		iks_insert_attrib(tmp, "type", pkg->curr_ert.talk_ert_type);
	}

	if(0 != strlen(pkg->curr_ert.talk_ert_type)){
		tmp = iks_insert(x, "encryption");
		iks_insert_cdata(iks_insert(tmp,"allow"), pkg->curr_ert.transfer_ert_type, 0);
	}
	
	if(0 != strlen(pkg->cps_type)){
		tmp = iks_insert(x, "compression");
		iks_insert_cdata(iks_insert(tmp,"allow"), pkg->cps_type, 0);
	}

	if( pkg->client_cert.signature[0] != 0 ){
		tmp = iks_insert(x, "certificate");
		iks_insert_attrib(tmp, "id", pkg->client_cert.cert_id);
		iks_insert_cdata(iks_insert(tmp, "subject"), pkg->client_cert.subject, 0);
		iks_insert_cdata(iks_insert(tmp, "signature"), pkg->client_cert.signature, 0);
	}

	r = iks_string(NULL, x);
	iks_delete(x);
	return r;
}
示例#16
0
// iksparser calls this when it has a full tag
// 
// Important: Nothing must be done after a self->streamHook invocation
// if the hook returns a non-zero value.
static int
tagHook (ikss_Stream *self, char *name, char **atts, int type)
{
  iks *x;
  int err;

  switch (type) {
  case IKS_OPEN:
  case IKS_SINGLE:
    if (self->current) {
      x = iks_insert (self->current, name);
      insert_attribs (x, atts);
    } else {
      x = iks_new (name);
      insert_attribs (x, atts);
      if (iks_strcmp (name, "stream:stream") == 0) {
	err = self->streamHook (self->user_data, IKS_NODE_START, x);
	if (err != IKS_OK) return err;
	break;
      }
    }
    self->current = x;
    if (IKS_OPEN == type) break;
  case IKS_CLOSE:
    x = self->current;
    if (NULL == x) {
      err = self->streamHook (self->user_data, IKS_NODE_STOP, NULL);
      if (err != IKS_OK) return err;
      break;
    }
    if (NULL == iks_parent (x)) {
      self->current = NULL;
      if (iks_strcmp (name, "challenge") == 0) {
	send_sasl_challenge(self, x);
	iks_delete (x);
      } else if (iks_strcmp (name, "stream:error") == 0) {
	err = self->streamHook (self->user_data, IKS_NODE_ERROR, x);
	if (err != IKS_OK) return err;
      } else {
	err = self->streamHook (self->user_data, IKS_NODE_NORMAL, x);
	if (err != IKS_OK) return err;
      }
      break;
    }
    self->current = iks_parent (x);
  }
  return IKS_OK;
}
示例#17
0
iks *
iks_copy_within (iks *x, ikstack *s)
{
	int level=0, dir=0;
	iks *copy = NULL;
	iks *cur = NULL;
	iks *y;

	while (1) {
		if (dir == 0) {
			if (x->type == IKS_TAG) {
				if (copy == NULL) {
					copy = iks_new_within (IKS_TAG_NAME (x), s);
					cur = copy;
				} else {
					cur = iks_insert (cur, IKS_TAG_NAME (x));
				}
				for (y = IKS_TAG_ATTRIBS (x); y; y = y->next) {
					iks_insert_attrib (cur, IKS_ATTRIB_NAME (y), IKS_ATTRIB_VALUE (y));
				}
				if (IKS_TAG_CHILDREN (x)) {
					x = IKS_TAG_CHILDREN (x);
					level++;
					continue;
				} else {
					cur = cur->parent;
				}
			} else {
				iks_insert_cdata (cur, IKS_CDATA_CDATA (x), IKS_CDATA_LEN (x));
			}
		}
		y = x->next;
		if (y) {
			if (0 == level) break;
			x = y;
			dir = 0;
		} else {
			if (level < 2) break;
			level--;
			x = x->parent;
			cur = cur->parent;
			dir = 1;
		}
	}
	return copy;
}
示例#18
0
iks *
iks_make_msg (enum iksubtype type, const char *to, const char *body)
{
	iks *x;
	char *t = NULL;

	x = iks_new ("message");
	switch (type) {
	case IKS_TYPE_CHAT: t = "chat"; break;
	case IKS_TYPE_GROUPCHAT: t = "groupchat"; break;
	case IKS_TYPE_HEADLINE: t = "headline"; break;
	default: break;
	}
	if (t) iks_insert_attrib (x, "type", t);
	if (to) iks_insert_attrib (x, "to", to);
	if (body) iks_insert_cdata (iks_insert (x, "body"), body, 0);
	return x;
}
示例#19
0
iks *
iks_make_iq (enum iksubtype type, const char *xmlns)
{
	iks *x;
	char *t = NULL;

	x = iks_new ("iq");
	switch (type) {
	case IKS_TYPE_GET: t = "get"; break;
	case IKS_TYPE_SET: t = "set"; break;
	case IKS_TYPE_RESULT: t = "result"; break;
	case IKS_TYPE_ERROR: t = "error"; break;
	default: break;
	}
	if (t) iks_insert_attrib (x, "type", t);
	iks_insert_attrib (iks_insert (x, "query"), "xmlns", xmlns);

	return x;
}
示例#20
0
iks *
iks_make_s10n (enum iksubtype type, const char *to, const char *msg)
{
	iks *x;
	char *t;

	x = iks_new ("presence");
	switch (type) {
		case IKS_TYPE_SUBSCRIBE: t = "subscribe"; break;
		case IKS_TYPE_SUBSCRIBED: t = "subscribed"; break;
		case IKS_TYPE_UNSUBSCRIBE: t = "unsubscribe"; break;
		case IKS_TYPE_UNSUBSCRIBED: t = "unsubscribed"; break;
		case IKS_TYPE_PROBE: t = "probe"; break;
		default: t = NULL; break;
	}
	if (t) iks_insert_attrib (x, "type", t);
	if (to) iks_insert_attrib (x, "to", to);
	if (msg) iks_insert_cdata(iks_insert (x, "status"), msg, 0);
	return x;
}
示例#21
0
iks *
iks_insert_cdata (iks *x, const char *data, size_t len)
{
	iks *y;

	if(!x || !data) return NULL;
	if(len == 0) len = strlen (data);

	y = IKS_TAG_LAST_CHILD (x);
	if (y && y->type == IKS_CDATA) {
		IKS_CDATA_CDATA (y) = iks_stack_strcat (x->s, IKS_CDATA_CDATA (y), IKS_CDATA_LEN (y), data, len);
		IKS_CDATA_LEN (y) += len;
	} else {
		y = iks_insert (x, NULL);
		if (!y) return NULL;
		y->type = IKS_CDATA;
		IKS_CDATA_CDATA (y) = iks_stack_strdup (x->s, data, len);
		if (!IKS_CDATA_CDATA (y)) return NULL;
		IKS_CDATA_LEN (y) = len;
	}
	return y;
}
示例#22
0
static int tagHook(struct stream_data *data, char *name, char **atts, int type)
{
	iks *x;
	int err;

	switch(type)
	{
	case IKS_OPEN:
	case IKS_SINGLE:
		if(data->flags & SF_TRY_SECURE)
		{
			if(strcmp(name, "proceed") == 0)
			{
				err = iks_default_tls.handshake(&data->tlsdata,
				                                data->trans, data->sock);
				if(err == IKS_OK)
				{
					data->flags &= (~SF_TRY_SECURE);
					data->flags |= SF_SECURE;
					iks_send_header(data->prs, data->server);
				}
				if(err == IKS_AGAIN)
				{
					data->flags &= (~SF_TRY_SECURE);
					data->flags |= SF_SECURE_AGAIN;
					err = IKS_OK;
				}
				return err;
			}
			else if(strcmp(name, "failure") == 0)
			{
				return IKS_NET_TLSFAIL;
			}
		}
		if(data->current)
		{
			x = iks_insert(data->current, name);
			insert_attribs(x, atts);
		}
		else
		{
			x = iks_new(name);
			insert_attribs(x, atts);
			if(iks_strcmp(name, "stream:stream") == 0)
			{
				err = data->streamHook(data->user_data, IKS_NODE_START, x);
				if(err != IKS_OK) return err;
				break;
			}
		}
		data->current = x;
		if(IKS_OPEN == type) break;
	case IKS_CLOSE:
		x = data->current;
		if(NULL == x)
		{
			err = data->streamHook(data->user_data, IKS_NODE_STOP, NULL);
			if(err != IKS_OK) return err;
			break;
		}
		if(NULL == iks_parent(x))
		{
			data->current = NULL;
			if(iks_strcmp(name, "challenge") == 0)
			{
				iks_sasl_challenge(data, x);
				iks_delete(x);
			}
			else if(iks_strcmp(name, "stream:error") == 0)
			{
				err = data->streamHook(data->user_data, IKS_NODE_ERROR, x);
				if(err != IKS_OK) return err;
			}
			else
			{
				err = data->streamHook(data->user_data, IKS_NODE_NORMAL, x);
				if(err != IKS_OK) return err;
			}
			break;
		}
		data->current = iks_parent(x);
	}
	return IKS_OK;
}
示例#23
0
static int
tagHook (struct stream_data *data, char *name, char **atts, int type)
{
	iks *x;
	int err;

	switch (type) {
		case IKS_OPEN:
		case IKS_SINGLE:
#ifdef HAVE_GNUTLS
			if (data->flags & SF_TRY_SECURE) {
				if (strcmp (name, "proceed") == 0) {
					err = handshake (data);
					return err;
				} else if (strcmp (name, "failure") == 0){
					return IKS_NET_TLSFAIL;
				}
			}
#elif HAVE_SSL
			if (data->flags & SF_TRY_SECURE) {
				if (strcmp (name, "proceed") == 0) {
					err = handshake (data);
					return err;
				} else if (strcmp (name, "failure") == 0){
					return IKS_NET_TLSFAIL;
				}
			}
#endif
			if (data->current) {
				x = iks_insert (data->current, name);
				insert_attribs (x, atts);
			} else {
				x = iks_new (name);
				insert_attribs (x, atts);
				if (iks_strcmp (name, "stream:stream") == 0) {
					err = data->streamHook (data->user_data, IKS_NODE_START, x);
					if (err != IKS_OK) return err;
					break;
				}
			}
			data->current = x;
			if (IKS_OPEN == type) break;
		case IKS_CLOSE:
			x = data->current;
			if (NULL == x) {
				err = data->streamHook (data->user_data, IKS_NODE_STOP, NULL);
				if (err != IKS_OK) return err;
				break;
			}
			if (NULL == iks_parent (x)) {
				data->current = NULL;
				if (iks_strcmp (name, "challenge") == 0)
					iks_sasl_challenge(data, x);
				else if (iks_strcmp (name, "stream:error") == 0) {
					err = data->streamHook (data->user_data, IKS_NODE_ERROR, x);
					if (err != IKS_OK) return err;
				} else {
					err = data->streamHook (data->user_data, IKS_NODE_NORMAL, x);
					if (err != IKS_OK) return err;
				}
				break;
			}
			data->current = iks_parent (x);
	}
	return IKS_OK;
}
示例#24
0
/**
 * Handle fax completion event from FreeSWITCH core
 * @param event received from FreeSWITCH core.  It will be destroyed by the core after this function returns.
 */
static void on_execute_complete_event(switch_event_t *event)
{
	const char *application = switch_event_get_header(event, "Application");
	
	if (!zstr(application) && (!strcmp(application, "rxfax") || !strcmp(application, "txfax"))) {
		int is_rxfax = !strcmp(application, "rxfax");
		const char *uuid = switch_event_get_header(event, "Unique-ID");
		const char *fax_jid = switch_event_get_header(event, "variable_rayo_fax_jid");
		struct rayo_actor *component;
		if (!zstr(fax_jid) && (component = RAYO_LOCATE(fax_jid))) {
			iks *result;
			iks *complete;
			iks *fax;
			int have_fax_document = 1;
			switch_core_session_t *session;
			switch_log_printf(SWITCH_CHANNEL_UUID_LOG(uuid), SWITCH_LOG_DEBUG, "Got result for %s\n", fax_jid);

			/* clean up channel */
			session = switch_core_session_locate(uuid);
			if (session) {
				switch_channel_set_variable(switch_core_session_get_channel(session), "rayo_read_frame_interrupt", NULL);
				switch_core_session_rwunlock(session);
			}

			/* RX only: transfer HTTP document and delete local copy */
			if (is_rxfax && RECEIVEFAX_COMPONENT(component)->http_put_after_receive && switch_file_exists(RECEIVEFAX_COMPONENT(component)->local_filename, RAYO_POOL(component)) == SWITCH_STATUS_SUCCESS) {
				switch_stream_handle_t stream = { 0 };
				SWITCH_STANDARD_STREAM(stream);
				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s PUT fax to %s\n", RAYO_JID(component), RECEIVEFAX_COMPONENT(component)->filename);
				switch_api_execute("http_put", RECEIVEFAX_COMPONENT(component)->filename, NULL, &stream);
				/* check if successful */
				if (!zstr(stream.data) && strncmp(stream.data, "+OK", 3)) {
					/* PUT failed */
					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s PUT fax to %s failed: %s\n", RAYO_JID(component), RECEIVEFAX_COMPONENT(component)->filename, (char *)stream.data);
					have_fax_document = 0;
				}
				switch_safe_free(stream.data)
				switch_file_remove(RECEIVEFAX_COMPONENT(component)->local_filename, RAYO_POOL(component));
			}

			/* successful fax? */
			if (have_fax_document && switch_true(switch_event_get_header(event, "variable_fax_success"))) {
				result = rayo_component_create_complete_event(RAYO_COMPONENT(component), FAX_FINISH);
			} else if (have_fax_document && FAX_COMPONENT(component)->stop)  {
				result = rayo_component_create_complete_event(RAYO_COMPONENT(component), COMPONENT_COMPLETE_STOP);
			} else {
				result = rayo_component_create_complete_event(RAYO_COMPONENT(component), COMPONENT_COMPLETE_ERROR);
			}
			complete = iks_find(result, "complete");

			/* RX only: add fax document information */
			if (is_rxfax && have_fax_document) {
				const char *pages = switch_event_get_header(event, "variable_fax_document_transferred_pages");
				if (!zstr(pages) && switch_is_number(pages) && atoi(pages) > 0) {
					const char *resolution = switch_event_get_header(event, "variable_fax_file_image_resolution");
					const char *size = switch_event_get_header(event, "variable_fax_image_size");

					fax = iks_insert(complete, "fax");
					iks_insert_attrib(fax, "xmlns", RAYO_FAX_COMPLETE_NS);

					if (RECEIVEFAX_COMPONENT(component)->http_put_after_receive) {
						iks_insert_attrib(fax, "url", RECEIVEFAX_COMPONENT(component)->filename);
					} else {
						/* convert absolute path to file:// URI */
						iks_insert_attrib_printf(fax, "url", "file://%s", RECEIVEFAX_COMPONENT(component)->filename);
					}

					if (!zstr(resolution)) {
						iks_insert_attrib(fax, "resolution", resolution);
					}
					if (!zstr(size)) {
						iks_insert_attrib(fax, "size", size);
					}
					iks_insert_attrib(fax, "pages", pages);
				}
			}

			/* add metadata from event */
			insert_fax_metadata(event, "fax_success", complete);
			insert_fax_metadata(event, "fax_result_code", complete);
			insert_fax_metadata(event, "fax_result_text", complete);
			insert_fax_metadata(event, "fax_document_transferred_pages", complete);
			insert_fax_metadata(event, "fax_document_total_pages", complete);
			insert_fax_metadata(event, "fax_image_resolution", complete);
			insert_fax_metadata(event, "fax_image_size", complete);
			insert_fax_metadata(event, "fax_bad_rows", complete);
			insert_fax_metadata(event, "fax_transfer_rate", complete);
			insert_fax_metadata(event, "fax_ecm_used", complete);
			insert_fax_metadata(event, "fax_local_station_id", complete);
			insert_fax_metadata(event, "fax_remote_station_id", complete);

			/* flag faxing as done */
			rayo_call_set_faxing(RAYO_CALL(RAYO_COMPONENT(component)->parent), 0);

			rayo_component_send_complete_event(RAYO_COMPONENT(component), result);

			RAYO_UNLOCK(component);
		}
	}
}
示例#25
0
/**
 * Create a <presence> event
 * @param name the event name
 * @param namespace the event namespace
 * @param from
 * @param to
 * @return the event XML node
 */
iks *iks_new_presence(const char *name, const char *namespace, const char *from, const char *to)
{
    iks *event = iks_new("presence");
    iks *x;
    /* iks makes copies of attrib name and value */
    iks_insert_attrib(event, "from", from);
    iks_insert_attrib(event, "to", to);
    x = iks_insert(event, name);
    if (!zstr(namespace)) {
        iks_insert_attrib(x, "xmlns", namespace);
    }
    return event;
}

/**
 * Create error response from request
 * @param req the request
 * @param from
 * @param to
 * @param err the XMPP stanza error
 * @return the error response
 */
iks *iks_new_error(iks *req, const struct xmpp_error *err)