~ubuntu-branches/debian/experimental/nzbget/experimental

« back to all changes in this revision

Viewing changes to ScriptController.h

  • Committer: Package Import Robot
  • Author(s): Andreas Moog
  • Date: 2013-07-18 14:50:28 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20130718145028-qhxse81w1sj5w424
Tags: 11.0+dfsg-1
* New upstream release (Closes: #701896)
* Repackage original tarball to remove copies of jquery and twitter-
  bootstrap
* debian/watch: Update for new versioning scheme
* debian/patches: Remove all old patches, add one patch:
  - dont-embed-libraries.patch: Don't install embedded jquery and bootstrap 
    libraries
* debian/combat: Upgrade to debhelper combat 9
* debian/control:
  - Fix Vcs-Git field
  - Adjust debhelper version for combat level 9
  - Add jquery and bootstrap to depends for integrated webserver
  - Add python to recommends for post-processing scripts
  - Bump build-depends on libpar2-dev to support the cancel function
* debian/links:
  - Use the system jquery and bootstrap libraries
* debian/rules:
  - Add get-orig-source target to build modified upstream tarball
* Adjust sample nzbget.conf:
  - Only listen to 127.0.0.1 instead of 0.0.0.0
  - Use nzbget.conf as template for webui configuration
* Adjust sample nzbgetd init file:
  - Point to correct location of nzbget binary

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 *  This file is part of nzbget
3
3
 *
4
 
 *  Copyright (C) 2007-2010 Andrei Prygounkov <hugbug@users.sourceforge.net>
 
4
 *  Copyright (C) 2007-2013 Andrey Prygunkov <hugbug@users.sourceforge.net>
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
17
17
 *  along with this program; if not, write to the Free Software
18
18
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19
19
 *
20
 
 * $Revision: 378 $
21
 
 * $Date: 2010-01-29 10:34:44 +0100 (Fri, 29 Jan 2010) $
 
20
 * $Revision: 711 $
 
21
 * $Date: 2013-06-17 22:39:46 +0200 (Mon, 17 Jun 2013) $
22
22
 *
23
23
 */
24
24
 
43
43
public:
44
44
                                                EnvironmentStrings();
45
45
                                                ~EnvironmentStrings();
 
46
        void                            Clear();
46
47
        void                            InitFromCurrentProcess();
47
48
        void                            Append(char* szString);
48
49
#ifdef WIN32
59
60
        const char*                     m_szWorkingDir;
60
61
        const char**            m_szArgs;
61
62
        bool                            m_bFreeArgs;
 
63
        const char*                     m_szStdArgs[2];
62
64
        const char*                     m_szInfoName;
63
 
        const char*                     m_szDefaultKindPrefix;
 
65
        const char*                     m_szLogPrefix;
64
66
        EnvironmentStrings      m_environmentStrings;
65
 
        Options::EScriptLogKind m_eDefaultLogKind;
66
67
        bool                            m_bTerminated;
67
68
#ifdef WIN32
68
69
        HANDLE                          m_hProcess;
 
70
        char                            m_szCmdLine[2048];
69
71
#else
70
72
        pid_t                           m_hProcess;
71
73
#endif
72
74
 
 
75
protected:
73
76
        void                            ProcessOutput(char* szText);
74
 
        void                            PrepareEnvironmentStrings();
75
 
 
76
 
protected:
77
 
        virtual void            AddMessage(Message::EKind eKind, bool bDefaultKind, Options::EMessageTarget eMessageTarget, const char* szText);
 
77
        virtual bool            ReadLine(char* szBuf, int iBufSize, FILE* pStream);
 
78
        void                            PrintMessage(Message::EKind eKind, const char* szFormat, ...);
 
79
        virtual void            AddMessage(Message::EKind eKind, const char* szText);
 
80
        bool                            GetTerminated() { return m_bTerminated; }
 
81
        void                            ResetEnv();
 
82
        void                            PrepareEnvOptions(const char* szStripPrefix);
 
83
        void                            PrepareEnvParameters(NZBInfo* pNZBInfo, const char* szStripPrefix);
 
84
        void                            PrepareArgs();
78
85
 
79
86
public:
80
87
                                                ScriptController();
88
95
        void                            SetArgs(const char** szArgs, bool bFreeArgs) { m_szArgs = szArgs; m_bFreeArgs = bFreeArgs; }
89
96
        void                            SetInfoName(const char* szInfoName) { m_szInfoName = szInfoName; }
90
97
        const char*                     GetInfoName() { return m_szInfoName; }
91
 
        void                            SetDefaultKindPrefix(const char* szDefaultKindPrefix) { m_szDefaultKindPrefix = szDefaultKindPrefix; }
92
 
        void                            SetDefaultLogKind(Options::EScriptLogKind eDefaultLogKind) { m_eDefaultLogKind = eDefaultLogKind; }
 
98
        void                            SetLogPrefix(const char* szLogPrefix) { m_szLogPrefix = szLogPrefix; }
93
99
        void                            SetEnvVar(const char* szName, const char* szValue);
 
100
        void                            SetEnvVarSpecial(const char* szPrefix, const char* szName, const char* szValue);
94
101
};
95
102
 
