7 * Copyright (c) 1998-2003 Carnegie Mellon University. All rights reserved.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in
18 * the documentation and/or other materials provided with the
21 * 3. The name "Carnegie Mellon University" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For permission or any other legal
24 * details, please contact
25 * Office of Technology Transfer
26 * Carnegie Mellon University
28 * Pittsburgh, PA 15213-3890
29 * (412) 268-4387, fax: (412) 268-7395
30 * tech-transfer@andrew.cmu.edu
32 * 4. Redistributions of any form whatsoever must retain the following
34 * "This product includes software developed by Computing Services
35 * at Carnegie Mellon University (http://www.cmu.edu/computing/)."
37 * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
38 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
39 * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
40 * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
41 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
42 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
43 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
47 /* sf discipline to add sasl
50 typedef struct _sasldisc
56 ssize_t sasl_read(Sfio_t *f, Void_t *buf, size_t size, Sfdisc_t *disc)
61 Sasldisc_t *sd = (Sasldisc_t *) disc;
63 len = sfrd(f, buf, size, disc);
68 result = sasl_decode(sd->conn, buf, len, &outbuf, &outlen);
70 if (result != SASL_OK) {
71 /* eventually, we'll want an exception here */
76 memcpy(buf, outbuf, outlen);
82 ssize_t sasl_write(Sfio_t *f, const Void_t *buf, size_t size, Sfdisc_t *disc)
87 Sasldisc_t *sd = (Sasldisc_t *) disc;
89 result = sasl_encode(sd->conn, buf, size, &outbuf, &outlen);
91 if (result != SASL_OK) {
96 sfwr(f, outbuf, outlen, disc);
102 int sfdcsasl(Sfio_t *f, sasl_conn_t *conn)
107 /* no need to do anything */
111 if(!(sasl = (Sasldisc_t*)malloc(sizeof(Sasldisc_t))) )
114 sasl->disc.readf = sasl_read;
115 sasl->disc.writef = sasl_write;
116 sasl->disc.seekf = NULL;
117 sasl->disc.exceptf = NULL;
121 if (sfdisc(f, (Sfdisc_t *) sasl) != (Sfdisc_t *) sasl) {