static int htsp_login(htsp_connection_t *hc) { const void *ch; size_t chlen; htsmsg_t *m; m = htsmsg_create_map(); htsmsg_add_str(m, "clientname", "HTS Showtime"); htsmsg_add_u32(m, "htspversion", 1); htsmsg_add_str(m, "method", "hello"); if((m = htsp_reqreply(hc, m)) == NULL) { return -1; } if(htsmsg_get_bin(m, "challenge", &ch, &chlen) || chlen != 32) { htsmsg_destroy(m); return -1; } memcpy(hc->hc_challenge, ch, 32); htsmsg_destroy(m); m = htsmsg_create_map(); htsmsg_add_str(m, "method", "login"); htsmsg_add_u32(m, "htspversion", HTSP_PROTO_VERSION); if((m = htsp_reqreply(hc, m)) == NULL) { return -1; } htsmsg_destroy(m); return 0; }
static void update_events(htsp_connection_t *hc, prop_t *metadata, int id, int next) { int i; htsmsg_t *m; prop_t *events = prop_create(metadata, "list"); prop_t *current_event = prop_create(metadata, "current"); prop_t *next_event = prop_create(metadata, "next"); int linkstate = 0; htsmsg_field_t *f; if(id == 0) { if(next == 0) { // No events at all prop_destroy_childs(events); return; } id = next; linkstate = 1; } m = htsmsg_create_map(); htsmsg_add_str(m, "method", "getEvents"); htsmsg_add_u32(m, "eventId", id); htsmsg_add_u32(m, "numFollowing", EPG_TAIL); if((m = htsp_reqreply(hc, m)) != NULL) { htsmsg_t *events = htsmsg_get_list(m, "events"); f = events ? TAILQ_FIRST(&events->hm_fields) : NULL; } else { f = NULL; } for(i = 0; i < EPG_TAIL; i++) { char buf[10]; uint32_t u32; snprintf(buf, sizeof(buf), "%d", i); if(f != NULL && f->hmf_type != HMF_MAP) f = NULL; if(f != NULL) { m = htsmsg_get_map_by_field(f); prop_t *e = prop_create(events, buf); prop_set_string(prop_create(e, "title"), htsmsg_get_str(m, "title")); prop_set_string(prop_create(e, "description"), htsmsg_get_str(m, "description")); if(!htsmsg_get_u32(m, "start", &u32)) prop_set_int(prop_create(e, "start"), u32); if(!htsmsg_get_u32(m, "stop", &u32)) prop_set_int(prop_create(e, "stop"), u32); switch(linkstate) { case 0: prop_link(e, current_event); break; case 1: prop_link(e, next_event); break; } linkstate++; f = TAILQ_NEXT(f, hmf_link); continue; } prop_destroy_by_name(events, buf); switch(linkstate) { case 0: prop_unlink(current_event); break; case 1: prop_unlink(next_event); break; } linkstate++; } }
static void update_events(htsp_connection_t *hc, prop_t *metadata, int id, int next) { int i; htsmsg_t *m; prop_t *events = prop_create(metadata, "list"); prop_t *current_event = prop_create(metadata, "current"); prop_t *next_event = prop_create(metadata, "next"); char buf[10]; uint32_t u32; int linkstate = 0; if(id == 0) { if(next == 0) { // No events at all prop_destroy_childs(events); return; } id = next; linkstate = 1; } for(i = 0; i < EPG_TAIL; i++) { snprintf(buf, sizeof(buf), "id%d", i); if(id != 0) { m = htsmsg_create_map(); htsmsg_add_str(m, "method", "getEvent"); htsmsg_add_u32(m, "eventId", id); if((m = htsp_reqreply(hc, m)) != NULL) { prop_t *e = prop_create(events, buf); prop_set_string(prop_create(e, "title"), htsmsg_get_str(m, "title")); prop_set_string(prop_create(e, "description"), htsmsg_get_str(m, "description")); if(!htsmsg_get_u32(m, "start", &u32)) prop_set_int(prop_create(e, "start"), u32); if(!htsmsg_get_u32(m, "stop", &u32)) prop_set_int(prop_create(e, "stop"), u32); switch(linkstate) { case 0: prop_link(e, current_event); break; case 1: prop_link(e, next_event); break; } linkstate++; id = htsmsg_get_u32_or_default(m, "nextEventId", 0); continue; } else { id = 0; } } prop_destroy_by_name(events, buf); switch(linkstate) { case 0: prop_unlink(current_event); break; case 1: prop_unlink(next_event); break; } linkstate++; } }