{"action":"created","issue":{"url":"https://api.github.com/repos/processone/xmpp/issues/9","repository_url":"https://api.github.com/repos/processone/xmpp","labels_url":"https://api.github.com/repos/processone/xmpp/issues/9/labels{/name}","comments_url":"https://api.github.com/repos/processone/xmpp/issues/9/comments","events_url":"https://api.github.com/repos/processone/xmpp/issues/9/events","html_url":"https://github.com/processone/xmpp/issues/9","id":205855303,"number":9,"title":"XMPP codec should be modular","user":{"login":"zinid","id":1095902,"avatar_url":"https://avatars3.githubusercontent.com/u/1095902?v=4","gravatar_id":"","url":"https://api.github.com/users/zinid","html_url":"https://github.com/zinid","followers_url":"https://api.github.com/users/zinid/followers","following_url":"https://api.github.com/users/zinid/following{/other_user}","gists_url":"https://api.github.com/users/zinid/gists{/gist_id}","starred_url":"https://api.github.com/users/zinid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zinid/subscriptions","organizations_url":"https://api.github.com/users/zinid/orgs","repos_url":"https://api.github.com/users/zinid/repos","events_url":"https://api.github.com/users/zinid/events{/privacy}","received_events_url":"https://api.github.com/users/zinid/received_events","type":"User","site_admin":false},"labels":[{"id":483662752,"url":"https://api.github.com/repos/processone/xmpp/labels/enhancement","name":"enhancement","color":"84b6eb","default":true}],"state":"closed","locked":false,"assignee":{"login":"zinid","id":1095902,"avatar_url":"https://avatars3.githubusercontent.com/u/1095902?v=4","gravatar_id":"","url":"https://api.github.com/users/zinid","html_url":"https://github.com/zinid","followers_url":"https://api.github.com/users/zinid/followers","following_url":"https://api.github.com/users/zinid/following{/other_user}","gists_url":"https://api.github.com/users/zinid/gists{/gist_id}","starred_url":"https://api.github.com/users/zinid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zinid/subscriptions","organizations_url":"https://api.github.com/users/zinid/orgs","repos_url":"https://api.github.com/users/zinid/repos","events_url":"https://api.github.com/users/zinid/events{/privacy}","received_events_url":"https://api.github.com/users/zinid/received_events","type":"User","site_admin":false},"assignees":[{"login":"zinid","id":1095902,"avatar_url":"https://avatars3.githubusercontent.com/u/1095902?v=4","gravatar_id":"","url":"https://api.github.com/users/zinid","html_url":"https://github.com/zinid","followers_url":"https://api.github.com/users/zinid/followers","following_url":"https://api.github.com/users/zinid/following{/other_user}","gists_url":"https://api.github.com/users/zinid/gists{/gist_id}","starred_url":"https://api.github.com/users/zinid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zinid/subscriptions","organizations_url":"https://api.github.com/users/zinid/orgs","repos_url":"https://api.github.com/users/zinid/repos","events_url":"https://api.github.com/users/zinid/events{/privacy}","received_events_url":"https://api.github.com/users/zinid/received_events","type":"User","site_admin":false}],"milestone":null,"comments":8,"created_at":"2017-02-07T11:07:35Z","updated_at":"2018-02-05T20:21:44Z","closed_at":"2017-02-07T11:07:51Z","author_association":"MEMBER","body":"XMPP codec should allow third-party developers to create their own submodules and plug them into xmpp_codec.\r\nThis is implemented in 3976a85b40f85002713a93c74a0ffca664c3c062\r\nHere is a brief description for developers about how they could use it:\r\n* Clone xmpp library somewhere:\r\n   `$ git clone https://github.com/processone/xmpp`\r\n* Compile it:\r\n   `$ make`\r\n* Add new elements to `specs/xmpp_codec.spec` with proper `module` attribute set\r\n* Recompile the codec:\r\n   `$ make spec`\r\n* The generator will create new file(s) in `src` directory. Those files are your submodules. Grab them to the working directory of your project.\r\n* The generator also will generate new records (with specs) inside `include/xmpp_codec.hrl`. Grab those too in your project (either put them in your *.hrl files or in your *.erl files directly).\r\n* In runtime, call to xmpp:register_codec/1 in order to register your submodule within xmpp_codec.\r\n\r\nDone!\r\nNot very clear, eh? OK, here is an example.\r\n\r\nLet's say we want to add submodule for the following element:\r\n```xml\r\n<foo x='1' xmlns='ns:foo'/>\r\n```\r\nClone and compile the repo, open `specs/xmpp_codec.spec` and put the following spec somewhere inside it (the order doesn't matter):\r\n```erlang\r\n-xml(foo,\r\n     #elem{name = <<\"foo\">>,\r\n           xmlns = <<\"ns:foo\">>,\r\n           module = foo,\r\n           result = {foo, '$x'},\r\n           attrs = [#attr{name = <<\"x\">>}]}).\r\n```\r\nNow type `make spec` in order to recompile the specification. New file will be created inside `src` directory:\r\n```\r\n$ git status\r\n...\r\nUntracked files:\r\n   ...\r\n   src/foo.erl\r\n```\r\nCopy this `foo.erl` into your working directory.\r\nNow, consult the recompiled `xmpp_codec.hrl`:\r\n```\r\n$ git diff include/xmpp_codec.hrl\r\n...\r\n+-record(foo, {x = <<>> :: binary()}).\r\n+-type foo() :: #foo{}.\r\n+\r\n...\r\n```\r\nPut this record and type definition somewhere in your files.\r\nNow, you need to register your submodule (`foo`) during startup. This should look something like this:\r\n```erlang\r\n-module(mod_foo).\r\n...\r\nstart(Blah, ...) ->\r\n    ...\r\n    xmpp:register_codec(foo),\r\n    ...\r\n```\r\nNote, that you need to call `xmpp:register_codec/1` again, if you have your submodule (`foo`) recompiled and reloaded in runtime.\r\nAlso, you may want to unregister the submodule during shutdown procedure, although, strictly speaking, this is not required:\r\n```erlang\r\nstop(...) ->\r\n    xmpp:unregister_codec(foo)\r\n```\r\nNow you have everything done to use your new \"subcodec\".\r\nHave fun ;)"},"comment":{"url":"https://api.github.com/repos/processone/xmpp/issues/comments/363209415","html_url":"https://github.com/processone/xmpp/issues/9#issuecomment-363209415","issue_url":"https://api.github.com/repos/processone/xmpp/issues/9","id":363209415,"user":{"login":"ltAldoRaine","id":17614392,"avatar_url":"https://avatars3.githubusercontent.com/u/17614392?v=4","gravatar_id":"","url":"https://api.github.com/users/ltAldoRaine","html_url":"https://github.com/ltAldoRaine","followers_url":"https://api.github.com/users/ltAldoRaine/followers","following_url":"https://api.github.com/users/ltAldoRaine/following{/other_user}","gists_url":"https://api.github.com/users/ltAldoRaine/gists{/gist_id}","starred_url":"https://api.github.com/users/ltAldoRaine/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ltAldoRaine/subscriptions","organizations_url":"https://api.github.com/users/ltAldoRaine/orgs","repos_url":"https://api.github.com/users/ltAldoRaine/repos","events_url":"https://api.github.com/users/ltAldoRaine/events{/privacy}","received_events_url":"https://api.github.com/users/ltAldoRaine/received_events","type":"User","site_admin":false},"created_at":"2018-02-05T20:21:44Z","updated_at":"2018-02-05T20:21:44Z","author_association":"NONE","body":"<iq type=“get”><query xmlns=“jabber:iq:conversation”><start>0</start><limit>10</limit></query></iq> \r\n\r\nI did everything as you described. after restarting ejabberd there was error which was throwed by xmpp:register_codec()\r\n\r\n\r\n7:47:40.261 [critical] Problem starting the module mod_conversation for host dev.mp.ge\r\n options: []\r\n error: undef\r\n[{conversation,module_info,[md5],[]},\r\n {xmpp_codec,register_module,2,[{file,\"src/xmpp_codec.erl\"},{line,121}]},\r\n {mod_conversation,start,2,[{file,\"src/mod_conversation.erl\"},{line,42}]},\r\n {gen_mod,start_module,4,[{file,\"src/gen_mod.erl\"},{line,200}]},\r\n {lists,foreach,2,[{file,\"lists.erl\"},{line,1338}]},\r\n {gen_mod,start_link,0,[{file,\"src/gen_mod.erl\"},{line,79}]},\r\n {supervisor,do_start_child,2,[{file,\"supervisor.erl\"},{line,365}]},\r\n {supervisor,start_children,3,[{file,\"supervisor.erl\"},{line,348}]}]\r\n17:47:40.261 [critical] ejabberd initialization was aborted because a module start failed.\r\nProblem starting the module mod_conversation for host dev.mp.ge\r\n options: []\r\n error: undef\r\n[{conversation,module_info,[md5],[]},\r\n {xmpp_codec,register_module,2,[{file,\"src/xmpp_codec.erl\"},{line,121\r\n\r\nCrash dump is being written to: /usr/local/var/log/ejabberd/erl_crash_20180205-174736.dump...done\r\n[os_mon] memory supervisor port (memsup): Erlang has closed\r\n"}}
{"actor":{"display_login":"ltAldoRaine"}}