/*
 * Copyright (c) 1996-2007, OpenFWTK Development Group
 * All rights reserved. See LICENSE.
 */

/*
 * Routines for reading/parsing and generating FTP/SMTP commands and responses
 *
 * $Id: smftp.h,v 1.3 2007/09/10 02:49:13 arkenoi Exp $
 */

#ifndef	_SMFTP_H
#define	_SMFTP_H	1

#include <sys/types.h>

/* Responses */
/* extract first, second, third digits (from left) from status response */
#define DIG1(n)		(((n) / 100) % 10)
#define DIG2(n)		(((n) / 10) % 10)
#define DIG3(n)		(((n) / 1) % 10)

typedef ssize_t read_actor(int,char*,int,int);
int read_smftp_response(int ifd, read_actor *reader);
int __read_smftp_response(int ifd, char *ln, int maxsize, ssize_t (*reader)(int,char*,int,int));
/* this one returns regardless of continuations */
int ____read_smftp_response(int ifd, int *cont, char *ln, int maxsize, ssize_t (*reader)(int,char*,int,int));

void __send_msg(int fd, int num, const char *sep, const char *text, const char *endl);
void send_msg(int fd, int num, int cont, const char *text);
void relay_msg(int fd, int num, int cont, const char *text);


/* Commands */
int ____send_noarg(int ofd, const char *cmd);
int ____handle_noarg(int ofd, const char *cmd, int (*retr)(int fd));
int ____handle_noarg_resp(int ofd, const char *cmd, int (*retr)(int fd, char *,int), char *resp, int max_size);
int ____send_1str(int ofd, const char *cmd, const char *arg);
int ____handle_1str(int ofd, const char *cmd, const char *arg, int (*retr)(int fd));
int ____handle_1str_resp(int ofd, const char *cmd, const char *arg, int (*retr)(int fd, char *, int), char *resp, int max_size);
int ____send_1num(int ofd, const char *cmd, int arg);
int ____handle_1num(int ofd, const char *cmd, int arg, int (*retr)(int fd));

#endif /* _SMFTP_H */
