00001 /* -*- Mode: C++ -*- 00002 * Worldvisions Weaver Software: 00003 * Copyright (C) 1997-2002 Net Integration Technologies, Inc. 00004 * 00005 */ 00006 #ifndef __WVPROTOSTREAM_H 00007 #define __WVPROTOSTREAM_H 00008 00009 #include "wvstreamclone.h" 00010 00011 class WvLog; 00012 00013 /** 00014 * WvProtoStream is a framework that makes it easy to communicate using 00015 * common command-response driven protocols. This is supposed to be 00016 * flexible enough to handle FTP, HTTP, SMTP, tunnelv, Weaver rcmd, and 00017 * many others. 00018 */ 00019 class WvProtoStream : public WvStreamClone 00020 { 00021 public: 00022 class Token 00023 { 00024 public: 00025 WvString data; 00026 size_t length; 00027 00028 Token(); 00029 Token(const unsigned char *_data, size_t _length); 00030 void fill(const unsigned char *_data, size_t _length); 00031 ~Token(); 00032 }; 00033 00034 DeclareWvList(Token); 00035 00036 WvDynBuf tokbuf; 00037 bool log_enable; 00038 00039 WvProtoStream(WvStream *_cloned, WvLog *_debuglog = NULL); 00040 virtual ~WvProtoStream(); 00041 00042 /** override uwrite() so we can log all output */ 00043 virtual size_t uwrite(const void *buffer, size_t size); 00044 00045 // Routines to convert an input line into a set of Tokens. 00046 virtual Token *next_token(); 00047 WvString next_token_str(); 00048 WvString token_remaining(); 00049 virtual TokenList *tokenize(); 00050 size_t list_to_array(TokenList *tl, Token **array); 00051 Token *tokline(const char *line); 00052 00053 /** Convert token strings to enum values */ 00054 int tokanal(const Token &t, char **lookup, 00055 bool case_sensitive = false); 00056 00057 // finite state machine 00058 int state; 00059 virtual void do_state(Token &t1); 00060 virtual void switch_state(int newstate); 00061 00062 /** pass input through to the state machine, one line at a time */ 00063 virtual void execute(); 00064 00065 protected: 00066 WvLog *logp; 00067 }; 00068 00069 00070 #endif // __WVPROTOSTREAM_H