// imapd/CommandParser.hh
// This file is part of Decimail; see http://decimail.org
// (C) 2004 Philip Endecott
 
// This is version $Name$
//   (if there is no version (e.g. V0-1) mentioned in the previous line,
//    this is probably a snapshot from between "official" releases.)
 
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
#ifndef Imapd_CommandParser_hh
#define Imapd_CommandParser_hh

#include <string>
using namespace std;

#include "ScannerExtra.hh"
#include "commands.hh"
#include "parse_imap_command.tab.h"
#include "scan_imap_command.h"

struct ParserParams {
  Imapd::Session* session;
  yyscan_t* scanner;
  ScannerExtra* scanner_extra;
  string tag;
  ParserParams(Imapd::Session* se, yyscan_t* sc, ScannerExtra* sx):
    session(se), scanner(sc), scanner_extra(sx) {}
};

extern int parse_imap_command_parse(void* params);
extern int parse_imap_command_debug;

#include "Session.hh"
#include "Exception.hh"

#include <string>
#include <iostream>
using namespace std;

#include <boost/thread/tss.hpp>


namespace Imapd {

  struct PerThreadParamsHandle {
    ParserParams* const params;
    PerThreadParamsHandle(ParserParams* p): params(p) {}
  };

  class CommandParser {
  public:
    CommandParser(Session& s);
    ~CommandParser();
    void parse(int in_fd);

    static ParserParams* get_params_from_thread(void);

  private:
    Session& session;
    yyscan_t scanner;
    ParserParams parser_params;
    ScannerExtra scanner_extra;

    static boost::thread_specific_ptr<PerThreadParamsHandle>&
    CommandParser::get_tsp(void);
  };

}

#endif


