~ubuntu-branches/ubuntu/oneiric/enigmail/oneiric-updates

« back to all changes in this revision

Viewing changes to extensions/enigmail/ipc/src/nsPipeTransport.h

  • Committer: Bazaar Package Importer
  • Author(s): Alexander Sack
  • Date: 2010-04-10 01:42:24 UTC
  • Revision ID: james.westby@ubuntu.com-20100410014224-fbq9ui5x3b0h2t36
Tags: 2:1.0.1-0ubuntu1
* First releaase of enigmail 1.0.1 for tbird/icedove 3
  (LP: #527138)
* redo packaging from scratch 
  + add debian/make-orig target that uses xulrunner provided
    buildsystem + enigmail tarball to produce a proper orig.tar.gz
  + use debhelper 7 with mozilla-devscripts
  + use debian source format 3.0 (quilt)
  + patch enigmail to use frozen API only
    - add debian/patches/frozen_api.diff
  + patch build system to not link against -lxul - which isnt
    available for sdks produced by all-static apps like tbird
    - add debian/patches/build_system_dont_link_libxul.diff
  + add minimal build-depends to control

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * The contents of this file are subject to the Mozilla Public
 
3
 * License Version 1.1 (the "MPL"); you may not use this file
 
4
 * except in compliance with the MPL. You may obtain a copy of
 
5
 * the MPL at http://www.mozilla.org/MPL/
 
6
 *
 
7
 * Software distributed under the MPL is distributed on an "AS
 
8
 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 
9
 * implied. See the MPL for the specific language governing
 
10
 * rights and limitations under the MPL.
 
11
 *
 
12
 * The Original Code is protoZilla.
 
13
 *
 
14
 * The Initial Developer of the Original Code is Ramalingam Saravanan.
 
15
 * Portions created by Ramalingam Saravanan <svn@xmlterm.org> are
 
16
 * Copyright (C) 2000 Ramalingam Saravanan. All Rights Reserved.
 
17
 *
 
18
 * Contributor(s):
 
19
 * Patrick Brunschwig <patrick@mozilla-enigmail.org>
 
20
 *
 
21
 * Alternatively, the contents of this file may be used under the
 
22
 * terms of the GNU General Public License (the "GPL"), in which case
 
23
 * the provisions of the GPL are applicable instead of
 
24
 * those above. If you wish to allow use of your version of this
 
25
 * file only under the terms of the GPL and not to allow
 
26
 * others to use your version of this file under the MPL, indicate
 
27
 * your decision by deleting the provisions above and replace them
 
28
 * with the notice and other provisions required by the GPL.
 
29
 * If you do not delete the provisions above, a recipient
 
30
 * may use your version of this file under either the MPL or the
 
31
 * GPL.
 
32
 */
 
33
 
 
34
#ifndef nsPipeTransport_h__
 
35
#define nsPipeTransport_h__
 
36
 
 
37
#include "nspr.h"
 
38
#include "IPCProcess.h"
 
39
 
 
40
#include "nsIPipeTransport.h"
 
41
#include "nsIPipeListener.h"
 
42
#include "nsIRunnable.h"
 
43
#include "nsIInterfaceRequestor.h"
 
44
#include "nsITransport.h"
 
45
#include "nsIChannel.h"
 
46
#include "nsIPipe.h"
 
47
#include "nsIFile.h"
 
48
#include "nsIThread.h"
 
49
#include "nsILoadGroup.h"
 
50
#include "nsCOMPtr.h"
 
51
#include "nsIStreamListener.h"
 
52
#include "nsIInputStream.h"
 
53
#include "nsIOutputStream.h"
 
54
#include "nsThreadUtils.h"
 
55
 
 
56
#ifndef _IPC_FORCE_INTERNAL_API
 
57
#include "nsStringAPI.h"
 
58
#else
 
59
#include "nsString.h"
 
60
#endif
 
61
 
 
62
 
 
63
#include "nsIAsyncInputStream.h"
 
64
#include "nsIAsyncOutputStream.h"
 
65
 
 
66
#define NS_PIPE_TRANSPORT_DEFAULT_SEGMENT_SIZE   (2*1024)
 
67
#define NS_PIPE_TRANSPORT_DEFAULT_BUFFER_SIZE    (8*1024)
 
68
#define NS_PIPE_TRANSPORT_DEFAULT_HEADERS_SIZE   (4*1024)
 
69
 
 
70
class nsStdoutPoller;
 
71
 
 
72
class nsPipeTransport : public nsIPipeTransport,
 
73
                        public nsIPipeTransportListener,
 
74
                        public nsIOutputStream,
 
75
                        public nsIStreamListener,
 
76
                        public nsIInputStreamCallback,
 
77
                        public nsIOutputStreamCallback
 
78
{
 
79
public:
 
80
    NS_DECL_ISUPPORTS
 
81
    NS_DECL_NSIPIPETRANSPORT
 
82
    NS_DECL_NSIPIPETRANSPORTHEADERS
 
83
    NS_DECL_NSIPIPETRANSPORTLISTENER
 
84
    NS_DECL_NSIREQUEST
 
85
    NS_DECL_NSIREQUESTOBSERVER
 
86
    NS_DECL_NSIOUTPUTSTREAM
 
87
    NS_DECL_NSISTREAMLISTENER
 
88
    NS_DECL_NSIINPUTSTREAMCALLBACK
 
89
    NS_DECL_NSIOUTPUTSTREAMCALLBACK
 
90
 
 
91
    // nsPipeTransport methods:
 
92
    nsPipeTransport();
 
93
    // Always make the destructor virtual:
 
94
    virtual ~nsPipeTransport();
 
95
 
 
96
    nsresult Finalize(PRBool destructor);
 
97
 
 
98
    void KillProcess(void);
 
99
 
 
100
    // Define a Create method to be used with a factory:
 
101
    static NS_METHOD
 
102
    Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult);
 
103
 
 
104
    enum PipeState {
 
105
      PIPE_NOT_YET_OPENED,
 
106
      PIPE_OPEN,
 
107
      PIPE_CLOSED
 
108
    };
 
109
 
 
110
    enum StreamState {
 
111
      STREAM_NOT_YET_OPENED,
 
112
      STREAM_ASYNC_OPEN,
 
113
      STREAM_SYNC_OPEN,
 
114
      STREAM_CLOSED
 
115
    };
 
116
 
 
117
protected:
 
118
    PRBool                              mFinalized;
 
119
    PRBool                              mNoProxy;
 
120
    PRBool                              mStartedRequest;
 
121
    PRMonitor*                          mMonitor;
 
122
 
 
123
    PipeState                           mPipeState;
 
124
    StreamState                         mStdoutStream;
 
125
    nsresult                            mCancelStatus;
 
126
 
 
127
    nsLoadFlags                         mLoadFlags;
 
128
    PRUint32                            mNotificationFlags;
 
129
 
 
130
    nsCString                           mExecutable;
 
131
    nsCString                           mCommand;
 
132
    nsCString                           mKillString;
 
133
    nsCString                           mCwd;
 
134
    PRUint32                            mStartupFlags;
 
135
 
 
136
    IPCProcess*                         mProcess;
 
137
    PRIntervalTime                      mKillWaitInterval;
 
138
    PRInt32                             mExitCode;
 
139
 
 
140
    PRUint32                            mBufferSegmentSize;
 
141
    PRUint32                            mBufferMaxSize;
 
142
    PRUint32                            mHeadersMaxSize;
 
143
 
 
144
    nsCString                           mExecBuf;
 
145
 
 
146
    IPCFileDesc*                        mStdinWrite;
 
147
 
 
148
    // Owning refs
 
149
    nsCOMPtr<nsIPipeTransportPoller>    mStdoutPoller;
 
150
    nsCOMPtr<nsIPipeListener>           mConsole;
 
151
    nsCOMPtr<nsIPipeTransportHeaders>   mHeaderProcessor;
 
152
 
 
153
    nsCOMPtr<nsIInputStream>            mInputStream;
 
154
    nsCOMPtr<nsIOutputStream>           mOutputStream;
 
155
 
 
156
    nsCOMPtr<nsIStreamListener>         mListener;
 
157
    nsCOMPtr<nsISupports>               mContext;
 
158
    nsCOMPtr<nsILoadGroup>              mLoadGroup;
 
159
    nsCOMPtr<nsIPipeTransportWriter>    mPipeTransportWriter;
 
160
};
 
