Comparison

plugins/mod_storage_xep0227.lua @ 12184:326f5466ddc7

mod_storage_xep0227: Add API to iterate all stores of a user
author Matthew Wild <mwild1@gmail.com>
date Fri, 14 Jan 2022 16:57:19 +0000
parent 12183:e77c938ed92b
child 12185:708769a4c5da
comparison
equal deleted inserted replaced
12183:e77c938ed92b 12184:326f5466ddc7
686 instance._get_user_xml = assert(options.get_user_xml); 686 instance._get_user_xml = assert(options.get_user_xml);
687 end 687 end
688 return instance; 688 return instance;
689 end 689 end
690 690
691 local function get_store_names_from_xml(self, user_xml)
692 local stores = set.new();
693 for handler_name, handler_funcs in pairs(handlers) do
694 if handler_funcs._stores then
695 stores:include(handler_funcs._stores(self, user_xml));
696 else
697 stores:include(handler_name);
698 end
699 end
700 return stores;
701 end
702
691 local function get_store_names(self, path) 703 local function get_store_names(self, path)
692 local stores = set.new(); 704 local stores = set.new();
693 local f, err = io_open(paths.join(prosody.paths.data, path)); 705 local f, err = io_open(paths.join(prosody.paths.data, path));
694 if not f then 706 if not f then
695 module:log("warn", "Unable to load XML file for <%s>: %s", "store listing", err); 707 module:log("warn", "Unable to load XML file for <%s>: %s", "store listing", err);
696 return stores; 708 return stores;
697 end 709 end
698 module:log("info", "Loaded %s", path); 710 module:log("info", "Loaded %s", path);
699 local s = f:read("*a"); 711 local s = f:read("*a");
700 f:close(); 712 f:close();
701 local xml = parse_xml_real(s); 713 local user_xml = parse_xml_real(s);
702 for _, handler_funcs in pairs(handlers) do 714 return get_store_names_from_xml(self, user_xml);
703 if handler_funcs._stores then
704 stores:include(handler_funcs._stores(self, xml));
705 end
706 end
707 return stores;
708 end 715 end
709 716
710 function driver:stores(username) 717 function driver:stores(username)
711 local store_dir = prosody.paths.data; 718 local store_dir = prosody.paths.data;
712 719
731 end 738 end
732 739
733 return store_names:items(); 740 return store_names:items();
734 end 741 end
735 742
743 function driver:xep0227_user_stores(username, host)
744 local user_xml = self:_get_user_xml(username, host);
745 if not user_xml then
746 return nil;
747 end
748 local store_names = get_store_names_from_xml(username, host);
749 return store_names:items();
750 end
751
736 module:provides("storage", driver); 752 module:provides("storage", driver);