pespin has uploaded this change for review.

View Change

cups_client: SPlit Tx of json str into its own function

This helper can be used in the future to submit a str multiple times
(eg. to multiple cups clients) without having to re-allocate the
content.

Change-Id: I505bf2eeea998a749e55f8f3b05c5013b5761297
---
M daemon/cups_client.c
1 file changed, 22 insertions(+), 16 deletions(-)

git pull ssh://gerrit.osmocom.org:29418/osmo-uecups refs/changes/55/42455/1
diff --git a/daemon/cups_client.c b/daemon/cups_client.c
index acadcd5..e283f23 100644
--- a/daemon/cups_client.c
+++ b/daemon/cups_client.c
@@ -85,13 +85,30 @@
talloc_free(sproc);
}

+static int cups_client_tx_json_str(struct cups_client *cc, const char *json_str, unsigned int json_strlen)
+{
+ struct msgb *msg = msgb_alloc(CUPS_MSGB_SIZE, "Tx JSON");
+ char *out;
+ LOGCC(cc, LOGL_DEBUG, "JSON Tx '%s'\n", json_str);
+
+ if (json_strlen > msgb_tailroom(msg)) {
+ LOGCC(cc, LOGL_ERROR, "Not enough room for JSON in msgb\n");
+ return 0;
+ }
+
+ out = (char *)msgb_put(msg, json_strlen);
+ memcpy(out, json_str, json_strlen);
+ osmo_stream_srv_send(cc->srv, msg);
+
+ return 0;
+}
+
/* Send JSON to a given client/connection */
int cups_client_tx_json(struct cups_client *cc, json_t *jtx)
{
- struct msgb *msg = msgb_alloc(CUPS_MSGB_SIZE, "Tx JSON");
char *json_str = json_dumps(jtx, JSON_SORT_KEYS);
- char *out;
- int json_strlen;
+ unsigned int json_strlen;
+ int rc;

json_decref(jtx);
if (!json_str) {
@@ -100,20 +117,9 @@
}
json_strlen = strlen(json_str);

- LOGCC(cc, LOGL_DEBUG, "JSON Tx '%s'\n", json_str);
-
- if (json_strlen > msgb_tailroom(msg)) {
- LOGCC(cc, LOGL_ERROR, "Not enough room for JSON in msgb\n");
- free(json_str);
- return 0;
- }
-
- out = (char *)msgb_put(msg, json_strlen);
- memcpy(out, json_str, json_strlen);
+ rc = cups_client_tx_json_str(cc, json_str, json_strlen);
free(json_str);
- osmo_stream_srv_send(cc->srv, msg);
-
- return 0;
+ return rc;
}

json_t *gen_uecups_result(const char *name, const char *res)

To view, visit change 42455. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: newchange
Gerrit-Project: osmo-uecups
Gerrit-Branch: master
Gerrit-Change-Id: I505bf2eeea998a749e55f8f3b05c5013b5761297
Gerrit-Change-Number: 42455
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin@sysmocom.de>