Ejemplo n.º 1
0
/**
 * Transforms SSML into file_string format and opens file_string.
 * @param handle
 * @param path the inline SSML
 * @return SWITCH_STATUS_SUCCESS if opened
 */
static switch_status_t ssml_file_open(switch_file_handle_t *handle, const char *path)
{
	switch_status_t status = SWITCH_STATUS_FALSE;
	struct ssml_context *context = switch_core_alloc(handle->memory_pool, sizeof(*context));
	struct ssml_parser *parsed_data = switch_core_alloc(handle->memory_pool, sizeof(*parsed_data));
	iksparser *parser = iks_sax_new(parsed_data, tag_hook, cdata_hook);

	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Open: %s\n", path);

	parsed_data->cur_node = NULL;
	parsed_data->files = switch_core_alloc(handle->memory_pool, sizeof(struct ssml_file) * MAX_VOICE_FILES);
	parsed_data->max_files = MAX_VOICE_FILES;
	parsed_data->num_files = 0;
	parsed_data->pool = handle->memory_pool;
	parsed_data->sample_rate = handle->samplerate;

	if (iks_parse(parser, path, 0, 1) == IKS_OK) {
		if (parsed_data->num_files) {
			context->files = parsed_data->files;
			context->num_files = parsed_data->num_files;
			context->index = -1;
			handle->private_info = context;
			status = next_file(handle);
		} else {
			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "No files to play: %s\n", path);
		}
	} else {
		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Parse error: %s, num_files = %i\n", path, parsed_data->num_files);
	}

	iks_parser_delete(parser);

	return status;
}
Ejemplo n.º 2
0
/**
 * Parse the result, looking for noinput/nomatch/match
 * @param result the NLSML result to parse
 * @param uuid optional UUID for logging
 * @return true if successful
 */