161
 
 
162
// Helper class to handle polling of STDOUT pipe
 
163
class nsStdoutPoller : public nsIPipeTransportPoller,
 
164
                       public nsIRunnable
 
165
{
 
166
public:
 
167
    NS_DECL_ISUPPORTS
 
168
    NS_DECL_NSIPIPETRANSPORTPOLLER
 
169
    NS_DECL_NSIRUNNABLE
 
170
 
 
171
    nsStdoutPoller();
 
172
    virtual ~nsStdoutPoller();
 
173
 
 
174
    nsresult Init(IPCFileDesc*            aStdoutRead,
 
175
                  IPCFileDesc*            aStderrRead,
 
176
                  PRIntervalTime          aTimeoutInterval,
 
177
                  nsIPipeListener*        aConsole);
 
178
 
 
179
    nsresult Finalize(PRBool destructor);
 
180
 
 
181
    PRBool IsInterrupted(void);
 
182
 
 
183
    nsresult GetPolledFD(PRFileDesc*& aFileDesc);
 
184
 
 
185
    nsresult HeaderSearch(const char* buf, PRUint32 count,
 
186
                          PRUint32 *headerOffset);
 
187
protected:
 
188
    PRBool                              mFinalized;
 
189
 
 
190
    PRLock*                             mLock;
 
191
    PRBool                              mInterrupted;
 
192
    PRBool                              mLoggingEnabled;
 
193
    PRBool                              mJoinableThread;
 
194
 
 
195
    PRIntervalTime                      mTimeoutInterval;
 
196
 
 
197
    nsCString                           mHeadersBuf;
 
198
    PRUint32                            mHeadersBufSize;
 
199
    PRUint32                            mHeadersLastNewline;
 
200
    PRBool                              mRequestStarted;
 
201
    PRInt32                             mContentLength;
 
202
 
 
203
    IPCFileDesc*                        mStdoutRead;
 
204
    IPCFileDesc*                        mStderrRead;
 
205
 
 
206
    PRInt32                             mPollCount;
 
207
    PRFileDesc*                         mPollableEvent;
 
208
    PRPollDesc*                         mPollFD;
 
209
 
 
210
    // Owning refs
 
211
    nsCOMPtr<nsIThread>                 mStdoutThread;
 
212
    nsCOMPtr<nsIOutputStream>           mOutputStream;
 
213
    nsCOMPtr<nsIPipeTransportListener>  mProxyPipeListener;
 
214
    nsCOMPtr<nsIPipeListener>           mConsole;
 
215
};
 
216
 
 
217
// Helper class to handle write to pipe
 
218
class nsStdinWriter : public nsIPipeTransportWriter,
 
219
                      public nsIRunnable
 
220
{
 
221
public:
 
222
    NS_DECL_ISUPPORTS
 
223
    NS_DECL_NSIPIPETRANSPORTWRITER
 
224
    NS_DECL_NSIRUNNABLE
 
225
 
 
226
    nsStdinWriter();
 
227
    virtual ~nsStdinWriter();
 
228
 
 
229
protected:
 
230
    nsCOMPtr<nsIInputStream> mInputStream;
 
231
    PRUint32                 mCount;
 
232
    IPCFileDesc*             mPipe;
 
233
    PRBool                   mCloseAfterWrite;
 
234
    nsCOMPtr<nsIThread>      mThread;
 
235
};
 
236
 
 
237
#endif // nsPipeTransport_h__