]> git.sur5r.net Git - openldap/blob - contrib/ldapc++/src/LDAPUrl.cpp
Initial check of the LDAP C++ SDK written by Ralf Haferkamp <rhafer@suse.de>
[openldap] / contrib / ldapc++ / src / LDAPUrl.cpp
1 /*
2  * Copyright 2000, OpenLDAP Foundation, All Rights Reserved.
3  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
4  */
5
6 // $Id: LDAPUrl.cpp,v 1.6 2000/08/31 17:43:49 rhafer Exp $
7
8 #include "LDAPUrl.h"
9 #include <ldap.h>
10 #include <ac/string.h>
11 #include "debug.h"
12
13 LDAPUrl::LDAPUrl(char *url){
14     DEBUG(LDAP_DEBUG_TRACE, "LDAPUrl::LDAPUrl()" << endl);
15     if (ldap_is_ldap_url(url)){
16         m_urlString = strdup(url);
17         ldap_url_parse(url, &m_urlDesc);
18     }else{
19         DEBUG(LDAP_DEBUG_TRACE,"   noUrl:" << url << endl);
20     }
21 }
22
23 LDAPUrl::LDAPUrl(char *host, int port, char *dn, char **attrs, int scope,
24         char *filter){
25     
26 }
27
28 LDAPUrl::~LDAPUrl(){
29     delete[] m_urlString;
30     ldap_free_urldesc(m_urlDesc);
31 }
32
33 int LDAPUrl::getPort() const {
34     return m_urlDesc->lud_port;
35 }
36
37 int LDAPUrl::getScope() const {
38     return m_urlDesc->lud_scope;
39 }
40
41 char* LDAPUrl::getURLString() const {
42     return strdup(m_urlString);
43 }
44
45 char* LDAPUrl::getHost() const {
46     return strdup(m_urlDesc->lud_host);
47 }
48
49 char* LDAPUrl::getDN() const {
50     return strdup(m_urlDesc->lud_dn);
51 }
52
53 char* LDAPUrl::getFilter() const {
54     return strdup(m_urlDesc->lud_filter);
55 }
56
57 char** LDAPUrl::getAttrs() const {
58     size_t s;
59     for ( char** i=m_urlDesc->lud_attrs; *i != 0; i++){
60         s++;
61     }
62     char** ret=new char*[s+1];
63     ret[s]=0;
64     int j=0;
65     for (char** i=m_urlDesc->lud_attrs; *i != 0; j++, i++){
66         ret[j] = strdup(*i);
67     }
68     return ret;
69 }
70