enum nlsml_match_type nlsml_parse(const char *result, const char *uuid)
{
	struct nlsml_parser parser = { 0 };
	parser.uuid = uuid;
	if (!zstr(result)) {
		iksparser *p = iks_sax_new(&parser, tag_hook, cdata_hook);
		if (iks_parse(p, result, 0, 1) == IKS_OK) {
			/* check result */
			if (parser.match) {
				return NMT_MATCH;
			}
			if (parser.nomatch) {
				return NMT_NOMATCH;
			}
			if (parser.noinput) {
				return NMT_NOINPUT;
			}
			switch_log_printf(SWITCH_CHANNEL_UUID_LOG(parser.uuid), SWITCH_LOG_INFO, "NLSML result does not have match/noinput/nomatch!\n");
		} else {
			switch_log_printf(SWITCH_CHANNEL_UUID_LOG(parser.uuid), SWITCH_LOG_INFO, "Failed to parse NLSML!\n");
		}
		iks_parser_delete(p);
	} else {
		switch_log_printf(SWITCH_CHANNEL_UUID_LOG(parser.uuid), SWITCH_LOG_INFO, "Missing NLSML result\n");
	}
	return NMT_BAD_XML;
}
Ejemplo n.º 3
0
void
document (char *xml)
{
	enum ikserror err;
	iksparser *p;

	nr_tests++;
	if (my_x) iks_delete (my_x);
	p = iks_dom_new (&my_x);
	err = iks_parse (p, xml, 0, 1);
	switch (err) {
		case IKS_OK:
			break;
		case IKS_NOMEM:
			PR_TEST;
			puts ("Not enough memory.");
			exit (1);
		case IKS_BADXML:
			PR_TEST;
			printf ("Invalid xml at byte %ld in\n[%s]\n", iks_nr_bytes (p), xml);
			exit (1);
		case IKS_HOOK:
			PR_TEST;
			puts ("Hook.");
	}
	iks_parser_delete (p);
}
Ejemplo n.º 4
0
void
serialize_test (char *buf, int len)
{
	unsigned long time;
	iks *x;
	iksparser *prs;
	char *xml;
	int err;

	prs = iks_dom_new (&x);
	err = iks_parse (prs, buf, len, 1);
	switch (err) {
		case IKS_OK:
			break;
		case IKS_NOMEM:
			exit (2);
		case IKS_BADXML:
			fprintf (stderr, "Invalid xml at byte %ld, line %ld\n",
				iks_nr_bytes (prs), iks_nr_lines (prs));
			exit (1);
		case IKS_HOOK:
			exit (1);
	}
	iks_parser_delete (prs);

	t_reset ();

	xml = iks_string (iks_stack (x), x);

	time = t_elapsed ();

	printf ("Serialize: serializing the tree took %ld milliseconds.\n", time);

	iks_delete (x);
}
Ejemplo n.º 5
0
static void test_rayo_test_srgs(void)
{
	iks *grammar = NULL;
	iksparser *p = iks_dom_new(&grammar);
	ASSERT_EQUALS(IKS_OK, iks_parse(p, rayo_test_srgs, 0, 1));
	iks_parser_delete(p);
	iks_delete(grammar);
}
Ejemplo n.º 6
0
static void test_empty_cdata(void)
{
	iks *iq = NULL;
	iks *input = NULL;
	iksparser *p = iks_dom_new(&iq);
	const char *cdata;
	ASSERT_EQUALS(IKS_OK, iks_parse(p, empty_cdata, 0, 1));
	iks_parser_delete(p);
	ASSERT_NOT_NULL((input = iks_find(iq, "input")));
	ASSERT_NULL((cdata = iks_find_cdata(input, "grammar")));
	iks_delete(iq);
}
Ejemplo n.º 7
0
static void test_repeating_bracket(void)
{
	iks *iq = NULL;
	iks *input = NULL;
	iksparser *p = iks_dom_new(&iq);
	const char *cdata;
	ASSERT_EQUALS(IKS_OK, iks_parse(p, repeating_bracket, 0, 1));
	iks_parser_delete(p);
	ASSERT_NOT_NULL((input = iks_find(iq, "input")));
	ASSERT_NOT_NULL((cdata = iks_find_cdata(input, "grammar")));
	ASSERT_STRING_EQUALS("[1 DIGITS]>]]]]]]]]] ]] ", cdata);
	iks_delete(iq);
}
Ejemplo n.º 8
0
static void _StouSvrConnOnData(CFStouSvrConn* conn, uint8_t* buf, size_t len)
{
    CFStouXmppGwConn* gwConn;
    
    LCF_DBG_IN_FUNC();
    gwConn = CFStouSvrConnGetUserData(conn);
    
    if (buf) {
        iks_parse(gwConn->sscParser, (const char*)buf, len, 0);
    } else {
        LCF_ERR("buf == NULL, bug!!\n");
    }
}
Ejemplo n.º 9
0
int iks_recv(iksparser *prs, int timeout)
{
	struct stream_data *data = iks_user_data(prs);
	int len, ret;

	while(1)
	{
		if(data->flags & SF_SECURE_AGAIN)
		{
			len = iks_default_tls.send(data->tlsdata, NULL, 0);

			if(len >= 0)
			{
				data->flags &= (~SF_SECURE_AGAIN);
				data->flags |= SF_SECURE;
				if((len = iks_send_header(data->prs, data->server) != IKS_OK))
				{
					data->flags &= (~SF_SECURE);
					data->flags |= SF_SECURE_AGAIN;
				}
				len = 0;
			}
		}
		else if(data->flags & SF_SECURE)
		{
			len = iks_default_tls.recv(data->tlsdata, data->buf,
			                           NET_IO_BUF_SIZE - 1, timeout);
		}
		else
		{
			len = data->trans->recv(data->sock, data->buf, NET_IO_BUF_SIZE - 1, timeout);
		}
		if(len < 0) return IKS_NET_RWERR;
		if(len == 0) break;
		data->buf[len] = '\0';
		if(data->logHook) data->logHook(data->user_data, data->buf, len, 1);
		ret = iks_parse(prs, data->buf, len, 0);
		if(ret != IKS_OK) return ret;
		if(!data->trans)
		{
			/* stream hook called iks_disconnect */
			return IKS_NET_NOCONN;
		}
		timeout = 0;
	}
	return IKS_OK;
}
Ejemplo n.º 10
0
void dom_test (char *buf, int len)
{
	int bs, i, err;
	iksparser *prs;
	unsigned long time;
	iks *x;
	size_t allocated, used;

	bs = block_size;
	if (0 == bs) bs = len;

	t_reset ();

	prs = iks_dom_new (&x);
	iks_set_size_hint (prs, len);
	i = 0;
	while (i < len) {
		if (i + bs > len) bs = len - i;
		err = iks_parse (prs, buf + i, bs, 0);
		switch (err) {
			case IKS_OK:
				break;
			case IKS_NOMEM:
				exit (2);
			case IKS_BADXML:
				fprintf (stderr, "Invalid xml at byte %ld, line %ld\n",
					iks_nr_bytes (prs), iks_nr_lines (prs));
				exit (1);
			case IKS_HOOK:
				exit (1);
		}
		i += bs;
	}

	time = t_elapsed ();
	iks_stack_stat (iks_stack (x), &allocated, &used);

	printf ("DOM: parsing and building the tree took %ld milliseconds.\n", time);
	printf ("DOM: ikstack: %d bytes allocated, %d bytes used.\n", allocated, used);

	t_reset ();
	iks_delete (x);
	time = t_elapsed ();
	printf ("DOM: deleting the tree took %ld milliseconds.\n", time);

	iks_parser_delete (prs);
}
Ejemplo n.º 11
0
/**
 * Makes NLSML result to conform to mrcpv2
 * @param result the potentially non-conforming result
 * @return the conforming result
 */
