static int asf_http_parse_response(asf_http_streaming_ctrl_t *asf_http_ctrl, HTTP_header_t *http_hdr ) { char *content_type, *pragma; char features[64] = "\0"; size_t len; if( http_response_parse(http_hdr)<0 ) { mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_ASF_Failed2ParseHTTPResponse); return -1; } switch( http_hdr->status_code ) { case 200: break; case 401: // Authentication required return ASF_Authenticate_e; default: mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_ASF_ServerReturn, http_hdr->status_code, http_hdr->reason_phrase); return -1; } content_type = http_get_field( http_hdr, "Content-Type"); //printf("Content-Type: [%s]\n", content_type); pragma = http_get_field( http_hdr, "Pragma"); while( pragma!=NULL ) { char *comma_ptr=NULL; char *end; //printf("Pragma: [%s]\n", pragma ); // The pragma line can get severals attributes // separeted with a comma ','. do { if( !strncasecmp( pragma, "features=", 9) ) { pragma += 9; end = strstr( pragma, "," ); if( end==NULL ) { len = strlen(pragma); } else { len = (unsigned int)(end-pragma); } if(len > sizeof(features) - 1) { mp_msg(MSGT_NETWORK,MSGL_WARN,MSGTR_MPDEMUX_ASF_ASFHTTPParseWarnCuttedPragma,pragma,len,sizeof(features) - 1); len = sizeof(features) - 1; } strncpy( features, pragma, len ); features[len]='\0'; break; } comma_ptr = strstr( pragma, "," ); if( comma_ptr!=NULL ) { pragma = comma_ptr+1; if( pragma[0]==' ' ) pragma++; } } while( comma_ptr!=NULL ); pragma = http_get_next_field( http_hdr ); } asf_http_ctrl->streaming_type = asf_http_streaming_type( content_type, features, http_hdr ); return 0; }
char * http_get_field( HTTP_header_t *http_hdr, const char *field_name ) { if( http_hdr==NULL || field_name==NULL ) return NULL; http_hdr->field_search_pos = http_hdr->first_field; http_hdr->field_search = realloc( http_hdr->field_search, strlen(field_name)+1 ); if( http_hdr->field_search==NULL ) { mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed\n"); return NULL; } strcpy( http_hdr->field_search, field_name ); return http_get_next_field( http_hdr ); }