Some Very Basic Questions about urls and Sockets
Posted: Tue Jun 15, 2010 4:20 pm
I am still working through how to best query LDAP in this little application I am trying to write,
It looks like using LDAP URLS, which my server supports, is the easiest way to do it - I don't have to write a full ldap client that way.
What I am not sure about is how, exactly, I should be sending those urls to the server so it will accept them. I have looked through various RFCs, but it almost seems like I am missing something so basic they they don't even talk about it...
Here is what I have so far:
I open the socket to the server, and send the url ldap://directory.xxxxx.com/ou=people,o=xxxxx,c=us??sub?(uid=1234567) to the the server, then read the socket. Since I wasn't sure if read Socket accepted "until eof", I figured I would just try reading a 1000 chars and see what I got. What I get is eof in the result, nothing in "it", and the socket is closed, I assume by the server since I am annoying it with junk requests.
I am assuming that what I am doing wrong is something basic - like I am not supposed to send the entire url, or I am not supposed to urlencode all of it, or it's supposed to be binary encoded for sending or something. I have tried several variations, but none of them seem to work.
I have tested the url I am sending using explorer and firefox, and which return the expected data. According according to the RFC it's html text, though it looks like the mimetype is set the vcard, since it opens in Windows address book. Names x'ed out to protect my employer.
At first I thought that maybe the processing of the URL had to be done on the client end and parsed into standard LDAP requests, but the documentation for the LDAP server we are using clearly states that it accepts LDAP URLS and returns HTML text.
Here is the script that I am currently trying - it's basic and needs work - I am just trying to get something to work first - but I figured it might be useful to see
This is the stack script - I send the messages openLdapSocket, sendLdapRequest and LdapDisconnect using buttons on the stack's only card.
As always, any help is much appreciated.
It looks like using LDAP URLS, which my server supports, is the easiest way to do it - I don't have to write a full ldap client that way.
What I am not sure about is how, exactly, I should be sending those urls to the server so it will accept them. I have looked through various RFCs, but it almost seems like I am missing something so basic they they don't even talk about it...
Here is what I have so far:
I open the socket to the server, and send the url ldap://directory.xxxxx.com/ou=people,o=xxxxx,c=us??sub?(uid=1234567) to the the server, then read the socket. Since I wasn't sure if read Socket accepted "until eof", I figured I would just try reading a 1000 chars and see what I got. What I get is eof in the result, nothing in "it", and the socket is closed, I assume by the server since I am annoying it with junk requests.
I am assuming that what I am doing wrong is something basic - like I am not supposed to send the entire url, or I am not supposed to urlencode all of it, or it's supposed to be binary encoded for sending or something. I have tried several variations, but none of them seem to work.
I have tested the url I am sending using explorer and firefox, and which return the expected data. According according to the RFC it's html text, though it looks like the mimetype is set the vcard, since it opens in Windows address book. Names x'ed out to protect my employer.
At first I thought that maybe the processing of the URL had to be done on the client end and parsed into standard LDAP requests, but the documentation for the LDAP server we are using clearly states that it accepts LDAP URLS and returns HTML text.
Here is the script that I am currently trying - it's basic and needs work - I am just trying to get something to work first - but I figured it might be useful to see
This is the stack script - I send the messages openLdapSocket, sendLdapRequest and LdapDisconnect using buttons on the stack's only card.
Code: Select all
local lLDAPsocket
on openLdapSocket
put "directory.xxxxx.com:389" &"|LDAP" into lLDAPsocket
open socket to lLDAPsocket with message "ldapConnected"
end openldapsocket
on socketTimeout theID
answer error "The connnection is not responding." with "Keep Trying" or "Cancel"
if it is "Cancel" then close socket theID
end socketTimeout
on LdapDisconnect
close socket lLDAPsocket
disable the target
enable button "connectLDAP"
set the visible of field "connected2LDAP" to false
put empty into lLDAPsocket
end LdapDisconnect
on sendLdapRequest
put "ldap://directory.xxxxx.com/ou=people,o=xxxxx,c=us??sub?(uid=1234567)" into theLdapRequest
put urlencode(theLdapRequest) into theLdapRequest
write theLdapRequest to socket lLDAPsocket with message "LDAPresponse"
put the result
end sendLDAPRequest
on ldapConnected
--this just provides feedback that the connection succeeds
if the opensockets contains lLDAPsocket then
set the visible of field "connected2LDAP" to true
disable button "connectLdap"
enable button "disconnectLdap"
end if
end ldapConnected
on LDAPresponse
read from socket lLDAPsocket for 1000 chars
put the result
put it into field "LDAPResponse"
end LDAPresponse