]> git.ipfire.org Git - thirdparty/pdns.git/blame - pdns/session.hh
add OpenSSL exception to PowerDNS, Netherlabs, van Dijk and Hubert copyrights
[thirdparty/pdns.git] / pdns / session.hh
CommitLineData
12c86877
BH
1/*
2 PowerDNS Versatile Database Driven Nameserver
96a2625e 3 Copyright (C) 2002 - 2013 PowerDNS.COM BV
12c86877
BH
4
5 This program is free software; you can redistribute it and/or modify
22dc646a
BH
6 it under the terms of the GNU General Public License version 2
7 as published by the Free Software Foundation
f782fe38
MH
8
9 Additionally, the license of this program contains a special
10 exception which allows to distribute the program in binary form when
11 it is linked against OpenSSL.
12c86877
BH
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
06bd9ccf 20 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
12c86877
BH
21*/
22#ifndef SESSION_HH
23#define SESSION_HH
24
25#include <string>
26#include <cerrno>
092f210a 27
76473b92
KM
28#include <sys/stat.h>
29#include <netdb.h>
30#include <unistd.h>
31#include <sys/time.h>
32#include <sys/socket.h>
33#include <arpa/inet.h>
34#include <netinet/in.h>
35#include <sys/types.h>
36#include <strings.h>
092f210a 37
96a2625e 38#include "iputils.hh"
5c409fa2 39#include "pdnsexception.hh"
12c86877 40
3f81d239 41class SessionException: public PDNSException
12c86877
BH
42{
43public:
3f81d239 44 SessionException(const string &reason) : PDNSException(reason){}
12c86877
BH
45};
46
47class SessionTimeoutException: public SessionException
48{
49public:
50 SessionTimeoutException(const string &reason) : SessionException(reason){}
51};
52
53//! The Session class represents a TCP/IP session, which can either be created or run on an existing socket
54class Session
55{
56public:
57 bool getLine(string &); //!< Read a line from the remote
58 bool haveLine(); //!< returns true if a line is available
59 bool putLine(const string &s); //!< Write a line to the remote
60 bool sendFile(int fd); //!< Send a file out
61 int timeoutRead(int s,char *buf, size_t len);
2d56550b 62 string get(unsigned int bytes);
12c86877
BH
63
64 Session(int s, struct sockaddr_in r); //!< Start a session on an existing socket, and inform this class of the remotes name
65
66 /** Create a session to a remote host and port. This function reads a timeout value from the ArgvMap class
67 and does a nonblocking connect to support this timeout. It should be noted that nonblocking connects
68 suffer from bad portability problems, so look here if you see weird problems on new platforms */
69 Session(const string &remote, int port, int timeout=0);
092f210a 70 Session(uint32_t ip, int port, int timeout=0);
12c86877
BH
71
72 Session(const Session &s);
73
74 ~Session();
75 int getSocket(); //!< return the filedescriptor for layering violations
76 string getRemote();
092f210a 77 uint32_t getRemoteAddr();
12c86877
BH
78 string getRemoteIP();
79 void beVerbose();
80 int close(); //!< close and disconnect the connection
81 void setTimeout(unsigned int seconds);
82private:
092f210a 83 void doConnect(uint32_t ip, int port);
12c86877
BH
84 bool d_verbose;
85 char *rdbuf;
86 int d_bufsize;
87 int rdoffset;
88 int wroffset;
89 int clisock;
90 struct sockaddr_in remote;
91 void init();
92 int d_timeout;
93
94};
95
96//! The server class can be used to create listening servers
97class Server
98{
99public:
100 Server(int p, const string &localaddress=""); //!< port on which to listen
101 Session* accept(); //!< Call accept() in an endless loop to accept new connections
96a2625e 102 ComboAddress d_local;
12c86877
BH
103private:
104 int s;
12c86877
BH
105};
106
12c86877 107#endif /* SESSION_HH */