LDAP_FIRST_MESSAGE(3)
π LDAP_FIRST_MESSAGE(3) β like, the whole manual page, bestie
okay so this is a page from the Library Functions Manual for LDAP_FIRST_MESSAGE(3), and it lives in libldap (-lldap) from OpenLDAP. sit down, grab a strawberry drink π, and let's talk about stepping through messages in a result chain, because honestly it's giving "walk the linked list" and it's iconic.
β¨ NAME β¨
ldap_first_message, ldap_next_message, ldap_count_messages β stepping through messages in a result chain π¦
π LIBRARY π
OpenLDAP LDAP (libldap, -lldap)
πΈ SYNOPSIS πΈ
#include <ldap.h>
int ldap_count_messages( LDAP *ld, LDAPMessage *result )
LDAPMessage *ldap_first_message( LDAP *ld, LDAPMessage *result )
LDAPMessage *ldap_next_message( LDAP *ld, LDAPMessage *message )
π DESCRIPTION π
so these routines are the ones you use to step through the messages in a result chain that you got back from ldap_result(3). for search operations, that result chain can contain referral, entry and result messages β like a lil mixed bag π. and if you need to tell which one is which, the ldap_msgtype(3) function is literally right there for exactly that.
ldap_first_message()β this one grabs the first message in a result chain. you feed it the result you got back from a call toldap_result(3),ldap_search_s(3)orldap_search_st(3), and it hands you back a pointer to the first message in the chain. main character energy, it goes first πldap_next_message()β you take that pointer and supply it on a subsequent call toldap_next_message()to get the next message. then that result gets supplied to the next call toldap_next_message(), and so on, and so on, forever and ever (jk, see next point). the way it just keeps going π- and when there are no more messages?
ldap_next_message()returnsNULL. that's your signal that the chain is done, no cap π.
these functions are genuinely useful when you're using routines like ldap_parse_result(3) that only operate on the first result in the chain β because sometimes you need to get past that first one, bestie.
want a count of the number of messages in the result chain? just call ldap_count_messages(). and here's the cute part: it can also be used to count the number of remaining messages in a chain β if you call it with a message, entry or reference returned by any of these:
ldap_first_message()ldap_next_message()ldap_first_entry(3)ldap_next_entry(3)ldap_first_reference(3)ldap_next_reference(3)
so yeah. it counts. it's flexible. we stan π«Ά
π ERRORS π
if an error happens inldap_first_message()orldap_next_message(),NULLis returned. if an error happens inldap_count_messages(),-1is returned.
that's it, that's the error section. two return values. memorise them or perish (jk, but like, do memorise them) π
π SEE ALSO π
ldap(3), ldap_search(3), ldap_result(3), ldap_parse_result(3), ldap_first_entry(3), ldap_first_reference(3)
go read those too, iykyk π§
π ACKNOWLEDGEMENTS π
OpenLDAP Software is developed and maintained by The OpenLDAP Project <http://www.openldap.org/>. OpenLDAP Software is derived from the University of Michigan LDAP 3.3 Release.
and that's the whole page, bestie, every last crumb of it πβ¨ signing off β this was OpenLDAP 2.6.16, dated 2026/10/21, and honestly? slay π π
π¦ where this page comes from
- fedora 44: openldap-devel 2.6.16-1.fc44 Β· OLDAP-2.8
- fedora 44: openldap-devel 2.6.16-1.fc44 Β· OLDAP-2.8
- Copyright 1998-2026 The OpenLDAP Foundation All Rights Reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms