1 /* $Id: common.c,v 1.4 2003/02/13 19:56:06 rjs3 Exp $ */
3 * Copyright (c) 1998-2003 Carnegie Mellon University. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
17 * 3. The name "Carnegie Mellon University" must not be used to
18 * endorse or promote products derived from this software without
19 * prior written permission. For permission or any other legal
20 * details, please contact
21 * Office of Technology Transfer
22 * Carnegie Mellon University
24 * Pittsburgh, PA 15213-3890
25 * (412) 268-4387, fax: (412) 268-7395
26 * tech-transfer@andrew.cmu.edu
28 * 4. Redistributions of any form whatsoever must retain the following
30 * "This product includes software developed by Computing Services
31 * at Carnegie Mellon University (http://www.cmu.edu/computing/)."
33 * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
34 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
35 * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
36 * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
37 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
38 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
39 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
50 /* send/recv library for IMAP4 style literals.
52 really not important; just one way of doing length coded strings */
54 int send_string(FILE *f, const char *s, int l)
58 al = fprintf(f, "{%d}\r\n", l);
62 printf("send: {%d}\n", l);
64 if (isprint((unsigned char) *s)) {
67 printf("[%X]", (unsigned char) *s);
76 int recv_string(FILE *f, char *buf, int buflen)
83 if (c != '{') return -1;
89 len = len * 10 + (c - '0');
92 if (c != '}') return -1;
94 if (c != '\r') return -1;
96 if (c != '\n') return -1;
100 fread(buf, buflen - 1, 1, f);
101 buf[buflen - 1] = '\0';
102 /* discard oversized string */
104 while (len--) (void)fgetc(f);
108 fread(buf, len, 1, f);
114 printf("recv: {%d}\n", len);
116 if (isprint((unsigned char) *s)) {
119 printf("[%X]", (unsigned char) *s);
130 int dprintf(int lvl, const char *fmt, ...)
135 if (debuglevel >= lvl) {
137 ret = vfprintf(stdout, fmt, ap);
144 void saslerr(int why, const char *what)
146 fprintf(stderr, "%s: %s", what, sasl_errstring(why, NULL, NULL));
149 void saslfail(int why, const char *what)