// aggregate control reply static void rtsp_client_aggregate_pause_onreply(void* rtsp, int r, void* parser) { int code; struct rtsp_client_context_t* ctx; ctx = (struct rtsp_client_context_t*)rtsp; assert(RTSP_PAUSE == ctx->status); assert(0 == ctx->progress); assert(ctx->aggregate); if(0 != r) { ctx->client.onpause(ctx->param, r); return; } code = rtsp_get_status_code(parser); if(459 == code) // 459 Aggregate operation not allowed (p26) { r = rtsp_client_media_pause(ctx); if(0 != r) ctx->client.onpause(ctx->param, -1); } else { ctx->client.onpause(ctx->param, 200==code ? 0 : -1); } }
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; } }
// aggregate control reply static int rtsp_client_aggregate_pause_onreply(struct rtsp_client_t* rtsp, void* parser) { int code; assert(rtsp->aggregate); code = rtsp_get_status_code(parser); if (459 == code) // 459 Aggregate operation not allowed (p26) { rtsp->aggregate = 0; return rtsp_client_media_pause(rtsp); } else if(200 == code) { return rtsp->handler.onpause(rtsp->param); } return -1; }
static void rtsp_client_media_pause_onreply(void* rtsp, int r, void* parser) { int code; struct rtsp_client_context_t* ctx; ctx = (struct rtsp_client_context_t*)rtsp; assert(0 == ctx->aggregate); assert(RTSP_PAUSE == ctx->status); assert(ctx->progress < ctx->media_count); if(0 != r) { ctx->client.onpause(ctx->param, r); return; } code = rtsp_get_status_code(parser); assert(460 != code); // 460 Only aggregate operation allowed (p26) if(200 == code) { if(ctx->media_count == ++ctx->progress) { ctx->client.onpause(ctx->param, 0); } else { r = rtsp_client_media_pause(ctx); if(0 != r) { ctx->client.onpause(ctx->param, r); } } } else { ctx->client.onpause(ctx->param, -1); } }
static int rtsp_client_media_pause_onreply(struct rtsp_client_t* rtsp, void* parser) { int code; assert(0 == rtsp->aggregate); assert(rtsp->progress < rtsp->media_count); code = rtsp_get_status_code(parser); assert(460 != code); // 460 Only aggregate operation allowed (p26) if (200 == code) { if (rtsp->media_count == ++rtsp->progress) { return rtsp->handler.onpause(rtsp->param); } else { return rtsp_client_media_pause(rtsp); } } else { return -1; } }
static int rtsp_get_answers( rtsp_client_t *rtsp ) { char *answer = NULL; unsigned int answer_seq; char **answer_ptr = rtsp->p_private->answers; int code; int ans_count = 0; answer = rtsp_get( rtsp ); if( !answer ) return 0; code = rtsp_get_status_code( rtsp, answer ); free( answer ); rtsp_free_answers( rtsp ); do { /* while we get answer lines */ answer = rtsp_get( rtsp ); if( !answer ) return 0; if( !strncasecmp( answer, "CSeq:", 5 ) ) { sscanf( answer, "%*s %u", &answer_seq ); if( rtsp->p_private->cseq != answer_seq ) { //fprintf( stderr, "warning: Cseq mismatch. got %u, assumed %u", // answer_seq, rtsp->p_private->cseq ); rtsp->p_private->cseq = answer_seq; } } if( !strncasecmp( answer, "Server:", 7 ) ) { char *buf = xmalloc( strlen(answer) ); sscanf( answer, "%*s %s", buf ); free( rtsp->p_private->server ); rtsp->p_private->server = buf; } if( !strncasecmp( answer, "Session:", 8 ) ) { char *buf = xmalloc( strlen(answer) ); sscanf( answer, "%*s %s", buf ); if( rtsp->p_private->session ) { if( strcmp( buf, rtsp->p_private->session ) ) { //fprintf( stderr, // "rtsp: warning: setting NEW session: %s\n", buf ); free( rtsp->p_private->session ); rtsp->p_private->session = strdup( buf ); } } else { //fprintf( stderr, "setting session id to: %s\n", buf ); rtsp->p_private->session = strdup( buf ); } free( buf ); } *answer_ptr = answer; answer_ptr++; } while( (strlen(answer) != 0) && (++ans_count < MAX_FIELDS) ); rtsp->p_private->cseq++; *answer_ptr = NULL; rtsp_schedule_standard( rtsp ); return code; }
static int rtsp_get_answers( rtsp_client_t *rtsp ) { access_t *p_access = (access_t*)rtsp->p_userdata; char *answer = NULL; unsigned int answer_seq; char **answer_ptr = rtsp->p_private->answers; int code; int ans_count = 0; answer = rtsp_get( rtsp ); if( !answer ) return 0; code = rtsp_get_status_code( rtsp, answer ); free( answer ); rtsp_free_answers( rtsp ); do { /* while we get answer lines */ answer = rtsp_get( rtsp ); if( !answer ) return 0; if( !strncasecmp( answer, "CSeq:", 5 ) ) { if (sscanf( answer, "%*s %u", &answer_seq ) == 1) { if( rtsp->p_private->cseq != answer_seq ) { msg_Warn (p_access, "Cseq mismatch, got %u, assumed %u", answer_seq, rtsp->p_private->cseq); rtsp->p_private->cseq = answer_seq; } } else { msg_Warn (p_access, "remote server sent CSeq without payload, ignoring."); } } if( !strncasecmp( answer, "Server:", 7 ) ) { char *buf = xmalloc( strlen(answer) ); if (sscanf( answer, "%*s %s", buf ) == 1) { free( rtsp->p_private->server ); rtsp->p_private->server = buf; } else { msg_Warn(p_access, "remote server sent Server without payload, ignoring."); } } if( !strncasecmp( answer, "Session:", 8 ) ) { char *buf = xmalloc( strlen(answer) ); if (sscanf( answer, "%*s %s", buf ) == 1) { // TODO: ignore attributes "Session: ${session-id};${attribute=value...}" if( rtsp->p_private->session ) { if( strcmp( buf, rtsp->p_private->session ) ) { msg_Warn (p_access, "setting NEW session: %s", buf); free( rtsp->p_private->session ); rtsp->p_private->session = strdup( buf ); } } else { msg_Dbg (p_access, "session id: '%s'", buf); rtsp->p_private->session = strdup( buf ); } } else { msg_Warn(p_access, "remote server sent Session without payload, ignoring."); } free( buf ); } *answer_ptr = answer; answer_ptr++; } while( (strlen(answer) != 0) && (++ans_count < MAX_FIELDS) ); rtsp->p_private->cseq++; if (ans_count != MAX_FIELDS) { *answer_ptr = NULL; } rtsp_schedule_standard( rtsp ); return code; }