Comparison

util/stanza.lua @ 11088:1f84d0e4d0c4

util.stanza: Extract Application-Specific Condition from errors API change
author Kim Alvefur <zash@zash.se>
date Sat, 26 Sep 2020 18:12:18 +0200
parent 11086:2846b6226a8e
child 11206:f051394762ff
comparison
equal deleted inserted replaced
11087:cdd4684992f1 11088:1f84d0e4d0c4
347 return t_concat(t); 347 return t_concat(t);
348 end 348 end
349 end 349 end
350 350
351 function stanza_mt.get_error(stanza) 351 function stanza_mt.get_error(stanza)
352 local error_type, condition, text; 352 local error_type, condition, text, extra_tag;
353 353
354 local error_tag = stanza:get_child("error"); 354 local error_tag = stanza:get_child("error");
355 if not error_tag then 355 if not error_tag then
356 return nil, nil, nil; 356 return nil, nil, nil, nil;
357 end 357 end
358 error_type = error_tag.attr.type; 358 error_type = error_tag.attr.type;
359 359
360 for _, child in ipairs(error_tag.tags) do 360 for _, child in ipairs(error_tag.tags) do
361 if child.attr.xmlns == xmlns_stanzas then 361 if child.attr.xmlns == xmlns_stanzas then
362 if not text and child.name == "text" then 362 if not text and child.name == "text" then
363 text = child:get_text(); 363 text = child:get_text();
364 elseif not condition then 364 elseif not condition then
365 condition = child.name; 365 condition = child.name;
366 end 366 end
367 if condition and text then 367 else
368 break; 368 extra_tag = child;
369 end 369 end
370 end 370 if condition and text and extra_tag then
371 end 371 break;
372 return error_type, condition or "undefined-condition", text; 372 end
373 end
374 return error_type, condition or "undefined-condition", text, extra_tag;
373 end 375 end
374 376
375 local function preserialize(stanza) 377 local function preserialize(stanza)
376 local s = { name = stanza.name, attr = stanza.attr }; 378 local s = { name = stanza.name, attr = stanza.attr };
377 for _, child in ipairs(stanza) do 379 for _, child in ipairs(stanza) do