3 * Copyright (c) 1990 Regents of the University of Michigan.
6 * Redistribution and use in source and binary forms are permitted
7 * provided that this notice is preserved and that due credit is given
8 * to the University of Michigan at Ann Arbor. The name of the University
9 * may not be used to endorse or promote products derived from this
10 * software without specific prior written permission. This software
11 * is provided ``as is'' without express or implied warranty.
18 #include <ac/socket.h>
19 #include <ac/string.h>
21 #include <quipu/commonarg.h>
22 #include <quipu/ds_error.h>
28 static struct msg *messages;
36 struct sockaddr *clientaddr
40 static int uniqid = 0;
42 /* make a new message */
43 if ( (new = (struct msg *) malloc( sizeof(struct msg) )) == NULL ) {
44 Debug( LDAP_DEBUG_ANY, "addmsg: malloc failed\n", 0, 0, 0 );
48 new->m_uniqid = ++uniqid;
49 new->m_msgtype = msgtype;
52 new->m_conn = dsaconn;
53 new->m_conn->c_refcnt++;
56 #ifdef LDAP_CONNECTIONLESS
58 new->m_searchbase = NULLDN;
61 new->m_clientaddr = *clientaddr;
62 Debug( LDAP_DEBUG_TRACE, "udp message from %s port %d\n",
63 inet_ntoa( ((struct sockaddr_in *)clientaddr)->sin_addr ),
64 ((struct sockaddr_in *)clientaddr)->sin_port, 0 );
68 /* add it to the front of the queue */
69 new->m_next = messages;
75 struct msg *get_msg( int uniqid )
79 for ( tmp = messages; tmp != NULL; tmp = tmp->m_next ) {
80 if ( tmp->m_uniqid == uniqid )
88 del_msg( struct msg *m )
90 struct msg *cur, *prev;
93 for ( cur = messages; cur != NULL; cur = cur->m_next ) {
100 Debug( LDAP_DEBUG_ANY, "delmsg: cannot find msg %lx\n",
101 (unsigned long) m, 0, 0 );
105 if ( prev == NULL ) {
106 messages = cur->m_next;
108 prev->m_next = cur->m_next;
110 conn_free( cur->m_conn );
111 modlist_free( cur->m_mods );
112 ber_free( cur->m_ber, 1 );
113 #ifdef LDAP_CONNECTIONLESS
114 if ( cur->m_searchbase != NULLDN ) {
115 dn_free( cur->m_searchbase );
117 #endif /* LDAP_CONNECTIONLESS */
118 free( (char *) cur );
124 * send_msg - Send a messge in response to every outstanding request on
125 * a given connection. This is used, for example, when an association to
126 * a dsa fails. It deletes messages to which it responds.
137 struct msg *tmp, *next;
140 for ( tmp = messages; tmp != NULL; tmp = next ) {
143 if ( tmp->m_conn == conn ) {
144 send_ldap_msgresult( clientsb, tmp->m_msgtype, tmp,
153 #ifdef LDAP_CONNECTIONLESS
158 struct sockaddr *fromaddr
163 for ( tmp = messages; tmp != NULL; tmp = tmp->m_next ) {
164 if ( tmp->m_cldap && tmp->m_msgid == msgid &&
165 tmp->m_msgtype == msgtype &&
166 ((struct sockaddr_in *)&tmp->m_clientaddr)->sin_port ==
167 ((struct sockaddr_in *)fromaddr)->sin_port &&
168 ((struct sockaddr_in *)&tmp->m_clientaddr)->sin_addr.s_addr
169 == ((struct sockaddr_in *)fromaddr)->sin_addr.s_addr ) {
176 #endif /* LDAP_CONNECTIONLESS */