* { font-family: Consolas, Lucida Console, Courier New; font-size: 100%; }
h1 { font-size: 150%; }
td.linenos { background-color: #f0f0f0; padding-right: 10px; }
span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; }
pre { line-height: 100%; width: 100%; }
.highlight span { width: 100%; display:-moz-inline-stack; display:inline-block; zoom:1; *display:inline; }
body { background: #ffffff; }
body .c { color: #999988; font-style: italic } /* Comment */
body .err { color: #a61717; background-color: #e3d2d2 } /* Error */
body .k { font-weight: bold } /* Keyword */
body .o { font-weight: bold } /* Operator */
body .cm { color: #999988; font-style: italic } /* Comment.Multiline */
body .cp { color: #999999; font-weight: bold } /* Comment.Preproc */
body .c1 { color: #999988; font-style: italic } /* Comment.Single */
body .cs { color: #999999; font-weight: bold; font-style: italic } /* Comment.Special */
body .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
body .ge { font-style: italic } /* Generic.Emph */
body .gr { color: #aa0000 } /* Generic.Error */
body .gh { color: #999999 } /* Generic.Heading */
body .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
body .go { color: #888888 } /* Generic.Output */
body .gp { color: #555555 } /* Generic.Prompt */
body .gs { font-weight: bold } /* Generic.Strong */
body .gu { color: #aaaaaa } /* Generic.Subheading */
body .gt { color: #aa0000 } /* Generic.Traceback */
body .kc { font-weight: bold } /* Keyword.Constant */
body .kd { font-weight: bold } /* Keyword.Declaration */
body .kp { font-weight: bold } /* Keyword.Pseudo */
body .kr { font-weight: bold } /* Keyword.Reserved */
body .kt { color: #445588; font-weight: bold } /* Keyword.Type */
body .m { color: #009999 } /* Literal.Number */
body .s { color: #bb8844 } /* Literal.String */
body .na { color: #008080 } /* Name.Attribute */
body .nb { color: #999999 } /* Name.Builtin */
body .nc { color: #445588; font-weight: bold } /* Name.Class */
body .no { color: #008080 } /* Name.Constant */
body .ni { color: #800080 } /* Name.Entity */
body .ne { color: #990000; font-weight: bold } /* Name.Exception */
body .nf { color: #990000; font-weight: bold } /* Name.Function */
body .nn { color: #555555 } /* Name.Namespace */
body .nt { color: #000080 } /* Name.Tag */
body .nv { color: #008080 } /* Name.Variable */
body .ow { font-weight: bold } /* Operator.Word */
body .w { color: #bbbbbb } /* Text.Whitespace */
body .mf { color: #009999 } /* Literal.Number.Float */
body .mh { color: #009999 } /* Literal.Number.Hex */
body .mi { color: #009999 } /* Literal.Number.Integer */
body .mo { color: #009999 } /* Literal.Number.Oct */
body .sb { color: #bb8844 } /* Literal.String.Backtick */
body .sc { color: #bb8844 } /* Literal.String.Char */
body .sd { color: #bb8844 } /* Literal.String.Doc */
body .s2 { color: #bb8844 } /* Literal.String.Double */
body .se { color: #bb8844 } /* Literal.String.Escape */
body .sh { color: #bb8844 } /* Literal.String.Heredoc */
body .si { color: #bb8844 } /* Literal.String.Interpol */
body .sx { color: #bb8844 } /* Literal.String.Other */
body .sr { color: #808000 } /* Literal.String.Regex */
body .s1 { color: #bb8844 } /* Literal.String.Single */
body .ss { color: #bb8844 } /* Literal.String.Symbol */
body .bp { color: #999999 } /* Name.Builtin.Pseudo */
body .vc { color: #008080 } /* Name.Variable.Class */
body .vg { color: #008080 } /* Name.Variable.Global */
body .vi { color: #008080 } /* Name.Variable.Instance */
body .il { color: #009999 } /* Literal.Number.Integer.Long */
Info
Revision:3386
Author:victor
Date:2008-07-19 22:16:58 +0300 (Sat, 19 Jul 2008)
Comment:added file upload to agent API
Changes
U trunk/src/server/include/nxsrvapi.h
U trunk/src/server/libnxsrv/agent.cpp
Diff
Modified: trunk/src/server/include/nxsrvapi.h
===================================================================
--- trunk/src/server/include/nxsrvapi.h 2008-07-17 20:59:45 UTC (rev 3385)
+++ trunk/src/server/include/nxsrvapi.h 2008-07-19 19:16:58 UTC (rev 3386)
@@ -262,7 +262,7 @@
DWORD m_dwAddr;
int m_nProtocolVersion;
int m_iAuthMethod;
- char m_szSecret[MAX_SECRET_LENGTH];
+ TCHAR m_szSecret[MAX_SECRET_LENGTH];
time_t m_tLastCommandTime;
SOCKET m_hSocket;
DWORD m_dwNumDataLines;
@@ -281,7 +281,11 @@
WORD m_wPort;
WORD m_wProxyPort;
int m_iProxyAuth;
- char m_szProxySecret[MAX_SECRET_LENGTH];
+ TCHAR m_szProxySecret[MAX_SECRET_LENGTH];
+ int m_hCurrFile;
+ DWORD m_dwUploadRequestId;
+ CONDITION m_condFileUpload;
+ BOOL m_fileUploadSucceeded;
void ReceiverThread(void);
static THREAD_RESULT THREAD_CALL ReceiverThreadStarter(void *);
@@ -295,9 +299,11 @@
DWORD Authenticate(BOOL bProxyData);
DWORD SetupProxyConnection(void);
DWORD GetIpAddr(void) { return ntohl(m_dwAddr); }
+ DWORD PrepareFileUpload(const TCHAR *fileName, DWORD rqId);
virtual void PrintMsg(const TCHAR *pszFormat, ...);
virtual void OnTrap(CSCPMessage *pMsg);
+ virtual void OnFileUpload(BOOL success);
void Lock(void) { MutexLock(m_mutexDataLock, INFINITE); }
void Unlock(void) { MutexUnlock(m_mutexDataLock); }
@@ -328,7 +334,7 @@
DWORD GetConfigFile(TCHAR **ppszConfig, DWORD *pdwSize);
DWORD UpdateConfigFile(const TCHAR *pszConfig);
DWORD EnableTraps(void);
- CSCPMessage *CustomRequest(CSCPMessage *pRequest);
+ CSCPMessage *CustomRequest(CSCPMessage *pRequest, const TCHAR *recvFile = NULL);
DWORD GetNumDataLines(void) { return m_dwNumDataLines; }
const TCHAR *GetDataLine(DWORD dwIndex) { return dwIndex < m_dwNumDataLines ? m_ppDataLines[dwIndex] : _T("(error)"); }
Modified: trunk/src/server/libnxsrv/agent.cpp
===================================================================
--- trunk/src/server/libnxsrv/agent.cpp 2008-07-17 20:59:45 UTC (rev 3385)
+++ trunk/src/server/libnxsrv/agent.cpp 2008-07-19 19:16:58 UTC (rev 3386)
@@ -30,8 +30,8 @@
// Constants
//
-//#define RECEIVER_BUFFER_SIZE 262144
-#define RECEIVER_BUFFER_SIZE 4194304
+#define RECEIVER_BUFFER_SIZE 262144
+//#define RECEIVER_BUFFER_SIZE 4194304
//
@@ -93,6 +93,8 @@
m_bUseProxy = FALSE;
m_dwRecvTimeout = 420000; // 7 minutes
m_nProtocolVersion = NXCP_VERSION;
+ m_hCurrFile = -1;
+ m_condFileUpload = ConditionCreate(TRUE);
}
@@ -134,6 +136,8 @@
m_bUseProxy = FALSE;
m_dwRecvTimeout = 420000; // 7 minutes
m_nProtocolVersion = NXCP_VERSION;
+ m_hCurrFile = -1;
+ m_condFileUpload = ConditionCreate(TRUE);
}
@@ -165,7 +169,11 @@
delete m_pMsgWaitQueue;
DestroyEncryptionContext(m_pCtx);
+ if (m_hCurrFile != -1)
+ close(m_hCurrFile);
+
MutexDestroy(m_mutexDataLock);
+ ConditionDestroy(m_condFileUpload);
}
@@ -252,17 +260,52 @@
continue; // Bad packet, wait for next
}
- // Create message object from raw message
- pMsg = new CSCPMessage(pRawMsg, m_nProtocolVersion);
- if (pMsg->GetCode() == CMD_TRAP)
- {
- OnTrap(pMsg);
- delete pMsg;
- }
- else
- {
- m_pMsgWaitQueue->Put(pMsg);
- }
+ if (ntohs(pRawMsg->wFlags) & MF_BINARY)
+ {
+ // Convert message header to host format
+ pRawMsg->dwId = ntohl(pRawMsg->dwId);
+ pRawMsg->wCode = ntohs(pRawMsg->wCode);
+ pRawMsg->dwNumVars = ntohl(pRawMsg->dwNumVars);
+ DbgPrintf(6, "Received raw message %s from agent at %s",
+ NXCPMessageCodeName(pRawMsg->wCode, szBuffer), IpToStr(GetIpAddr(), szBuffer));
+
+ if ((pRawMsg->wCode == CMD_FILE_DATA) &&
+ (m_hCurrFile != -1) && (pRawMsg->dwId == m_dwUploadRequestId))
+ {
+ if (write(m_hCurrFile, pRawMsg->df, pRawMsg->dwNumVars) == (int)pRawMsg->dwNumVars)
+ {
+ if (ntohs(pRawMsg->wFlags) & MF_END_OF_FILE)
+ {
+ close(m_hCurrFile);
+ m_hCurrFile = -1;
+
+ OnFileUpload(TRUE);
+ }
+ }
+ else
+ {
+ // I/O error
+ close(m_hCurrFile);
+ m_hCurrFile = -1;
+
+ OnFileUpload(FALSE);
+ }
+ }
+ }
+ else
+ {
+ // Create message object from raw message
+ pMsg = new CSCPMessage(pRawMsg, m_nProtocolVersion);
+ if (pMsg->GetCode() == CMD_TRAP)
+ {
+ OnTrap(pMsg);
+ delete pMsg;
+ }
+ else
+ {
+ m_pMsgWaitQueue->Put(pMsg);
+ }
+ }
}
// Close socket and mark connection as disconnected
@@ -1385,14 +1428,83 @@
// Send custom request to agent
//
-CSCPMessage *AgentConnection::CustomRequest(CSCPMessage *pRequest)
+CSCPMessage *AgentConnection::CustomRequest(CSCPMessage *pRequest, const TCHAR *recvFile)
{
- DWORD dwRqId;
+ DWORD dwRqId, rcc;
+ CSCPMessage *msg = NULL;
dwRqId = m_dwRequestId++;
pRequest->SetId(dwRqId);
- if (SendMessage(pRequest))
- return WaitForMessage(CMD_REQUEST_COMPLETED, dwRqId, m_dwCommandTimeout);
- else
- return NULL;
+ if (recvFile != NULL)
+ {
+ rcc = PrepareFileUpload(recvFile, dwRqId);
+ if (rcc != ERR_SUCCESS)
+ {
+ // Create fake response message
+ msg = new CSCPMessage;
+ msg->SetCode(CMD_REQUEST_COMPLETED);
+ msg->SetId(dwRqId);
+ msg->SetVariable(VID_RCC, rcc);
+ }
+ }
+
+ if (msg == NULL)
+ {
+ if (SendMessage(pRequest))
+ {
+ msg = WaitForMessage(CMD_REQUEST_COMPLETED, dwRqId, m_dwCommandTimeout);
+ if ((msg != NULL) && (recvFile != NULL))
+ {
+ if (msg->GetVariableLong(VID_RCC) == ERR_SUCCESS)
+ {
+ if (ConditionWait(m_condFileUpload, 1800000)) // 30 min timeout
+ {
+ if (!m_fileUploadSucceeded)
+ {
+ msg->SetVariable(VID_RCC, ERR_IO_FAILURE);
+ remove(recvFile);
+ }
+ }
+ else
+ {
+ msg->SetVariable(VID_RCC, ERR_REQUEST_TIMEOUT);
+ }
+ }
+ else
+ {
+ close(m_hCurrFile);
+ m_hCurrFile = -1;
+ remove(recvFile);
+ }
+ }
+ }
+ }
+
+ return msg;
}
+
+
+//
+// Prepare for file upload
+//
+
+DWORD AgentConnection::PrepareFileUpload(const TCHAR *fileName, DWORD rqId)
+{
+ if (m_hCurrFile != -1)
+ return ERR_RESOURCE_BUSY;
+
+ ConditionReset(m_condFileUpload);
+ m_hCurrFile = open(fileName, O_CREAT | O_TRUNC | O_WRONLY | O_BINARY, O_RDWR);
+ return (m_hCurrFile != -1) ? ERR_SUCCESS : ERR_FILE_OPEN_ERROR;
+}
+
+
+//
+// File upload completion handler
+//
+
+void AgentConnection::OnFileUpload(BOOL success)
+{
+ m_fileUploadSucceeded = success;
+ ConditionSet(m_condFileUpload);
+}
Received on Sat Jul 19 2008 - 22:16:58 EEST
This archive was generated by hypermail 2.2.0 : Sat Jul 19 2008 - 20:15:13 EEST