summaryrefslogtreecommitdiff
path: root/cleopatre
diff options
context:
space:
mode:
Diffstat (limited to 'cleopatre')
-rw-r--r--cleopatre/devkit/plcd/inc/plcd_ctx.h52
-rw-r--r--cleopatre/devkit/plcd/src/plcd_files.c134
2 files changed, 132 insertions, 54 deletions
diff --git a/cleopatre/devkit/plcd/inc/plcd_ctx.h b/cleopatre/devkit/plcd/inc/plcd_ctx.h
index 364996c3ab..2f7ec078fd 100644
--- a/cleopatre/devkit/plcd/inc/plcd_ctx.h
+++ b/cleopatre/devkit/plcd/inc/plcd_ctx.h
@@ -89,6 +89,38 @@ typedef struct
char tonemask[192];
} plcd_nvram_t;
+typedef struct
+{
+ /* CCo preference */
+ libspid_boolean_t is_cco_preferred;
+ /* CCo status at boot */
+ libspid_boolean_t was_cco;
+ /* NMK value */
+ char nmk_str[LIBSPID_HPAV_CONF_NMK_STR_LEN];
+ /* NID value */
+ char nid_str[LIBSPID_HPAV_CONF_NID_STR_LEN];
+ /* SL value */
+ char sl_str[LIBSPID_HPAV_CONF_SL_STR_MAX_LEN];
+ /* user HFID value */
+ char user_hfid[LIBSPID_HPAV_CONF_HFID_MAX_LEN];
+ /* AVLN HFID value */
+ char avln_hfid[LIBSPID_HPAV_CONF_HFID_MAX_LEN];
+} plcd_hpav_conf_t;
+
+typedef struct
+{
+ /* status value */
+ char status[LIBSPID_HPAV_INFO_STATUS_MAX_LEN];
+ /* CCo value */
+ char cco[LIBSPID_HPAV_INFO_CCO_MAX_LEN];
+ /* backup CCo value */
+ libspid_boolean_t is_backup_cco;
+ /* Simple Connect value */
+ libspid_boolean_t is_sc;
+ /* Simple Connect button value */
+ libspid_boolean_t is_sc_button;
+} plcd_hpav_info_t;
+
/** main context of plc daemon */
typedef struct
{
@@ -115,25 +147,9 @@ typedef struct
/** indicates if other processes have to be informed about files modifications */
libspid_boolean_t is_warn_needed;
/* hpav.conf last values */
- struct
- {
- /* CCo preference */
- libspid_boolean_t is_cco_preferred;
- /* CCo status at boot */
- libspid_boolean_t was_cco;
- /* NMK value */
- char nmk_str[LIBSPID_HPAV_CONF_NMK_STR_LEN];
- /* NID value */
- char nid_str[LIBSPID_HPAV_CONF_NID_STR_LEN];
- /* SL value */
- char sl_str[LIBSPID_HPAV_CONF_SL_STR_MAX_LEN];
- /* user HFID value */
- char user_hfid[LIBSPID_HPAV_CONF_HFID_MAX_LEN];
- /* AVLN HFID value */
- char avln_hfid[LIBSPID_HPAV_CONF_HFID_MAX_LEN];
- } hpav_conf;
+ plcd_hpav_conf_t hpav_conf;
/* hpav.info last values */
- libspid_hpav_info_t hpav_info;
+ plcd_hpav_info_t hpav_info;
/** Last time the multicast info file was checked. */
struct timespec mcast_last_check;
diff --git a/cleopatre/devkit/plcd/src/plcd_files.c b/cleopatre/devkit/plcd/src/plcd_files.c
index b13242b9e2..0f834726a1 100644
--- a/cleopatre/devkit/plcd/src/plcd_files.c
+++ b/cleopatre/devkit/plcd/src/plcd_files.c
@@ -21,39 +21,87 @@
int
plcd_files_read_hpavconf (plcd_ctx_t *ctx)
{
- char is_cco_preferred_str[LIBSPID_BOOLEAN_STR_MAX_LEN] = {0};
- char was_cco_str[LIBSPID_BOOLEAN_STR_MAX_LEN] = {0};
+ char is_cco_preferred_str[LIBSPID_BOOLEAN_STR_MAX_LEN];
+ char was_cco_str[LIBSPID_BOOLEAN_STR_MAX_LEN];
+ libspid_error_t libspid_ret;
PLCD_ASSERT (ctx);
- /* read and save hpav.conf file contents */
- if ((LIBSPID_SUCCESS != libspid_config_read_item (ctx->hpav_conf_path,
- LIBSPID_HPAV_CONF_LABEL_CCO_PREFERRED, is_cco_preferred_str,
- LIBSPID_BOOLEAN_STR_MAX_LEN))
- || (LIBSPID_SUCCESS != libspid_config_read_item (ctx->hpav_conf_path,
- LIBSPID_HPAV_CONF_LABEL_WAS_CCO, was_cco_str, LIBSPID_BOOLEAN_STR_MAX_LEN))
- || (LIBSPID_SUCCESS != libspid_config_read_item (ctx->hpav_conf_path,
- LIBSPID_HPAV_CONF_LABEL_NMK, ctx->hpav_conf.nmk_str,
- LIBSPID_HPAV_CONF_NMK_STR_LEN))
- || (LIBSPID_SUCCESS != libspid_config_read_item (ctx->hpav_conf_path,
- LIBSPID_HPAV_CONF_LABEL_NID, ctx->hpav_conf.nid_str,
- LIBSPID_HPAV_CONF_NID_STR_LEN))
- || (LIBSPID_SUCCESS != libspid_config_read_item (ctx->hpav_conf_path,
- LIBSPID_HPAV_CONF_LABEL_SL, ctx->hpav_conf.sl_str,
- LIBSPID_HPAV_CONF_SL_STR_MAX_LEN))
- || (LIBSPID_SUCCESS != libspid_config_read_item (ctx->hpav_conf_path,
- LIBSPID_HPAV_CONF_LABEL_USER_HFID, ctx->hpav_conf.user_hfid,
- LIBSPID_HPAV_CONF_HFID_MAX_LEN))
- || (LIBSPID_SUCCESS != libspid_config_read_item (ctx->hpav_conf_path,
- LIBSPID_HPAV_CONF_LABEL_AVLN_HFID, ctx->hpav_conf.avln_hfid,
- LIBSPID_HPAV_CONF_HFID_MAX_LEN)))
+ memset (is_cco_preferred_str, 0, sizeof (is_cco_preferred_str));
+ memset (was_cco_str, 0, sizeof (was_cco_str));
+
+ /* Only NMK item is mandatory, other are optionals.
+ * There is no default value possible. */
+ if (LIBSPID_SUCCESS
+ != libspid_config_read_item (
+ ctx->hpav_conf_path,
+ LIBSPID_HPAV_CONF_LABEL_NMK,
+ ctx->hpav_conf.nmk_str,
+ LIBSPID_HPAV_CONF_NMK_STR_LEN))
+ {
+ syslog (LOG_ERR, "libspid NMK read failed");
+
+ return -1;
+ }
+
+ /* Optional items.
+ * Be careful, amount of labels, values and lens must be sync. */
+#define PLCD_HPAV_CONF_NB_ITEM 6
+ const char * const hpav_conf_labels[PLCD_HPAV_CONF_NB_ITEM] = {
+ LIBSPID_HPAV_CONF_LABEL_CCO_PREFERRED,
+ LIBSPID_HPAV_CONF_LABEL_WAS_CCO,
+ LIBSPID_HPAV_CONF_LABEL_NID,
+ LIBSPID_HPAV_CONF_LABEL_SL,
+ LIBSPID_HPAV_CONF_LABEL_USER_HFID,
+ LIBSPID_HPAV_CONF_LABEL_AVLN_HFID
+ };
+ char *hpav_conf_values[PLCD_HPAV_CONF_NB_ITEM] = {
+ is_cco_preferred_str,
+ was_cco_str,
+ ctx->hpav_conf.nid_str,
+ ctx->hpav_conf.sl_str,
+ ctx->hpav_conf.user_hfid,
+ ctx->hpav_conf.avln_hfid
+ };
+ const int hpav_conf_len[PLCD_HPAV_CONF_NB_ITEM] = {
+ LIBSPID_BOOLEAN_STR_MAX_LEN,
+ LIBSPID_BOOLEAN_STR_MAX_LEN,
+ LIBSPID_HPAV_CONF_NID_STR_LEN,
+ LIBSPID_HPAV_CONF_SL_STR_MAX_LEN,
+ LIBSPID_HPAV_CONF_HFID_MAX_LEN,
+ LIBSPID_HPAV_CONF_HFID_MAX_LEN
+ };
+
+ libspid_ret = libspid_config_read_items (
+ ctx->hpav_conf_path, hpav_conf_labels, hpav_conf_values,
+ hpav_conf_len, PLCD_HPAV_CONF_NB_ITEM);
+
+ if (LIBSPID_ERROR_NOT_FOUND != libspid_ret
+ && LIBSPID_SUCCESS != libspid_ret)
{
- syslog (LOG_WARNING, "libspid config read item failed");
+ syslog (LOG_ERR, "libspid read optional items failed");
return -1;
}
+ /* Interpret strings returned (or not) by libspid. */
ctx->hpav_conf.is_cco_preferred = LIBSPID_GET_BOOLEAN (is_cco_preferred_str);
ctx->hpav_conf.was_cco = LIBSPID_GET_BOOLEAN (was_cco_str);
+
+ if (strlen (ctx->hpav_conf.nid_str) == 0)
+ strncpy (ctx->hpav_conf.nid_str,
+ LIBSPID_VALUE_NONE,
+ LIBSPID_HPAV_CONF_NID_STR_LEN - 1);
+
+ /* Set to default value (Simple Connect),
+ * if any available value found. */
+ if (strcmp (ctx->hpav_conf.sl_str, LIBSPID_HPAV_CONF_VALUE_SL_SC)
+ && strcmp (ctx->hpav_conf.sl_str, LIBSPID_HPAV_CONF_VALUE_SL_HS))
+ strncpy (ctx->hpav_conf.sl_str,
+ LIBSPID_HPAV_CONF_VALUE_SL_SC,
+ LIBSPID_HPAV_CONF_SL_STR_MAX_LEN - 1);
+
+ /* No default value for user_hfid and avln_hfid. */
+
return 0;
}
@@ -69,19 +117,33 @@ plcd_files_write_default_hpavinfo (plcd_ctx_t *ctx)
ctx->hpav_info.is_sc = LIBSPID_FALSE;
ctx->hpav_info.is_sc_button = LIBSPID_FALSE;
- /* create an empty hpav.info file for writing default values */
- if ((LIBSPID_SUCCESS != libspid_config_write_item (ctx->hpav_info_path,
- LIBSPID_HPAV_INFO_LABEL_STATUS, LIBSPID_HPAV_INFO_VALUE_STATUS_UNASSOCIATED))
- || (LIBSPID_SUCCESS != libspid_config_write_item (ctx->hpav_info_path,
- LIBSPID_HPAV_INFO_LABEL_CCO, LIBSPID_HPAV_INFO_VALUE_CCO_STATION))
- || (LIBSPID_SUCCESS != libspid_config_write_item (ctx->hpav_info_path,
- LIBSPID_HPAV_INFO_LABEL_BACKUP_CCO, LIBSPID_VALUE_BOOLEAN_FALSE))
- || (LIBSPID_SUCCESS != libspid_config_write_item (ctx->hpav_info_path,
- LIBSPID_HPAV_INFO_LABEL_SC, LIBSPID_VALUE_BOOLEAN_FALSE))
- || (LIBSPID_SUCCESS != libspid_config_write_item (ctx->hpav_info_path,
- LIBSPID_HPAV_INFO_LABEL_SC_BUTTON, LIBSPID_VALUE_BOOLEAN_FALSE)))
+ /* Be careful, amount of labels and values must be sync. */
+#define PLCD_HPAV_INFO_NB_ITEM 5
+
+ /* Create a default hpav.info file with libspid. */
+ const char * const hpav_info_labels[PLCD_HPAV_INFO_NB_ITEM] = {
+ LIBSPID_HPAV_INFO_LABEL_STATUS,
+ LIBSPID_HPAV_INFO_LABEL_CCO,
+ LIBSPID_HPAV_INFO_LABEL_BACKUP_CCO,
+ LIBSPID_HPAV_INFO_LABEL_SC,
+ LIBSPID_HPAV_INFO_LABEL_SC_BUTTON
+ };
+ const char * const hpav_info_values[PLCD_HPAV_INFO_NB_ITEM] = {
+ ctx->hpav_info.status,
+ ctx->hpav_info.cco,
+ LIBSPID_VALUE_BOOLEAN_FALSE,
+ LIBSPID_VALUE_BOOLEAN_FALSE,
+ LIBSPID_VALUE_BOOLEAN_FALSE
+ };
+
+ if (LIBSPID_SUCCESS != libspid_config_write_items (
+ ctx->hpav_info_path,
+ hpav_info_labels, hpav_info_values,
+ PLCD_HPAV_INFO_NB_ITEM))
{
- syslog (LOG_WARNING, "libspid config write item failed");
+ syslog (LOG_ERR,
+ "libspid write items failed (file: %s)",
+ ctx->hpav_info_path);
return -1;
}