Hi there, I'm new to erlang and ejabberd, checking it out to see if it'll fit my purposes.
At the moment, I'm essentially trying to implement a custom roster module based on the original. Essentially, I want to add my own attributes to a roster item that I can read and write via XML. For example, the typical roster items include jid, name, subscription, etc. I'm trying to add a few more items that each contact in a roster can have. My first step was simply to add the item I wanted to the "roster" record in mod_roster.hrl, e.g:
-record(roster, {usj,
us,
jid,
name = "",
subscription = none,
some_custom_item,
ask = none,
groups = [],
askmessage = [],
xs = []}).
Though when I try to run it, I get error messages about bad records, essentially:
=ERROR REPORT==== 2010-03-05 17:22:30 ===
E(<0.352.0>:ejabberd_hooks:335) : {{badrecord,roster},
[{mod_shared_roster,
'-get_user_roster/2-fun-2-',2},
{lists,mapfoldl,3},
{mod_shared_roster,get_user_roster,2},
{ejabberd_hooks,run_fold1,4},
{mod_roster,process_iq_get,3},
{gen_iq_handler,process_iq,6},
{gen_iq_handler,handle_info,2},
{gen_server,handle_msg,5}]}
running hook: {roster_get,[{"someuser","localhost"}]}
which doesn't really tell me a whole lot. I'd thought there might be a conflict since records in that table won't have the item, so I cleared the database all together (actually by erasing the install directory and rebuilding, if anyone knows a better way to reset the database I'm all ears), hoping it would create the table with my own record intact, but I still get the message.
If you have any ideas on how I can implement this I'd love to hear them!
Thanks.
The 'roster' record is used
The 'roster' record is used by several modules. When you modify the record definition, better you run "make clean; make" to ensure all the files are recompiled.
Alternatively, maybe you can include your extended elements in the 'xs' field of the 'roster' record, which means you don't need to change the record definition, only to fill that field with your desired data.
No Luck
Hey,
That was a good idea, especially after I noticed the error pops up in mod_shared_roster as well, unfortunately no luck. I'm still getting the same error message about bad records even after a total rebuild.
It seems to be having a problem with fill_subscription_lists, specifically at the line "J = element(3, I#roster.usj)". If I understand my erlang (which I may not), this should just be assigning J the 3rd element of the tuple usj in I which is a roster. I don't see how adding an element to the roster would effect that.
The other places it complains about bad elements seems to be in "mod_shared_roster/get_user_roster" and "get_in_pending_subscriptions", which do indeed do some alternations to roster records but nothing popping out at me that would cause an issue.
Anything other suggestions, please let me know. I'll keep investigating in the meantime, and might try changing the xs field as you suggested. Thanks.
I isn't a valid roster record
the line "J = element(3, I#roster.usj)". If I understand my erlang (which I may not), this should just be assigning J the 3rd element of the tuple usj in I which is a roster. I don't see how adding an element to the roster would effect that.
That line:
1. checks if I is a 'roster' valid record as defined in the module binary
2. gets the element 'usj' of the record
3. as usj is a tuple with three elements, then it gets the third element (the JID)
If that line generates the error {badrecord,roster}, it means I isn't a valid 'roster' record. Maybe it is a string, or an atom, or an invalid 'roster' record (generated by a module that has a different definition of the record).
Oh I see
Ah, yes that makes sense. The record isn't going to be a valid roster record since I changed the definition of the type so the record it was loading from the roster table didn't match. Turns out what I was trying before (recreating the DB and make clean) was individually insufficient, I had to do both a full rebuild with make clean and recreate the database, and now I've got a new column in the roster table I can change! Neat, though I still have a ways to go.
I noticed that using xs, it tries to append the element as a whole new XML tag. Maybe I should have been more clear before, I'm actually trying to add some attributes to an item tag, e.g. <item jid="bla" myattrib="nifty">...etc. I'm not sure if xs will work for that seems it to want a new element altogether.
I'm hoping using a custom element in the "roster" record, and experimenting with item_to_xml will help, but I'll be posting back here if I run into more issues.
Thanks for your help!
Did you ever complete your
Did you ever complete your custom mod_roster? I'm also making a similar change currently and need to add an attribute to the roster item as well as add an attribute to the that the items are within. I'm hoping to not have to make a copy of mod_roster but it looks like the only choice.
Thanks.