client: Restructure {srvc,bankd}_read_cb()

Introduce some switch statements to make code more extensable.

Change-Id: I9d1a6c29cbfc2f01995a2093978fae8577f1771f
changes/97/13497/1
Harald Welte 4 years ago
parent 15b75e1e5c
commit 1a17104639
  1. 27
      src/remsim_client.c
  2. 33
      src/remsim_client_fsm.c

@ -49,18 +49,23 @@ int bankd_read_cb(struct ipa_client_conn *conn, struct msgb *msg)
if (msgb_length(msg) < sizeof(*hh))
goto invalid;
msg->l2h = &hh->data[0];
if (hh->proto != IPAC_PROTO_OSMO)
goto invalid;
if (!he || msgb_l2len(msg) < sizeof(*he))
goto invalid;
msg->l2h = &he->data[0];
if (he->proto != IPAC_PROTO_EXT_RSPRO)
switch (hh->proto) {
case IPAC_PROTO_OSMO:
if (!he || msgb_l2len(msg) < sizeof(*he))
goto invalid;
msg->l2h = &he->data[0];
switch (he->proto) {
case IPAC_PROTO_EXT_RSPRO:
printf("Received RSPRO %s\n", msgb_hexdump(msg));
rc = bankd_handle_msg(bc, msg);
break;
default:
goto invalid;
}
break;
default:
goto invalid;
printf("Received RSPRO %s\n", msgb_hexdump(msg));
rc = bankd_handle_msg(bc, msg);
}
return rc;

@ -281,21 +281,28 @@ static int srvc_read_cb(struct ipa_client_conn *conn, struct msgb *msg)
if (msgb_length(msg) < sizeof(*hh))
goto invalid;
msg->l2h = &hh->data[0];
if (hh->proto != IPAC_PROTO_OSMO)
goto invalid;
if (!he || msgb_l2len(msg) < sizeof(*he))
goto invalid;
msg->l2h = &he->data[0];
if (he->proto != IPAC_PROTO_EXT_RSPRO)
goto invalid;
printf("Received RSPRO %s\n", msgb_hexdump(msg));
pdu = rspro_dec_msg(msg);
if (!pdu)
switch (hh->proto) {
case IPAC_PROTO_OSMO:
if (!he || msgb_l2len(msg) < sizeof(*he))
goto invalid;
msg->l2h = &he->data[0];
switch (he->proto) {
case IPAC_PROTO_EXT_RSPRO:
printf("Received RSPRO %s\n", msgb_hexdump(msg));
pdu = rspro_dec_msg(msg);
if (!pdu)
goto invalid;
rc = srvc->handle_rx(srvc, pdu);
ASN_STRUCT_FREE(asn_DEF_RsproPDU, pdu);
break;
default:
goto invalid;
}
break;
default:
goto invalid;
}
rc = srvc->handle_rx(srvc, pdu);
return rc;
invalid:

Loading…
Cancel
Save