예제 #1
0
int rtsp_client_setup_onreply(struct rtsp_client_t* rtsp, void* parser)
{
	int code;
	const char *session;
	const char *transport;

	assert(RTSP_SETUP == rtsp->state);
	assert(rtsp->progress < rtsp->media_count);

	code = rtsp_get_status_code(parser);
	if (200 == code)
	{
		session = rtsp_get_header_by_name(parser, "Session");
		transport = rtsp_get_header_by_name(parser, "Transport");
		if (!session || 0 != rtsp_header_session(session, &rtsp->media[rtsp->progress].session)
			|| !transport || 0 != rtsp_header_transport(transport, &rtsp->media[rtsp->progress].transport))
		{
			printf("Get rtsp transport error.\n");
			return -EINVAL;
		}

		assert(strlen(session) < sizeof(rtsp->media[0].session.session));
		assert(!rtsp->aggregate || 0 == strcmp(rtsp->media[0].session.session, rtsp->media[rtsp->progress].session.session));

		if (rtsp->media_count == ++rtsp->progress)
		{
			return rtsp->handler.onsetup(rtsp->param);
		}
		else
		{
			// setup next media
			return rtsp_client_media_setup(rtsp);
		}
	}
	else if (401 == code)
	{
		// Unauthorized
		const char* authenticate;
		authenticate = rtsp_get_header_by_name(parser, "WWW-Authenticate");
		if (authenticate)
		{
			rtsp_client_www_authenticate(rtsp, authenticate);
		}
		return -EACCES; // try again
	}
	else
	{
		return -1;
	}
}
예제 #2
0
static int rtsp_header_transport_ex(const char* value, struct rtsp_header_transport_t *transport, size_t *num)
{
	size_t i;
	const char* p = value;

	for(i = 0; i < *num && p; i++)
	{
		if(0 != rtsp_header_transport(p, &transport[i]))
			return -1;

		p = strchr(p+1, ',');
	}

	*num = i;
	return 0;
}