rtmp-services: Add format_version to services.json

The entire services file had to be restructured, but this allows us to
be able to change the format of the json file safely (if ever needed).
master
jp9000 2015-08-19 16:19:03 -07:00
parent d3eaeda27c
commit b5f1bbdd4c
4 changed files with 453 additions and 418 deletions

View File

@ -7,6 +7,9 @@ set(rtmp-services_SOURCES
rtmp-custom.c rtmp-custom.c
rtmp-services-main.c) rtmp-services-main.c)
set(rtmp-services_HEADERS
rtmp-format-ver.h)
set(RTMP_SERVICES_URL set(RTMP_SERVICES_URL
"https://obsproject.com/obs2_update/rtmp-services" "https://obsproject.com/obs2_update/rtmp-services"
CACHE STRING "Default services package URL") CACHE STRING "Default services package URL")
@ -20,6 +23,7 @@ set(rtmp-services_config_HEADERS
add_library(rtmp-services MODULE add_library(rtmp-services MODULE
${rtmp-services_SOURCES} ${rtmp-services_SOURCES}
${rtmp-services_HEADERS}
${rtmp-services_config_HEADERS}) ${rtmp-services_config_HEADERS})
target_link_libraries(rtmp-services target_link_libraries(rtmp-services
libobs libobs

View File

@ -1,4 +1,6 @@
[ {
"format_version": 1,
"services": [
{ {
"name": "Twitch", "name": "Twitch",
"common": true, "common": true,
@ -417,3 +419,4 @@
] ]
} }
] ]
}

View File

@ -2,6 +2,8 @@
#include <obs-module.h> #include <obs-module.h>
#include <jansson.h> #include <jansson.h>
#include "rtmp-format-ver.h"
struct rtmp_common { struct rtmp_common {
char *service; char *service;
char *server; char *server;
@ -129,6 +131,8 @@ static json_t *open_json_file(const char *file)
char *file_data = os_quick_read_utf8_file(file); char *file_data = os_quick_read_utf8_file(file);
json_error_t error; json_error_t error;
json_t *root; json_t *root;
json_t *list;
int format_ver;
if (!file_data) if (!file_data)
return NULL; return NULL;
@ -143,7 +147,28 @@ static json_t *open_json_file(const char *file)
return NULL; return NULL;
} }
return root; format_ver = get_int_val(root, "format_version");
if (format_ver != RTMP_SERVICES_FORMAT_VERSION) {
blog(LOG_WARNING, "rtmp-common.c: [open_json_file] "
"Wrong format version (%d), expected %d",
format_ver, RTMP_SERVICES_FORMAT_VERSION);
json_decref(root);
return NULL;
}
list = json_object_get(root, "services");
if (list)
json_incref(list);
json_decref(root);
if (!list) {
blog(LOG_WARNING, "rtmp-common.c: [open_json_file] "
"No services list");
return NULL;
}
return list;
} }
static void build_service_list(obs_property_t *list, json_t *root, static void build_service_list(obs_property_t *list, json_t *root,

View File

@ -0,0 +1,3 @@
#pragma once
#define RTMP_SERVICES_FORMAT_VERSION 1