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.
15 #include <sys/types.h>
16 #include <sys/socket.h>
17 #include <netinet/in.h>
18 #include <quipu/commonarg.h>
19 #include <quipu/ds_error.h>
24 static struct msg *messages;
32 struct sockaddr *clientaddr
36 static int uniqid = 0;
38 /* make a new message */
39 if ( (new = (struct msg *) malloc( sizeof(struct msg) )) == NULL ) {
40 Debug( LDAP_DEBUG_ANY, "addmsg: malloc failed\n", 0, 0, 0 );
44 new->m_uniqid = ++uniqid;
45 new->m_msgtype = msgtype;
48 new->m_conn = dsaconn;
49 new->m_conn->c_refcnt++;
54 new->m_searchbase = NULLDN;
57 new->m_clientaddr = *clientaddr;
58 Debug( LDAP_DEBUG_TRACE, "udp message from %s port %d\n",
59 inet_ntoa( ((struct sockaddr_in *)clientaddr)->sin_addr ),
60 ((struct sockaddr_in *)clientaddr)->sin_port, 0 );
64 /* add it to the front of the queue */
65 new->m_next = messages;
71 struct msg *get_msg( int uniqid )
75 for ( tmp = messages; tmp != NULL; tmp = tmp->m_next ) {
76 if ( tmp->m_uniqid == uniqid )
84 del_msg( struct msg *m )
86 struct msg *cur, *prev;
89 for ( cur = messages; cur != NULL; cur = cur->m_next ) {
96 Debug( LDAP_DEBUG_ANY, "delmsg: cannot find msg %x\n", m,
101 if ( prev == NULL ) {
102 messages = cur->m_next;
104 prev->m_next = cur->m_next;
106 conn_free( cur->m_conn );
107 modlist_free( cur->m_mods );
108 ber_free( cur->m_ber, 1 );
110 if ( cur->m_searchbase != NULLDN ) {
111 dn_free( cur->m_searchbase );
114 free( (char *) cur );
120 * send_msg - Send a messge in response to every outstanding request on
121 * a given connection. This is used, for example, when an association to
122 * a dsa fails. It deletes messages to which it responds.
133 struct msg *tmp, *next;
136 for ( tmp = messages; tmp != NULL; tmp = next ) {
139 if ( tmp->m_conn == conn ) {
140 send_ldap_msgresult( clientsb, tmp->m_msgtype, tmp,
154 struct sockaddr *fromaddr
159 for ( tmp = messages; tmp != NULL; tmp = tmp->m_next ) {
160 if ( tmp->m_cldap && tmp->m_msgid == msgid &&
161 tmp->m_msgtype == msgtype &&
162 ((struct sockaddr_in *)&tmp->m_clientaddr)->sin_port ==
163 ((struct sockaddr_in *)fromaddr)->sin_port &&
164 ((struct sockaddr_in *)&tmp->m_clientaddr)->sin_addr.s_addr
165 == ((struct sockaddr_in *)fromaddr)->sin_addr.s_addr ) {