int main() { dmap_settings settings = { on_dict_start, on_dict_end, on_int32, on_int64, on_uint32, on_uint64, on_date, on_string, on_data, NULL }; int i; int count = sizeof(tests) / sizeof(test); int failcount = 0; int result; for (i = 0; i < count; i++) { output[0] = '\0'; outpos = 0; prefix[0] = '\0'; result = dmap_parse(&settings, tests[i].msg, tests[i].msglen); if (tests[i].expected != NULL) { if (result != 0) { failcount++; printf("Failed test: %s returned error response\n", tests[i].name); } else if (strcmp(output, tests[i].expected) != 0) { failcount++; printf("Failed test: %s\nExpected:\n%sActual:\n%s\n", tests[i].name, tests[i].expected, output); } } else if (result != -1) { failcount++; printf("Failed test: %s, should have errored\n", tests[i].name); } } printf("%d tests passed", count - failcount); if (failcount > 0) printf(", %d failed", failcount); printf("\n"); return failcount ? 1 : 0; }
void _dacp_client_web_connection_response_received_callback(web_client_connection_p connection, web_request_p request, web_response_p response, void* ctx) { struct dacp_client_t* dc = (struct dacp_client_t*)ctx; if (web_response_get_status(response) == 200 && dc->callbacks.playback_state_changed != NULL) { web_headers_p headers = web_response_get_headers(response); size_t content_length; const char* s_content_type = web_headers_value(headers, "Content-Type"); if (s_content_type != NULL && strcmp(s_content_type, "application/x-dmap-tagged") == 0 && (content_length = web_response_get_content(response, NULL, 0)) > 0) { char data[content_length]; web_response_get_content(response, data, content_length); dmap_p dmap = dmap_create(); dmap_parse(dmap, data, content_length); dmap_p container = dmap_container_for_atom_identifer(dmap, "com.airfloat.nowplayingcontainer"); if (container != NULL) { char now_playing = dmap_char_for_atom_identifer(container, "com.airfloat.nowplayingstatus"); dc->playback_state = now_playing; dc->callbacks.playback_state_changed(dc, dc->playback_state, dc->callbacks.ctx.playback_state_changed); } object_release(dmap); } } }