Skip to content

Commit

Permalink
Save model for content only available on the box.
Browse files Browse the repository at this point in the history
  • Loading branch information
SciLor committed Oct 4, 2023
1 parent 11a12e6 commit 870a53a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 20 deletions.
1 change: 1 addition & 0 deletions include/contentJson.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ typedef struct

error_t load_content_json(const char *content_path, contentJson_t *content_json);
error_t save_content_json(const char *content_path, contentJson_t *content_json);
void content_json_update_model(contentJson_t *content_json, uint32_t audio_id);
void free_content_json(contentJson_t *content_json);
23 changes: 23 additions & 0 deletions src/contentJson.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "cJSON.h"
#include "net_config.h"
#include "server_helpers.h"
#include "toniesJson.h"

char *content_jsonGetString(cJSON *jsonElement, char *name)
{
Expand Down Expand Up @@ -236,6 +237,28 @@ error_t save_content_json(const char *content_path, contentJson_t *content_json)
return error;
}

void content_json_update_model(contentJson_t *content_json, uint32_t audio_id)
{
toniesJson_item_t *toniesJson = tonies_byAudioId(audio_id);
if (content_json->_valid)
{
if (toniesJson != NULL && osStrcmp(content_json->tonie_model, "") == 0)
{
if (osStrcmp(content_json->tonie_model, toniesJson->model) != 0)
{
osFreeMem(content_json->tonie_model);
content_json->tonie_model = strdup(toniesJson->model);
content_json->_updated = true;
}
}
else if (toniesJson == NULL && osStrcmp(content_json->tonie_model, "") != 0)
{
// TODO add to tonies.custom.json + report
TRACE_WARNING("Audio-id %08X unknown but previous content known by model %s.\r\n", audio_id, content_json->tonie_model);
}
}
}

void free_content_json(contentJson_t *content_json)
{
content_json->_valid = false;
Expand Down
21 changes: 1 addition & 20 deletions src/handler.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "handler.h"
#include "server_helpers.h"
#include "toniesJson.h"

req_cbr_t getCloudCbr(HttpConnection *connection, const char_t *uri, const char_t *queryString, cloudapi_t api, cbr_ctx_t *ctx, client_ctx_t *client_ctx)
{
Expand Down Expand Up @@ -275,25 +274,7 @@ tonie_info_t getTonieInfo(const char *contentPath, settings_t *settings)
if (tonieInfo.tafHeader)
{
tonieInfo.valid = true;
toniesJson_item_t *toniesJson = tonies_byAudioId(tonieInfo.tafHeader->audio_id);
if (tonieInfo.contentConfig._valid)
{
if (toniesJson != NULL && osStrcmp(tonieInfo.contentConfig.tonie_model, "") == 0)
{
if (osStrcmp(tonieInfo.contentConfig.tonie_model, toniesJson->model) != 0)
{
osFreeMem(tonieInfo.contentConfig.tonie_model);
tonieInfo.contentConfig.tonie_model = strdup(toniesJson->model);
tonieInfo.contentConfig._updated = true;
}
}
else if (toniesJson == NULL && osStrcmp(tonieInfo.contentConfig.tonie_model, "") != 0)
{
// TODO add to tonies.custom.json + report
TRACE_WARNING("Audio-id %08X unknown but previous content known by model %s.\r\n", tonieInfo.tafHeader->audio_id, tonieInfo.contentConfig.tonie_model);
}
}

content_json_update_model(&tonieInfo.contentConfig, tonieInfo.tafHeader->audio_id);
if (tonieInfo.tafHeader->num_bytes == TONIE_LENGTH_MAX)
{
tonieInfo.stream = true;
Expand Down
4 changes: 4 additions & 0 deletions src/handler_cloud.c
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,10 @@ error_t handleCloudFreshnessCheck(HttpConnection *connection, const char_t *uri,
date_buffer_server,
custom_server ? ", custom" : "");
}
else
{
content_json_update_model(&tonieInfo.contentConfig, freshReq->tonie_infos[i]->audio_id);
}

TRACE_INFO_RESUME("\r\n");

Expand Down

0 comments on commit 870a53a

Please sign in to comment.