~ubuntu-branches/ubuntu/saucy/gnash/saucy-proposed

« back to all changes in this revision

Viewing changes to libnet/network.h

  • Committer: Bazaar Package Importer
  • Author(s): Sindhudweep Narayan Sarkar
  • Date: 2009-10-07 00:06:10 UTC
  • mfrom: (1.1.12 upstream)
  • Revision ID: james.westby@ubuntu.com-20091007000610-mj9rwqe774gizn1j
Tags: 0.8.6-0ubuntu1
new upstream release 0.8.6 (LP: #435897)

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
#include "gnashconfig.h"
23
23
#endif
24
24
 
25
 
#include <boost/thread/mutex.hpp>
26
25
#if !defined(HAVE_WINSOCK_H) || defined(__OS2__)
27
26
# include <sys/types.h>
28
27
# include <netinet/in.h>
43
42
# include <io.h>
44
43
#endif
45
44
 
46
 
#include "dsodefs.h" //For DSOEXPORT.
47
45
#include <boost/shared_ptr.hpp>
 
46
#include <boost/scoped_ptr.hpp>
48
47
#include <boost/cstdint.hpp>
 
48
#include <boost/thread/mutex.hpp>
49
49
#include <vector>
50
50
#include <cassert>
51
51
#include <string>
52
52
#include <map>
53
53
 
 
54
#ifdef USE_SSH
 
55
# include "sshclient.h"
 
56
#endif
 
57
 
 
58
#ifdef USE_SSL
 
59
# include "sslclient.h"
 
60
#endif
 
61
 
 
62
#include "dsodefs.h" //For DSOEXPORT.
 
63
 
54
64
namespace amf {
55
65
class Buffer;
56
66
}
59
69
///     This is the main namespace for Gnash and it's libraries.
60
70
namespace gnash {
61
71
 
 
72
// forward declare the encryption protocols
 
73
class SSLClient;
 
74
class SSHClient;
 
75
 
 
76
// Define the default ports
 
77
const short SSL_PORT    = 443;
 
78
const short SSH_PORT    = 22;
 
79
const short HTTP_PORT   = 80;
 
80
 
 
81
// Delay Tolerant Networking Research Group, http://www.dtnrg.org
 
82
const short DTN1_PORT   = 2445;
 
83
const short DTN2_PORT   = 4556;
 
84
 
62
85
// Define the ports for the RTMP protocols
63
 
const short ADMIN_PORT = 1111;
64
 
const short RTMP_PORT = 1935;
65
 
const short RTMPE_PORT = 1935;
66
 
const short RTMPT_PORT = 80;
67
 
const short RTMPTE_PORT = 80;
68
 
const short RTMPTS_PORT = 443;
 
86
const short ADMIN_PORT  = 1111;
 
87
const short RTMP_PORT   = 1935;
 
88
const short RTMPE_PORT  = 1935;
 
89
const short RTMPT_PORT  = HTTP_PORT;
 
90
const short RTMPTE_PORT = HTTP_PORT;
 
91
const short RTMPTS_PORT = SSL_PORT;
 
92
const short CGIBIN_PORT = 1234;
69
93
 
70
94
#ifdef __OS2__
71
95
 typedef int    socklen_t;
78
102
  typedef int    socklen_t;
79
103
#endif
80
104
 
 
105
#if defined(HAVE_POLL_H) || defined(HAVE_PPOLL)
 
106
#include <poll.h>
 
107
#else
 
108
struct pollfd {
 
109
    int   fd; 
 
110
    short events;
 
111
    short revents;
 
112
};
 
113
#endif
81
114
 
82
115
/// \class Network
83
116
///     This is a low level network class for Gnash and Cygnal. This
85
118
///     side of a network connection.
86
119
class DSOEXPORT Network {
87
120
public:
 
121
    /// This enum contains the list of all supported protocols.
 
122
    typedef enum {
 
123
        NONE,
 
124
        HTTP,
 
125
        HTTPS,
 
126
        RTMP,
 
127
        RTMPT,
 
128
        RTMPTS,
 
129
        RTMPE,
 
130
        RTMPS,
 
131
        DTN
 
132
    } protocols_supported_e;
88
133
    // This is used to pass parameters to a thread using boost::bind
89
134
    typedef struct {
 
135
        int tid;
 
136
        int port;
90
137
        int netfd;
91
 
        int port;
 
138
        void *entry;
92
139
        void *handler;
93
140
        std::string filespec;
94
 
        int tid;
 
141
        protocols_supported_e protocol;
95
142
    } thread_params_t;
96
143
    typedef boost::uint8_t byte_t;
97
144
    typedef bool entry_t (thread_params_t *);
191
238
    /// @param limit The max number of file descriptors to wait for.
192
239
    ///
193
240
    /// @return A vector of the file descriptors that have activity.
194
 
#ifdef HAVE_POLL_H
195
241
    boost::shared_ptr<std::vector<struct pollfd> > waitForNetData(int limit, struct pollfd *fds);
196
 
#endif
197
242
    fd_set waitForNetData(int limit, fd_set data);
198
243
    fd_set waitForNetData(std::vector<int> &data);
199
244
        
214
259
    bool send(const char *str);
215
260
 
216
261
    // Accessors for testing
217
 
    bool connected()           
 
262
    bool connected() const
218
263
    {
219
264
        assert ( ( _connected && _sockfd > 0 ) || ( ! _connected && _sockfd <= 0 ) );
220
265
        return _connected;
227
272
    int getListenFd() const { return _listenfd; };
228
273
    void setListenFd(int x) { _listenfd = x; };
229
274
    const std::string& getURL() const { return _url; }
 
275
    void setURL(const std::string& url) { _url = url; }
 
276
 
230
277
    const std::string& getProtocol() const  { return _protocol; }
 
278
    void setProtocol(const std::string& proto) { _protocol = proto; }
 
279
 
231
280
    const std::string& getHost() const { return _host; }
 
281
    void setHost(const std::string& host) { _host = host; }
 
282
 
232
283
    const std::string& getPortStr() const { return _portstr; }
 
284
    void setPortStr(const std::string& port) { _portstr = port; }
 
285
 
233
286
    const std::string& getPath() const { return _path; }
 
287
    void setPath(const std::string& path) { _path = path; }
 
288
 
234
289
    void setTimeout(int x) { _timeout = x; }
235
290
    int getTimeout() const { return _timeout; }
236
291
 
245
300
    void erasePollFD(std::vector<struct pollfd>::iterator &itt);
246
301
    struct pollfd &getPollFD(int fd);
247
302
    struct pollfd *getPollFDPtr();
 
303
#ifdef HAVE_POLL_H
248
304
    size_t getPollFDSize() { return _pollfds.size(); };
249
305
    void clearPollFD() { _pollfds.clear(); };
 
306
#endif
250
307
 
251
308
    // The entry point is an function pointer, which is the event
252
309
    // handler when there is data on a file descriptor.
254
311
    entry_t *getEntry(int fd);
255
312
    
256
313
//    void executePollFD(int index) { _handler[index](); ];
 
314
 
 
315
#ifdef USE_SSL
 
316
    bool initSSL(std::string &hostname);
 
317
    bool initSSL(std::string &hostname, std::string &password);
 
318
    bool initSSL(std::string &hostname, std::string &password, bool auth);
 
319
    bool initSSL(std::string &hostname, std::string &password, 
 
320
                 std::string &keyfile, std::string &calist,
 
321
                 std::string &rootpath, bool auth);
 
322
#endif
257
323
    
258
324
 protected:
259
325
    in_addr_t   _ipaddr;
268
334
    bool        _connected;
269
335
    bool        _debug;
270
336
    int         _timeout;
 
337
    size_t      _bytes_loaded;
271
338
    /// \var Handler::_handlers
272
339
    ///         Keep a list of all active network connections
273
340
    std::map<int, entry_t *> _handlers;
274
 
#ifdef HAVE_POLL_H
275
341
    std::vector<struct pollfd> _pollfds;
276
342
    // This is the mutex that controls access to the que.
277
343
    boost::mutex        _poll_mutex;
 
344
    boost::mutex        _net_mutex;
 
345
#ifdef USE_SSL
 
346
    boost::scoped_ptr<SSLClient> _ssl;
 
347
#endif
 
348
#ifdef USE_SSH
 
349
    boost::scoped_ptr<SSHClient> _ssh;
278
350
#endif
279
351
};
280
352