2 * Copyright (c) 1990 Regents of the University of Michigan.
5 * Redistribution and use in source and binary forms are permitted
6 * provided that this notice is preserved and that due credit is given
7 * to the University of Michigan at Ann Arbor. The name of the University
8 * may not be used to endorse or promote products derived from this
9 * software without specific prior written permission. This software
10 * is provided ``as is'' without express or implied warranty.
17 #include <ac/socket.h>
18 #include <ac/string.h>
20 #include <quipu/commonarg.h>
21 #include <quipu/ds_error.h>
27 static struct msg *messages;
35 struct sockaddr *clientaddr
39 static int uniqid = 0;
41 /* make a new message */
42 if ( (new = (struct msg *) malloc( sizeof(struct msg) )) == NULL ) {
43 Debug( LDAP_DEBUG_ANY, "addmsg: malloc failed\n", 0, 0, 0 );
47 new->m_uniqid = ++uniqid;
48 new->m_msgtype = msgtype;
51 new->m_conn = dsaconn;
52 new->m_conn->c_refcnt++;
55 #ifdef LDAP_CONNECTIONLESS
57 new->m_searchbase = NULLDN;
60 new->m_clientaddr = *clientaddr;
61 Debug( LDAP_DEBUG_TRACE, "udp message from %s port %d\n",
62 inet_ntoa( ((struct sockaddr_in *)clientaddr)->sin_addr ),
63 ((struct sockaddr_in *)clientaddr)->sin_port, 0 );
67 /* add it to the front of the queue */
68 new->m_next = messages;
74 struct msg *get_msg( int uniqid )
78 for ( tmp = messages; tmp != NULL; tmp = tmp->m_next ) {
79 if ( tmp->m_uniqid == uniqid )
87 del_msg( struct msg *m )
89 struct msg *cur, *prev;
92 for ( cur = messages; cur != NULL; cur = cur->m_next ) {
99 Debug( LDAP_DEBUG_ANY, "delmsg: cannot find msg %lx\n",
100 (unsigned long) m, 0, 0 );
104 if ( prev == NULL ) {
105 messages = cur->m_next;
107 prev->m_next = cur->m_next;
109 conn_free( cur->m_conn );
110 modlist_free( cur->m_mods );
111 ber_free( cur->m_ber, 1 );
112 #ifdef LDAP_CONNECTIONLESS
113 if ( cur->m_searchbase != NULLDN ) {
114 dn_free( cur->m_searchbase );
116 #endif /* LDAP_CONNECTIONLESS */
117 free( (char *) cur );
123 * send_msg - Send a messge in response to every outstanding request on
124 * a given connection. This is used, for example, when an association to
125 * a dsa fails. It deletes messages to which it responds.
136 struct msg *tmp, *next;
139 for ( tmp = messages; tmp != NULL; tmp = next ) {
142 if ( tmp->m_conn == conn ) {
143 send_ldap_msgresult( clientsb, tmp->m_msgtype, tmp,
152 #ifdef LDAP_CONNECTIONLESS
157 struct sockaddr *fromaddr
162 for ( tmp = messages; tmp != NULL; tmp = tmp->m_next ) {
163 if ( tmp->m_cldap && tmp->m_msgid == msgid &&
164 tmp->m_msgtype == msgtype &&
165 ((struct sockaddr_in *)&tmp->m_clientaddr)->sin_port ==
166 ((struct sockaddr_in *)fromaddr)->sin_port &&
167 ((struct sockaddr_in *)&tmp->m_clientaddr)->sin_addr.s_addr
168 == ((struct sockaddr_in *)fromaddr)->sin_addr.s_addr ) {
175 #endif /* LDAP_CONNECTIONLESS */