Exemplo n.º 1
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;
}
Exemplo n.º 2
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;
}