common: error out if trying to set a HLQ item with incompatible version

Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
1 files changed, 24 insertions(+), 20 deletions(-)

M common/qso-pack.c
M common/qso-pack.c +24 -20
@@ 36,26 36,27 @@ 
 
 static const struct side_field {
 	const char *name;
+	int minver;
 	struct val *(*get)(const struct qso_side *);
 	int (*set)(struct qso_side *, struct val *);
 } side_fields[] = {
-	{ "station",   qso_get_station_call_val,  qso_set_station_call_val },
-	{ "operator",  qso_get_operator_call_val, qso_set_operator_call_val },
-	{ "power",     qso_get_power,             qso_set_power_val },
-	{ "freq",      qso_get_freq,              qso_set_freq_val },
-	{ "mode",      qso_get_mode_val,          qso_set_mode_val },
-	{ "rst",       qso_get_rst_val,           qso_set_rst_val },
-	{ "name",      qso_get_name_val,          qso_set_name_val },
-	{ "qth",       qso_get_qth_val,           qso_set_qth_val },
-	{ "grid",      qso_get_grid_val,          qso_set_grid_val },
-	{ "country",   qso_get_country_val,       qso_set_country_val },
-	{ "state",     qso_get_state_val,         qso_set_state_val },
-	{ "county",    qso_get_county_val,        qso_set_county_val },
-	{ "continent", qso_get_continent_val,     qso_set_continent_val },
-	{ "dxcc",      qso_get_zone_dxcc,         qso_set_zone_dxcc_val },
-	{ "itu",       qso_get_zone_itu,          qso_set_zone_itu_val },
-	{ "cqz",       qso_get_zone_cqz,          qso_set_zone_cqz_val },
-	{ "seq",       qso_get_seq,               qso_set_seq_val },
+	{ "station",   0, qso_get_station_call_val,  qso_set_station_call_val },
+	{ "operator",  0, qso_get_operator_call_val, qso_set_operator_call_val },
+	{ "power",     0, qso_get_power,             qso_set_power_val },
+	{ "freq",      0, qso_get_freq,              qso_set_freq_val },
+	{ "mode",      0, qso_get_mode_val,          qso_set_mode_val },
+	{ "rst",       0, qso_get_rst_val,           qso_set_rst_val },
+	{ "name",      0, qso_get_name_val,          qso_set_name_val },
+	{ "qth",       0, qso_get_qth_val,           qso_set_qth_val },
+	{ "grid",      0, qso_get_grid_val,          qso_set_grid_val },
+	{ "country",   0, qso_get_country_val,       qso_set_country_val },
+	{ "state",     0, qso_get_state_val,         qso_set_state_val },
+	{ "county",    0, qso_get_county_val,        qso_set_county_val },
+	{ "continent", 0, qso_get_continent_val,     qso_set_continent_val },
+	{ "dxcc",      0, qso_get_zone_dxcc,         qso_set_zone_dxcc_val },
+	{ "itu",       0, qso_get_zone_itu,          qso_set_zone_itu_val },
+	{ "cqz",       0, qso_get_zone_cqz,          qso_set_zone_cqz_val },
+	{ "seq",       0, qso_get_seq,               qso_set_seq_val },
 };
 
 /*

          
@@ 806,7 807,7 @@ static int __unpack_qso_ns(struct qso *q
 	return ret;
 }
 
-static int __unpack_side_ns(struct qso_side *side, const char *key,
+static int __unpack_side_ns(struct qso_side *side, int ver, const char *key,
 			    struct val *val)
 {
 	size_t i;

          
@@ 817,6 818,9 @@ static int __unpack_side_ns(struct qso_s
 		if (strcmp(f->name, key))
 			continue;
 
+		if (ver < f->minver)
+			return -EILSEQ;
+
 		return f->set(side, val);
 	}
 

          
@@ 849,10 853,10 @@ int qso_set_hlq_item(struct qso *qso, in
 			ret = __unpack_qso_ns(qso, key, val);
 			break;
 		case QSO_NS_TX:
-			ret = __unpack_side_ns(&qso->tx, key, val);
+			ret = __unpack_side_ns(&qso->tx, ver, key, val);
 			break;
 		case QSO_NS_RX:
-			ret = __unpack_side_ns(&qso->rx, key, val);
+			ret = __unpack_side_ns(&qso->rx, ver, key, val);
 			break;
 		case QSO_NS_ADDL:
 			ret = nvl_set(qso->additional, key, val);