Beispiel #1
0
static int cddb_query_parse(HTTP_header_t *http_hdr, cddb_data_t *cddb_data)
{
    char album_title[100];
    char *ptr = NULL;
    int ret, status;

    ret = sscanf(http_hdr->body, "%d ", &status);
    if (ret != 1) {
        mp_tmsg(MSGT_DEMUX, MSGL_ERR, "parse error");
        return -1;
    }

    switch (status) {
    case 200:
        // Found exact match
        ret = sscanf(http_hdr->body, "%d %99s %08lx %99s", &status,
                     cddb_data->category, &(cddb_data->disc_id), album_title);
        if (ret != 4) {
            mp_tmsg(MSGT_DEMUX, MSGL_ERR, "parse error");
            return -1;
        }
        ptr = strstr(http_hdr->body, album_title);
        if (ptr != NULL) {
            char *ptr2;
            int len;
            ptr2 = strstr(ptr, "\n");
            if (ptr2 == NULL) {
                len = (http_hdr->body_size)-(ptr-(http_hdr->body));
            } else {
                len = ptr2-ptr+1;
            }
            len = FFMIN(sizeof(album_title) - 1, len);
            strncpy(album_title, ptr, len);
            album_title[len]='\0';
        }
        mp_tmsg(MSGT_DEMUX, MSGL_STATUS, "Parse OK, found: %s\n", album_title);
        return cddb_request_titles(cddb_data);
    case 202:
        // No match found
        mp_tmsg(MSGT_DEMUX, MSGL_WARN, "Album not found.\n");
        break;
    case 210:
        // Found exact matches, list follows
        cddb_parse_matches_list(http_hdr, cddb_data);
        return cddb_request_titles(cddb_data);
/*
body=[210 Found exact matches, list follows (until terminating `.')
misc c711930d Santana / Supernatural
rock c711930d Santana / Supernatural
blues c711930d Santana / Supernatural
.]
*/
    case 211:
        // Found inexact matches, list follows
        cddb_parse_matches_list(http_hdr, cddb_data);
        return cddb_request_titles(cddb_data);
    case 500:
        mp_tmsg(MSGT_DEMUX, MSGL_FIXME,
                "Server returns: Command syntax error\n");
        break;
    default:
        mp_tmsg(MSGT_DEMUX, MSGL_FIXME, "unhandled code\n");
    }
    return -1;
}
Beispiel #2
0
int
cddb_query_parse(HTTP_header_t *http_hdr, cddb_data_t *cddb_data) {
	char album_title[100];
	char *ptr = NULL;
	int ret, status;
	
	ret = sscanf( http_hdr->body, "%d ", &status);
	if( ret!=1 ) {
		mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_ParseError);
		return -1;
	}

	switch(status) {
		case 200:
			// Found exact match
			ret = sscanf(http_hdr->body, "%d %99s %08lx %99s", &status, cddb_data->category, &(cddb_data->disc_id), album_title);
			if( ret!=4 ) {
				mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_ParseError);
				return -1;
			}
			ptr = strstr(http_hdr->body, album_title);
			if( ptr!=NULL ) {
				char *ptr2;
				int len;
				ptr2 = strstr(ptr, "\n");
				if( ptr2==NULL ) {
					len = (http_hdr->body_size)-(ptr-(http_hdr->body));
				} else {
					len = ptr2-ptr+1;
				}
				strncpy(album_title, ptr, len);
				album_title[len-2]='\0';
			}
			mp_msg(MSGT_DEMUX, MSGL_STATUS, MSGTR_MPDEMUX_CDDB_ParseOKFoundAlbumTitle, album_title);
			return cddb_request_titles(cddb_data);
		case 202:
			// No match found
			mp_msg(MSGT_DEMUX, MSGL_WARN, MSGTR_MPDEMUX_CDDB_AlbumNotFound);
			break;
		case 210:
			// Found exact matches, list follows
			cddb_parse_matches_list(http_hdr, cddb_data);
			return cddb_request_titles(cddb_data);
/*
body=[210 Found exact matches, list follows (until terminating `.')
misc c711930d Santana / Supernatural
rock c711930d Santana / Supernatural
blues c711930d Santana / Supernatural
.]
*/	
		case 211:
			// Found inexact matches, list follows
			cddb_parse_matches_list(http_hdr, cddb_data);
			return cddb_request_titles(cddb_data);
		case 500:
			mp_msg(MSGT_DEMUX, MSGL_FIXME, MSGTR_MPDEMUX_CDDB_ServerReturnsCommandSyntaxErr);
			break;
		default:
			mp_msg(MSGT_DEMUX, MSGL_FIXME, MSGTR_MPDEMUX_CDDB_UnhandledCode);	
	}
	return -1;
}