ATF_TC_BODY(t_saslc__error, tc) { saslc_t *ctx; ATF_REQUIRE(ctx = saslc_alloc()); ATF_REQUIRE_EQ(saslc_init(ctx, NULL, NULL), 0); saslc__error_set(ERR(ctx), ERROR_GENERAL, "test"); ATF_CHECK_EQ(saslc__error_get_errno(ERR(ctx)), ERROR_GENERAL); ATF_CHECK_STREQ(saslc_strerror(ctx), "test"); saslc__error_set_errno(ERR(ctx), ERROR_NOMEM); ATF_CHECK_STREQ(saslc_strerror(ctx), "no memory available"); ATF_REQUIRE_EQ(saslc_end(ctx), 0); }
int main(int argc, char **argv) { int opt, n, cont; char *mechanism = NULL; saslc_t *ctx; saslc_sess_t *sess; char input[LINE_MAX]; char *option, *var; char *output; static char empty[] = ""; size_t input_len, output_len; while ((opt = getopt(argc, argv, "hm:l")) != -1) { switch (opt) { case 'm': /* mechanism */ mechanism = optarg; break; case 'l': /* list mechanisms */ list_mechanisms(); return EXIT_SUCCESS; case 'h': default: /* ??? */ print_help(); return EXIT_FAILURE; } } if (mechanism == NULL) { printf("mechanism: "); if (nextline(input, sizeof(input), stdin) == NULL) goto eof; mechanism = input; } ctx = saslc_alloc(); if (saslc_init(ctx, NULL, NULL) < 0) goto error; if ((sess = saslc_sess_init(ctx, mechanism, NULL)) == NULL) goto error; /* reading properties */ if (nextline(input, sizeof(input), stdin) == NULL) goto eof; n = atoi(input); while (n--) { if (nextline(input, sizeof(input), stdin) == NULL) goto eof; var = strchr(input, ' '); if (var != NULL) *var++ = '\0'; else var = empty; option = input; if (saslc_sess_setprop(sess, option, var) < 0) goto error; } printf("session:\n"); for (;;) { if (nextline(input, sizeof(input), stdin) == NULL) break; input_len = strlen(input); cont = saslc_sess_cont(sess, input, input_len, (void **)&output, &output_len); if (cont < 0) goto error_sess; printf("%s\n", output == NULL ? "empty line" : output); if (cont == 0) break; } saslc_sess_end(sess); if (saslc_end(ctx) < 0) goto error; return 0; eof: err(EXIT_FAILURE, "Unexpected EOF"); error: errx(EXIT_FAILURE, "%s", saslc_strerror(ctx)); error_sess: errx(EXIT_FAILURE, "%s", saslc_sess_strerror(sess)); }