96
 
class PostScriptController : public Thread, ScriptController
 
103
class PostScriptController : public Thread, public ScriptController
97
104
{
98
105
private:
99
106
        PostInfo*                       m_pPostInfo;
100
 
        bool                            m_bNZBFileCompleted;
101
 
        bool                            m_bHasFailedParJobs;
 
107
        char                            m_szNZBName[1024];
 
108
 
 
109
        void                            ExecuteScript(const char* szScriptName, const char* szDisplayName, const char* szLocation);
 
110
        void                            PrepareParams(const char* szScriptName);
 
111
        ScriptStatus::EStatus   AnalyseExitCode(int iExitCode);
 
112
 
 
113
        typedef std::deque<char*>               FileList;
102
114
 
103
115
protected:
104
 
        virtual void            AddMessage(Message::EKind eKind, bool bDefaultKind, Options::EMessageTarget eMessageTarget, const char* szText);
 
116
        virtual void            AddMessage(Message::EKind eKind, const char* szText);
105
117
 
106
118
public:
107
119
        virtual void            Run();
108
120
        virtual void            Stop();
109
 
        static void                     StartScriptJob(PostInfo* pPostInfo, const char* szScript, 
110
 
                                                        bool bNZBFileCompleted, bool bHasFailedParJobs);
 
121
        static void                     StartJob(PostInfo* pPostInfo);
 
122
        static void                     InitParamsForNewNZB(NZBInfo* pNZBInfo);
111
123
};
112
124
 
113
125
class NZBScriptController : public ScriptController
114
126
{
115
127
private:
 
128
        char**                          m_pNZBName;
116
129
        char**                          m_pCategory;
117
 
        NZBParameterList*       m_pParameterList;
 
130
        int*                            m_iPriority;
 
131
        NZBParameterList*       m_pParameters;
 
132
        bool*                           m_bAddTop;
 
133
        bool*                           m_bAddPaused;
 
134
        int                                     m_iPrefixLen;
118
135
 
119
136
protected:
120
 
        virtual void            AddMessage(Message::EKind eKind, bool bDefaultKind, Options::EMessageTarget eMessageTarget, const char* szText);
121
 
 
122
 
public:
123
 
        static void                     ExecuteScript(const char* szScript, const char* szNZBFilename, const char* szDirectory, char** pCategory, NZBParameterList* pParameterList);
124
 
};
125
 
 
126
 
class SchedulerScriptController : public Thread, ScriptController
 
137
        virtual void            AddMessage(Message::EKind eKind, const char* szText);
 
138
 
 
139
public:
 
140
        static void                     ExecuteScript(const char* szScript, const char* szNZBFilename, const char* szDirectory,
 
141
                                                        char** pNZBName, char** pCategory, int* iPriority, NZBParameterList* pParameters,
 
142
                                                        bool* bAddTop, bool* bAddPaused);
 
143
};
 
144
 
 
145
class NZBAddedScriptController : public Thread, public ScriptController
 
146
{
 
147
private:
 
148
        char*                           m_szNZBName;
 
149
 
 
150
public:
 
151
        virtual void            Run();
 
152
        static void                     StartScript(DownloadQueue* pDownloadQueue, NZBInfo *pNZBInfo, const char* szScript);
 
153
};
 
154
 
 
155
class SchedulerScriptController : public Thread, public ScriptController
127
156
{
128
157
public:
129
158
        virtual void            Run();