iks *nlsml_normalize(const char *result)
{
	iks *result_xml = NULL;
	iksparser *p = iks_dom_new(&result_xml);
	if (iks_parse(p, result, 0, 1) == IKS_OK && result_xml) {
		/* for now, all that is needed is to set the proper namespace */
		iks_insert_attrib(result_xml, "xmlns", NLSML_NS);
	} else {
		/* unexpected ... */
		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Failed to normalize NLSML result: %s\n", result);
		if (result_xml) {
			iks_delete(result_xml);
		}
	}
	iks_parser_delete(p);
	return result_xml;
}
Ejemplo n.º 12
0
iks *
zip_load_xml (zip *z, const char *name, int *err)
{
	iksparser *prs;
	char *real_buf;
	iks *x;
	struct zipfile *zfile;

	*err = ZIP_OK;

	zfile = find_file (z, name);
	if (!zfile) {
		*err = ZIP_NOFILE;
		return NULL;
	}

	seek_file (z, zfile);

	real_buf = malloc (zfile->real_size + 1);
	if (zfile->zip_size < zfile->real_size) {
		char *zip_buf;
		z_stream zs;
		zs.zalloc = NULL;
		zs.zfree = NULL;
		zs.opaque = NULL;
		zip_buf = malloc (zfile->zip_size);
		fread (zip_buf, zfile->zip_size, 1, z->f);
		zs.next_in = zip_buf;
		zs.avail_in = zfile->zip_size;
		zs.next_out = real_buf;
		zs.avail_out = zfile->real_size;
		inflateInit2 (&zs, -MAX_WBITS);
		inflate (&zs, Z_FINISH);
		inflateEnd (&zs);
		free (zip_buf);
	} else {
		fread (real_buf, zfile->real_size, 1, z->f);
	}

	real_buf[zfile->real_size] = '\0';
	prs = iks_dom_new (&x);
	iks_parse (prs, real_buf, zfile->real_size, 1);
	iks_parser_delete (prs);
	free (real_buf);
	return x;
}
Ejemplo n.º 13
0
static int handle_recv (ikss_Stream *self, int len)
{
  if (len < 0) return IKS_NET_RWERR;
  if (len == 0) return IKS_OK; // a non-receive like this is not strictly illegal
  self->recv_buf[len] = '\0';
#if !defined(__SYMBIAN32__)
  printf("RECV '%s'\n", self->recv_buf); // useful for debugging
#endif /* __SYMBIAN32__ */
  int ret = iks_parse (self->prs, self->recv_buf, len, 0);
  if (ret != IKS_OK) return ret;
  if (!self->sock) {
    /* stream hook called iks_disconnect */
    return IKS_NET_NOCONN;
  }

  return IKS_OK;
}
Ejemplo n.º 14
0
/**
 * Send rayo complete
 */
