Discussion:
[erlang-questions] eldap:search result
unknown
2014-01-12 19:41:59 UTC
Permalink
Hi list

I am experimenting with eldap, but i am wondering on how to correctly get
the result from an ldap search?

In my module, i am doing an eldap:search

-----------------
{ok, Result} = eldap:search(S, Search),
eldap:close(S),
io:format("Search Result: ~p~n", [Result]).
-----------------

And i am getting following:

-----------------
Search Result: {eldap_search_result,
[{eldap_entry,
"blaa,blaaa,blaa,blaa,blaa",
[{"status",["available"]}]}],
[]}
ok
-----------------

So far so good, eldap is doing it's work, but what i am really interrested
in is just the content of the attribute status which is "available". How
can i get the status into an variable? Do i need to get it from an record,
or ?

Thomas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20140112/929c9fdb/attachment.html>
unknown
2014-01-12 20:50:22 UTC
Permalink
I offer this approach:

{ok, Result} = eldap:search(S, Search),
eldap:close(S),
{eldap_search_result, [{_, _, [{"status", [Status]}]}], []} = Result,

& at this point, Status =:= "available", if I have successfully
balanced the brackets and braces. You may wish also to match 'eldap_entry'
in your assignment.

Regards,
John R. Ashmun


On Sun, Jan 12, 2014 at 11:41 AM, Thomas Elsgaard <thomas.elsgaard
Post by unknown
Hi list
I am experimenting with eldap, but i am wondering on how to correctly get
the result from an ldap search?
In my module, i am doing an eldap:search
-----------------
{ok, Result} = eldap:search(S, Search),
eldap:close(S),
io:format("Search Result: ~p~n", [Result]).
-----------------
-----------------
Search Result: {eldap_search_result,
[{eldap_entry,
"blaa,blaaa,blaa,blaa,blaa",
[{"status",["available"]}]}],
[]}
ok
-----------------
So far so good, eldap is doing it's work, but what i am really interrested
in is just the content of the attribute status which is "available". How
can i get the status into an variable? Do i need to get it from an record,
or ?
Thomas
_______________________________________________
erlang-questions mailing list
erlang-questions
http://erlang.org/mailman/listinfo/erlang-questions
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20140112/3ed9f474/attachment.html>
unknown
2014-01-12 22:55:31 UTC
Permalink
Hi Thomas,

In this case you should include eldap's hrl file to and use records to pattern match the results.
Matching records as tuples is considered a bad practice.
http://www.erlang.se/doc/programming_rules.shtml#HDR23

I suggest you start with:

-include_lib("eldap/include/eldap.hrl").

Note that you'll be dealing with a _list_ of entries.
lists:map/2 (or list comprehension) can come in handy for further processing.

Cheers,
/A.
Post by unknown
{ok, Result} = eldap:search(S, Search),
eldap:close(S),
{eldap_search_result, [{_, _, [{"status", [Status]}]}], []} = Result,
& at this point, Status =:= "available", if I have successfully balanced the brackets and braces. You may wish also to match 'eldap_entry' in your assignment.
Regards,
John R. Ashmun
Hi list
I am experimenting with eldap, but i am wondering on how to correctly get the result from an ldap search?
In my module, i am doing an eldap:search
-----------------
{ok, Result} = eldap:search(S, Search),
eldap:close(S),
io:format("Search Result: ~p~n", [Result]).
-----------------
-----------------
Search Result: {eldap_search_result,
[{eldap_entry,
"blaa,blaaa,blaa,blaa,blaa",
[{"status",["available"]}]}],
[]}
ok
-----------------
So far so good, eldap is doing it's work, but what i am really interrested in is just the content of the attribute status which is "available". How can i get the status into an variable? Do i need to get it from an record, or ?
Thomas
_______________________________________________
erlang-questions mailing list
erlang-questions
http://erlang.org/mailman/listinfo/erlang-questions
_______________________________________________
erlang-questions mailing list
erlang-questions
http://erlang.org/mailman/listinfo/erlang-questions
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20140112/bed668d5/attachment.html>
Loading...