MCPcopy Create free account
hub / github.com/ElementsProject/lightning / rune_altern_decode

Function rune_altern_decode

ccan/ccan/rune/coding.c:217–258  ·  view source on GitHub ↗

Sets *more on success: true if another altern follows */

Source from the content-addressed store, hash-verified

215
216/* Sets *more on success: true if another altern follows */
217static struct rune_altern *rune_altern_decode(const tal_t *ctx,
218 const char **data, size_t *len,
219 bool *more)
220{
221 struct rune_altern *alt = tal(ctx, struct rune_altern);
222 char *value;
223 size_t strlen;
224 char c;
225
226 /* Swallow field up to possible conditional */
227 strlen = rune_altern_fieldname_len(*data, *len);
228 alt->fieldname = tal_strndup(alt, *data, strlen);
229 *data += strlen;
230 *len -= strlen;
231
232 /* Grab conditional */
233 if (!pull_char(data, len, &c) || !rune_condition_is_valid(c))
234 return tal_free(alt);
235
236 alt->condition = c;
237
238 /* Assign worst case. */
239 value = tal_arr(alt, char, *len + 1);
240 strlen = 0;
241 *more = false;
242 while (*len && pull_char(data, len, &c)) {
243 if (c == '|') {
244 *more = true;
245 break;
246 }
247 if (c == '&')
248 break;
249
250 if (c == '\\' && !pull_char(data, len, &c))
251 return tal_free(alt);
252 value[strlen++] = c;
253 }
254 value[strlen] = '\0';
255 tal_resize(&value, strlen + 1);
256 alt->value = value;
257 return alt;
258}
259
260static struct rune_restr *rune_restr_decode(const tal_t *ctx,
261 const char **data, size_t *len)

Callers 1

rune_restr_decodeFunction · 0.85

Calls 4

pull_charFunction · 0.85
rune_condition_is_validFunction · 0.85
tal_freeFunction · 0.85

Tested by

no test coverage detected