Mercurial > prosody-modules
changeset 643:28b0a8cd950a
mod_webpresence: Update to timber, remove squish hack (icons are now loaded relative to the module file)
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sat, 28 Apr 2012 19:44:42 +0100 (2012-04-28) |
parents | 842a8a3b0d81 |
children | ceac1a0e74ea |
files | mod_webpresence/mod_webpresence.in.lua mod_webpresence/mod_webpresence.lua mod_webpresence/squishy |
diffstat | 3 files changed, 54 insertions(+), 112 deletions(-) [+] |
line wrap: on
line diff
--- a/mod_webpresence/mod_webpresence.in.lua Sat Apr 28 18:21:29 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +0,0 @@ -local jid_split = require "util.jid".prepped_split; - -if not require_resource then - function require_resource(name) - local f = io.open((config.get("*", "core", "presence_icons") or "")..name); - if f then - return f:read("*a"); - end - module:log("warn", "Failed to open image file %s", (config.get("*", "core", "presence_icons") or "")..name); - return ""; - end -end - -local response_404 = { status = "404 Not Found", body = "<h1>Page Not Found</h1>Sorry, we couldn't find what you were looking for :(" }; - -local statuses = { "online", "away", "xa", "dnd", "chat", "offline" }; - -for _, status in ipairs(statuses) do - statuses[status] = { status = "200 OK", headers = { ["Content-Type"] = "image/png" }, - body = require_resource("icons/status_"..status..".png") }; -end - -local function handle_request(method, body, request) - local jid = request.url.path:match("[^/]+$"); - if jid then - local user, host = jid_split(jid); - if host and not user then - user, host = host, request.headers.host; - if host then host = host:gsub(":%d+$", ""); end - end - if user and host then - local user_sessions = hosts[host] and hosts[host].sessions[user]; - if user_sessions then - local status = user_sessions.top_resources[1]; - if status and status.presence then - status = status.presence:child_with_name("show"); - if not status then - status = "online"; - else - status = status:get_text(); - end - return statuses[status]; - end - end - end - end - return statuses.offline; -end - -local ports = config.get(module.host, "core", "http_ports") or { 5280 }; -require "net.httpserver".new_from_config(ports, "status", handle_request);
--- a/mod_webpresence/mod_webpresence.lua Sat Apr 28 18:21:29 2012 +0100 +++ b/mod_webpresence/mod_webpresence.lua Sat Apr 28 19:44:42 2012 +0100 @@ -1,49 +1,56 @@ -do local e={};e["icons/status_online.png"]='�PNG\r\ -\ -\0\0\0\rIHDR\0\0\0\0\0\0\0\0\0�V%\0\0\0sBIT|d�\0\0\0 pHYs\0\0\r�\0\0\r�B(�x\0\0\0tEXtSoftware\0www.inkscape.org��<\0\0IDAT(�U�_h[u�?�wo�M�65K�el]�+��a[u�OE\ -"�>D܆P�d0����/V�ӗ�XAa��)��Ct�i�����n7�U��$m�&Mn��{ׇ;kw���p���s��뺬�\'?��7C��jZ�����Ԣ� T��u����\\;�zV��wxG�n{f4�3���wiI���/�/���ѿ�^;y�^���#����j�b��B\0H["�%v��1���k�?�R۶��<�\ -���\\b��Ь*Z@C�{�A\r�PQu%�3ε�jL�\0���ޕ�{Yh�T��P���y��ɟ\'�� ��ޫ��?��(��a+dE((BAh�c3T���^Ob0�a��2K�%u���U�-��.�x"-K��Ÿ`ߖ}�zb���cz�4P��ª��ґȲ�9���l��6m�i���b��A.w\\Fn�/7XQA GZ�Ч!��~�a�lcm"G"�9��� ��<�����x�ULE���o.5�"-�-�>~�@6@��$�>�<JӚ&�q��8���<���pZ�)�[�<�H\'\0�I���%��~#�t�gR!X����־����ؽ���2F�� #�\0p�C܈���wp*<��d������3S��/?�oY�V�\\�v�6X����a\ -�V��������SC�����T&��[��ζ�B5�?�1�2oe@��uw�DήI����\'�%�+ƈ�ݩ�QN��{<�J᱂�TTd�:\r�6��\\\ -}��q���s��C�Z��ӝ/V�����jg-hE�����ӯ�������_���\'�i�~�&\0\0\0\0IEND�B`�'e["icons/status_away.png"]='�PNG\r\ -\ -\0\0\0\rIHDR\0\0\0\0\0\0\0\0\0�V%\0\0\0sBIT|d�\0\0\0 pHYs\0\0\r�\0\0\r�B(�x\0\0\0tEXtSoftware\0www.inkscape.org��<\0\01IDAT(�U�_L�u\0����{���Q�D� at���Ԍp�X�H�g��\\��5��a��Vm��څEK��E.Bm,\'� �H�) �����9�y��{]�����s�<�R��9���/���*���nA<�Ʀ]���m�����s��=��nS�lq����2����\0�t��c3w���r��I��p��w��~�x�ry��T��n0�i���i���8��.�p�ԉ3J\0<����X-V\0=0}�|�`�?���b��`�7A�}��m\0����m���5Ç0M���sf��Dj��K��+��XΚ����<_��0UzW8� �@:�a �~tˏfhB��á��f,��ͤX�(�[��>c��y�@y(�)��BI���,Y��ue�y�z3o�$胰�Z&�,�PII*���C����$2�d�I�{C��ֻ|���S����<\0��"�r��:��p�.���d�J�I$x�-���6~����/���Q�`�ք1>�E�b�}t~x�֣ͼw��Ҩ�{�u���5�T%�%%\0�Ӿ��}�f&����Կ�G��Ъ`x��7<IM��Gw3H�@*�;0��K"���U�Dtd��/�M}C#6nfo��l ^`E(����5�����y�z�_C����z�cy�+W�����um��d��sx�IT�f�`2��\ -�{~��_SJQ]�U+����FFK�3��GϰőgƘY�Lz�A>�=4�>���=Fu�VC�h��?��bɔ�4C̠ɬ�w��U������j�wv����{Y[��ҏ]�@��*���N�nk^���q�Ro���,3v��,j�\0\0\0\0IEND�B`�'e["icons/status_xa.png"]="�PNG\r\ -\ -\0\0\0\rIHDR\0\0\0\0\0\0\0\0\0�V%\0\0\0sBIT|d�\0\0\0 pHYs\0\0\r�\0\0\r�B(�x\0\0\0tEXtSoftware\0www.inkscape.org��<\0\07IDAT(�U�mLUu\0���s�=�s�7���Lo�C��jm\r��IlB��h�����Ћ�sE�����zq���ImI�,m �(6�)|P,��.��������������쑄,Ϟ��6��ivF�jYEq�hF���������tC�m���E?�K�ۤIH�mL����Dm�3�r�љPy����uS�m���^����JUMƥ�\0X�C�p�O��Kk���-,�>_SU180$d����'�x���h���S��T��>u��o�_PD�����87s@~���i�ҵ�/����M4��ώ��#���8�ӹk/�Ot���$X�ʖ���k%�|!�X�P�KW����6�օx�s�b��G�uk;/?����etJ� ����%{�F�����};y�X��/��!�����8B��aa������ҁ��D����>7^��Ӷ���*>��+�~?�X�ƚ{y_��IX��&�����Eq9ic�9��acd�d���i��(\0�`���vp�\0��`�Ӓ$�j���5�T ��O\r�7��M\r��Ӆat=��P%��p���x��Y%�j3ٌ]p�Ѻ���~D������a&FFس�\0w����zv��XԽ3R䡺�����L'\\�+�z�������װL�3��ZU��딎��������͒��á#��N�ge���ʑ\\2��Q�m ,K2�L��M�7��^hQ\0��ڎc����+���_ ��E�e'(.�i-\\1��m����J������X�������M1�Q䋉���;Vw�>�E����*�lwQ:����E�=wUU'���v�?�����h��j��\0\0\0\0IEND�B`�"e["icons/status_dnd.png"]="�PNG\r\ -\ -\0\0\0\rIHDR\0\0\0\0\0\0\0\0\0�V%\0\0\0sBIT|d�\0\0\0 pHYs\0\0\r�\0\0\r�B(�x\0\0\0tEXtSoftware\0www.inkscape.org��<\0\0�IDAT(�}��k\\U���s��;IBj�\"���2h���RL��M[pQ����WnDtUQ(�nZ*6�]T�\ -�ªP-�lL-I�$����w���⚚ ���w��^x��D�����;{��-��S�GZ�宩�������_��U���٣��6�?�j��d\ -%!���E`9�x��}W'��zy�?�O��Z�����x�i��.�+#E��i:mϷ{G~;�ܡ����\0h�^x���k}���`m�^D�@�w��)��|xp��_�'�浙�7~0XS*�'�}�z�`��@�B�����\"v�|�_���:;��ڢ�1�Z� R��Z�5(�P\ -����_��6ϙ�(��\ -7�\0i���+R�1J�1A 1D�i�W���L�>�F�b�{s����9�s��f�=��?���=7j�!!ƈ�k-���(�ͦJVj�<w�]>�3��B� DAD�֚�Z�]1�4[���C��/��4�j�D!@��UY��@�����}�b�������SC�B�P��ʴ�zE�,E�n�w��������p�1����e:�]Yߕ��_��\\|j�ڭ{����ɉ�'�֓�{�+��|�_����R:6rj��x����u�Rc���ፖN�uj)���О�O�?y�[�]�x�t��#������fjWW���d�������ݿ(�y�Ri�\0\0\0\0IEND�B`�"e["icons/status_chat.png"]='�PNG\r\ -\ -\0\0\0\rIHDR\0\0\0\0\0\0\0\0\0�V%\0\0\0sBIT|d�\0\0\0 pHYs\0\0\r�\0\0\r�B(�x\0\0\0tEXtSoftware\0www.inkscape.org��<\0\0IDAT(�U�L�u����s��!����D�`s��q�Y:3�deS˭��1���5d�-���m�f�rㇶ6;f-o��Zs؈X6`LԎ�������������K��k?��P�W�t:r5c�0:��75m\rLƌP��/ު���z��[�/�=�����@�4"�Xb24��~����ğo/�ǎ�{_h���h�*�Rn�r"),I �$��3�=]}8�@�m��@�J���.Fk/Z�к�<���-�n��o:����\0���w��//��g�Mk6�E)�ŲbX�}N����\r�`"�&�����o++tyY�ŕ�Ma�p\0�к�\ -P�E�h�������v��si�w%]��D�a�gk�B�Y �e%�,���Nݦ��G�{�bu�o��X�d(-��+�g�E2tw�P\\<M�3N��G���ɓg�7�������-I�33ss��&ׯ���oC�?xzg���c�+�YS�����f �\0�\0� �Ld�D" jk�s����b����"|�#G�p�g�,,K1q�yGϦ�̓g����Z[/��\ -u����Z� �@\ -�J 2���ܝ����u�ȵ���X%�W�իa���u�H����H�T7���j*�jލ�������Z&cy�����\\�={���$n��Cq��.�u��~-" "�������.�D�}��䧟�7��Knٲ�7��Su�%XDx�����7��{lK��`��-�����("��j��[,ϛ\rVT�V/se}�c��Ȉ��aw^�������b�@0�3\0\0\0\0IEND�B`�'e["icons/status_offline.png"]="�PNG\r\ -\ -\0\0\0\rIHDR\0\0\0\0\0\0\0\0\0�V%\0\0\0sBIT|d�\0\0\0 pHYs\0\0\r�\0\0\r�B(�x\0\0\0tEXtSoftware\0www.inkscape.org��<\0\0IDAT(�U��Kcg��^���\\��[;���S�Ap�)t�m�L)3V,dp��`6����]�/BA�2�JA�P���(����i�NҚdD'~Nr?�X��ٝ��=�Q��\\�_?V����AQ�v� �������埮g�j���C�i�a����(\0B<��u].//��ūT]>Z~��P�E�o5Fo�f���0\0����P0w�r���{�U���F��փ�6660�41]����!�J��d<�<P>�߯F>���������H)�u�t:���8###8�����F0>0��{5���놚�d���dpp���vFGG�m���n��8�T���ft]GJ���Q��\0�X���y������`ee������YZZb�����I��)����F�\ -(��szz����P���#z{{��bT*��2������Du��<��$MMM�E\ -�\0�m�L&�����<�\0x��jm7���֬������J����#�LR�TH$�������eYh���i)���˸���8d�Y��������Β�f���abb���~����u]|�e���>�Ь�¡��������R�D\"Agg'��S,�RRWWG�TUʓ��EJ�Gw?�ގ��<�\\.�������i��#��������3y��_?n���T�p�ztx\\�CQ���۶B�� ˲^���E�W���lx��V��ߥ��aY�7�&���Â�3�Y�D��_~���UUu��۟_<1��mU�ir���r���Z���7�������g����D\0\0\0\0IEND�B`�"function require_resource(r)return e[r]or error("resource '"..tostring(r).."' not found");end end local s=require"util.jid".prepped_split;if not require_resource then -function require_resource(e)local r=io.open((config.get("*","core","presence_icons")or"")..e);if r then -return r:read("*a");end -module:log("warn","Failed to open image file %s",(config.get("*","core","presence_icons")or"")..e);return"";end +module:depends("http"); + +local jid_split = require "util.jid".prepped_split; + +if not require_resource then + function require_resource(name) + local icon_path = module:get_option_string("presence_icons", "icons"); + local f, err = module:load_resource(icon_path.."/"..name); + if f then + return f:read("*a"); + end + module:log("warn", "Failed to open image file %s", icon_path..name); + return ""; + end +end + +local statuses = { "online", "away", "xa", "dnd", "chat", "offline" }; + +for _, status in ipairs(statuses) do + statuses[status] = { status_code = 200, headers = { content_type = "image/png" }, + body = require_resource("status_"..status..".png") }; end -local e={status="404 Not Found",body="<h1>Page Not Found</h1>Sorry, we couldn't find what you were looking for :("};local n={"online","away","xa","dnd","chat","offline"};for r,e in ipairs(n)do -n[e]={status="200 OK",headers={["Content-Type"]="image/png"},body=require_resource("icons/status_"..e..".png")};end -local function t(e,e,o)local e=o.url.path:match("[^/]+$");if e then -local r,e=s(e);if e and not r then -r,e=e,o.headers.host;if e then e=e:gsub(":%d+$","");end + +local function handle_request(event, path) + local jid = path:match("[^/]+$"); + if jid then + local user, host = jid_split(jid); + if host and not user then + user, host = host, event.request.headers.host; + if host then host = host:gsub(":%d+$", ""); end + end + if user and host then + local user_sessions = hosts[host] and hosts[host].sessions[user]; + if user_sessions then + local status = user_sessions.top_resources[1]; + if status and status.presence then + status = status.presence:child_with_name("show"); + if not status then + status = "online"; + else + status = status:get_text(); + end + return statuses[status]; + end + end + end + end + return statuses.offline; end -if r and e then -local e=hosts[e]and hosts[e].sessions[r];if e then -local e=e.top_resources[1];if e and e.presence then -e=e.presence:child_with_name("show");if not e then -e="online";else -e=e:get_text();end -return n[e];end -end -end -end -return n.offline;end -local e=config.get(module.host,"core","http_ports")or{5280};require"net.httpserver".new_from_config(e,"status",t); \ No newline at end of file + +module:provides("http", { + default_path = "/status"; + route = { + ["GET /*"] = handle_request; + }; +});
--- a/mod_webpresence/squishy Sat Apr 28 18:21:29 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,14 +0,0 @@ - -Option "minify-level" "full" - -Resource "icons/status_online.png" -Resource "icons/status_away.png" -Resource "icons/status_xa.png" -Resource "icons/status_dnd.png" -Resource "icons/status_chat.png" -Resource "icons/status_offline.png" - -Main "mod_webpresence.in.lua" - -Output "mod_webpresence.lua" -