void rayo_component_send_complete_with_metadata_string(struct rayo_component *component, const char *reason, const char *reason_namespace, const char *meta, int child_of_complete)
{
	iks *meta_xml = NULL;
	iksparser *p = iks_dom_new(&meta_xml);
	if (iks_parse(p, meta, 0, 1) != IKS_OK) {
		/* unexpected ... */
		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "%s Failed to parse metadata for complete event: %s\n",
			RAYO_JID(component), meta);
		/* send without... */
		rayo_component_send_complete(component, reason, reason_namespace);
	} else {
		rayo_component_send_complete_with_metadata(component, reason, reason_namespace, meta_xml, child_of_complete);
	}
	if (meta_xml) {
		iks_delete(meta_xml);
	}
	iks_parser_delete(p);
}
Ejemplo n.º 15
0
void
sax_test (char *buf, int len)
{
	unsigned long time;
	iksparser *prs;
	int bs, i, err;

	bs = block_size;
	if (0 == bs) bs = len;
	sax_tag = 0;
	sax_cdata = 0;

	t_reset ();

	prs = iks_sax_new (NULL, tagHook, cdataHook);
	i = 0;
	while (i < len) {
		if (i + bs > len) bs = len - i;
		err = iks_parse (prs, buf + i, bs, 0);
		switch (err) {
			case IKS_OK:
				break;
			case IKS_NOMEM:
				exit (2);
			case IKS_BADXML:
				fprintf (stderr, "Invalid xml at byte %ld, line %ld\n",
					iks_nr_bytes (prs), iks_nr_lines (prs));
				exit (1);
			case IKS_HOOK:
				exit (1);
		}
		i += bs;
	}

	time = t_elapsed ();

	printf ("SAX: parsing took %ld milliseconds.\n", time);
	printf ("SAX: tag hook called %d, cdata hook called %d times.\n", sax_tag, sax_cdata);

	iks_parser_delete (prs);
}
Ejemplo n.º 16
0
int
iks_recv (iksparser *prs, int timeout)
{
	struct stream_data *data = iks_user_data (prs);
	int len, ret;
	
#ifdef HAVE_SSL
	int   err;
#endif

	while (1) {
#ifdef HAVE_GNUTLS
		if (data->flags & SF_SECURE) {
			len = gnutls_record_recv (data->sess, data->buf, NET_IO_BUF_SIZE - 1);
			if (len == 0) len = -1;
		} else
#elif HAVE_SSL
		if (data->flags & SF_SECURE) {
			ret = sock_read_ready(data, timeout*1000);

			if (ret == -1) {
				return IKS_NET_TLSFAIL;
			} else if( ret == 0 ) {
				return IKS_OK;
			} else {
				len = SSL_read(data->ssl, data->buf, NET_IO_BUF_SIZE - 1);
			}
			
			if( len <= 0 ) 
			{
				switch( err = SSL_get_error(data->ssl, len) ) 
				{
					case SSL_ERROR_WANT_READ:
					case SSL_ERROR_WANT_WRITE:
						return IKS_OK;
						break;
					default:
						if(data->logHook)
							data->logHook(data->user_data, ERR_error_string(err, NULL), strlen(ERR_error_string(err, NULL)), 1); 
						return IKS_NET_TLSFAIL;
						break;
				}
			}
		} else
#endif
		{
			len = data->trans->recv (data->sock, data->buf, NET_IO_BUF_SIZE - 1, timeout);
		}
		if (len < 0) return IKS_NET_RWERR;
		if (len == 0) break;
		data->buf[len] = '\0';
		if (data->logHook) data->logHook (data->user_data, data->buf, len, 1);
		ret = iks_parse (prs, data->buf, len, 0);

		if (ret != IKS_OK) return ret;
		if (!data->trans) {
			/* stream hook called iks_disconnect */
			return IKS_NET_NOCONN;
		}
		timeout = 0;
	}
	return IKS_OK;
}