396 end |
396 end |
397 |
397 |
398 return stanza; |
398 return stanza; |
399 end |
399 end |
400 |
400 |
401 local function clone(stanza) |
401 local function _clone(stanza) |
402 local attr, tags = {}, {}; |
402 local attr, tags = {}, {}; |
403 for k,v in pairs(stanza.attr) do attr[k] = v; end |
403 for k,v in pairs(stanza.attr) do attr[k] = v; end |
404 local old_namespaces, namespaces = stanza.namespaces; |
404 local old_namespaces, namespaces = stanza.namespaces; |
405 if old_namespaces then |
405 if old_namespaces then |
406 namespaces = {}; |
406 namespaces = {}; |
408 end |
408 end |
409 local new = { name = stanza.name, attr = attr, namespaces = namespaces, tags = tags }; |
409 local new = { name = stanza.name, attr = attr, namespaces = namespaces, tags = tags }; |
410 for i=1,#stanza do |
410 for i=1,#stanza do |
411 local child = stanza[i]; |
411 local child = stanza[i]; |
412 if child.name then |
412 if child.name then |
413 child = clone(child); |
413 child = _clone(child); |
414 t_insert(tags, child); |
414 t_insert(tags, child); |
415 end |
415 end |
416 t_insert(new, child); |
416 t_insert(new, child); |
417 end |
417 end |
418 return setmetatable(new, stanza_mt); |
418 return setmetatable(new, stanza_mt); |
|
419 end |
|
420 |
|
421 local function clone(stanza) |
|
422 if not is_stanza(stanza) then |
|
423 error("bad argument to clone: expected stanza, got "..type(stanza)); |
|
424 end |
|
425 return _clone(stanza); |
419 end |
426 end |
420 |
427 |
421 local function message(attr, body) |
428 local function message(attr, body) |
422 if not body then |
429 if not body then |
423 return new_stanza("message", attr); |
430 return new_stanza("message", attr); |