From: Ralf Haferkamp Date: Mon, 3 Jul 2006 16:31:27 +0000 (+0000) Subject: example code for the LDAPUrl Class X-Git-Tag: OPENLDAP_REL_ENG_2_4_3ALPHA~9^2~64 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=2d2ad0e314eb70c59a099ea9620161988fb075c5;p=openldap example code for the LDAPUrl Class --- diff --git a/contrib/ldapc++/examples/Makefile.am b/contrib/ldapc++/examples/Makefile.am index 3ce2798935..bf46194225 100644 --- a/contrib/ldapc++/examples/Makefile.am +++ b/contrib/ldapc++/examples/Makefile.am @@ -2,10 +2,13 @@ # Copyright 2003, OpenLDAP Foundation, All Rights Reserved. # COPYING RESTRICTIONS APPLY, see COPYRIGHT file ## -noinst_PROGRAMS = main readSchema +noinst_PROGRAMS = main readSchema urlTest main_SOURCES = main.cpp main_LDADD = ../src/libldapcpp.la readSchema_SOURCES = readSchema.cpp readSchema_LDADD = ../src/libldapcpp.la + +urlTest_SOURCES = urlTest.cpp +urlTest_LDADD = ../src/libldapcpp.la diff --git a/contrib/ldapc++/examples/Makefile.in b/contrib/ldapc++/examples/Makefile.in index f9ce63e775..8685a81367 100644 --- a/contrib/ldapc++/examples/Makefile.in +++ b/contrib/ldapc++/examples/Makefile.in @@ -36,7 +36,7 @@ PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ -noinst_PROGRAMS = main$(EXEEXT) readSchema$(EXEEXT) +noinst_PROGRAMS = main$(EXEEXT) readSchema$(EXEEXT) urlTest$(EXEEXT) subdir = examples DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 @@ -53,6 +53,9 @@ main_DEPENDENCIES = ../src/libldapcpp.la am_readSchema_OBJECTS = readSchema.$(OBJEXT) readSchema_OBJECTS = $(am_readSchema_OBJECTS) readSchema_DEPENDENCIES = ../src/libldapcpp.la +am_urlTest_OBJECTS = urlTest.$(OBJEXT) +urlTest_OBJECTS = $(am_urlTest_OBJECTS) +urlTest_DEPENDENCIES = ../src/libldapcpp.la DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)/src depcomp = $(SHELL) $(top_srcdir)/depcomp am__depfiles_maybe = depfiles @@ -64,8 +67,9 @@ LTCXXCOMPILE = $(LIBTOOL) --tag=CXX --mode=compile $(CXX) $(DEFS) \ CXXLD = $(CXX) CXXLINK = $(LIBTOOL) --tag=CXX --mode=link $(CXXLD) $(AM_CXXFLAGS) \ $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ -SOURCES = $(main_SOURCES) $(readSchema_SOURCES) -DIST_SOURCES = $(main_SOURCES) $(readSchema_SOURCES) +SOURCES = $(main_SOURCES) $(readSchema_SOURCES) $(urlTest_SOURCES) +DIST_SOURCES = $(main_SOURCES) $(readSchema_SOURCES) \ + $(urlTest_SOURCES) ETAGS = etags CTAGS = ctags DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) @@ -169,6 +173,8 @@ main_SOURCES = main.cpp main_LDADD = ../src/libldapcpp.la readSchema_SOURCES = readSchema.cpp readSchema_LDADD = ../src/libldapcpp.la +urlTest_SOURCES = urlTest.cpp +urlTest_LDADD = ../src/libldapcpp.la all: all-am .SUFFIXES: @@ -215,6 +221,9 @@ main$(EXEEXT): $(main_OBJECTS) $(main_DEPENDENCIES) readSchema$(EXEEXT): $(readSchema_OBJECTS) $(readSchema_DEPENDENCIES) @rm -f readSchema$(EXEEXT) $(CXXLINK) $(readSchema_LDFLAGS) $(readSchema_OBJECTS) $(readSchema_LDADD) $(LIBS) +urlTest$(EXEEXT): $(urlTest_OBJECTS) $(urlTest_DEPENDENCIES) + @rm -f urlTest$(EXEEXT) + $(CXXLINK) $(urlTest_LDFLAGS) $(urlTest_OBJECTS) $(urlTest_LDADD) $(LIBS) mostlyclean-compile: -rm -f *.$(OBJEXT) @@ -224,6 +233,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/readSchema.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/urlTest.Po@am__quote@ .cpp.o: @am__fastdepCXX_TRUE@ if $(CXXCOMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \ diff --git a/contrib/ldapc++/examples/urlTest.cpp b/contrib/ldapc++/examples/urlTest.cpp new file mode 100644 index 0000000000..e1ab2a0dae --- /dev/null +++ b/contrib/ldapc++/examples/urlTest.cpp @@ -0,0 +1,34 @@ +#include +#include +#include + +int main(int argc, char *argv[]) { + if ( argc != 2 ) { + std::cout << argc << std::endl; + std::cout << "urlTest " << std::endl; + exit(1); + } + std::string uristr = argv[1]; + try { + LDAPUrl url(uristr); + std::cout << "Host: " << url.getHost() << std::endl; + std::cout << "Port: " << url.getPort() << std::endl; + std::cout << "BaseDN: " << url.getDN() << std::endl; + std::cout << "Scope: " << url.getScope() << std::endl; + StringList attrs = url.getAttrs(); + std::cout << "Attrs: " << std::endl; + StringList::const_iterator i = attrs.begin(); + for( ; i != attrs.end(); i++ ) { + std::cout << " " << *i << std::endl; + } + std::cout << "Filter: " << url.getFilter() << std::endl; + std::cout << "Setting new BaseDN" << std::endl; + url.setDN("o=Beispiel, c=DE"); + std::cout << "Url: " << url.getURLString() << std::endl; + } catch (LDAPUrlException e) { + std::cout << e.getCode() << std::endl; + std::cout << e.getErrorMessage() << std::endl; + std::cout << e.getAdditionalInfo() << std::endl; + } + +}