// TSServer.cpp: implementation of the TSServer and TSSchema classes. // ///////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include #include #include #include #include "TSAttachment.h" #include "TSAuxiliaryItem.h" #include "TSChangeHistory.h" #include "TSDisplayField.h" #include "TSItem.h" #include "TSItemLink.h" #include "TSField.h" #include "TSPrimaryItem.h" #include "TSProject.h" #include "TSRecord.h" #include "TSRecordRef.h" #include "TSServer.h" #include "TSTransition.h" #include "TSUtility.h" /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Global Error status functions. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ static int TSErrorCode = TS_OK; static char* TSErrorMessage = ""; void TSSetLastError( int errorCode ) { TSErrorCode = errorCode; } int TSGetLastError() { return TSErrorCode; } void TSClearLastError() { TSSetLastError( TS_OK ); } void TSSetLastErrorMessage( char* sErrorMessage ) { TSErrorMessage = sErrorMessage; } void TSAppendLastErrorMessage( char* sErrorMessage ) { char sep[3] = "; "; int length = strlen( sErrorMessage ) + strlen( sep ) + strlen( TSErrorMessage ); char* sNewMessage = new char[length+1]; sprintf( sNewMessage, "%s%s%s", sErrorMessage, sep, TSErrorMessage ); TSErrorMessage = sNewMessage; delete [] sNewMessage; } char* TSGetLastErrorMessage() { return TSErrorMessage; } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Methods for the Schema class. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ TSSchema::~TSSchema() { fieldList.EmptyAndDestroyList(); } TSObject* TSSchema::NewObject() { TSSchema* newSchema = new TSSchema; if ( newSchema ) { return newSchema; } else { TSSetLastError( TS_MEMORY_ERROR ); TSSetLastErrorMessage( "TSSchema::NewObject: Unable to allocate memory" ); return NULL; } } // Deep copy a schema by creating a new schema and *this* onto it. TSObject* TSSchema::Duplicate( int /*type = 0*/ ) { TSSchema* obj = new TSSchema(); if ( obj ) { obj->tableId = tableId; obj->name = name; obj->userDefinedFields = userDefinedFields; // Duplicate deep copies caller list onto the parameter list. fieldList.Duplicate( &obj->fieldList ); return obj; } else { TSSetLastError( TS_MEMORY_ERROR ); TSSetLastErrorMessage( "TSSchema::Duplicate: Unable to allocate memory" ); return NULL; } } // The Copy method shallow copies the sourceSchema into *this*. void TSSchema::Copy( TSObject* sourceSchema ) { TSSchema* schema = static_cast( sourceSchema ); tableId = schema->tableId; name = schema->name; // The Copy method shallow copies the parameter list into the calling list. fieldList.Copy( &schema->fieldList ); } TSString TSSchema::StringDump( int /*recursive*/, TSString indentation ) { char tmp[24]; TSString s = indentation; s += "tableId = "; sprintf( tmp, "%ld", tableId ); s += tmp; s += "\n"; s += indentation; s += "name = "; s += name; s += "\n"; if ( userDefinedFields ) { s += "Has User Defined Fields\n"; } else { s += "Does Not Have User Defined Fields\n"; } s += "fields: \n"; TSField* field; TSPosition* pos = fieldList.GetFirst(); while ( pos ) { field = fieldList.GetAt( pos ); s += field->StringDump( true, " " ); s += "\n"; pos = fieldList.GetNext( pos ); } return s; } int TSSchema::SocketString( TSString& /*str*/ ) { // Not needed for a schema since it's a client-side-only object. TSSetLastError( TS_ERROR ); return TSGetLastError(); } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Methods for the Server class. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ TSServer::TSServer() : protocolString ( "" ), serverName ( "" ), directoryName ( "" ), dllName ( "" ), portNumber ( 0 ), proxyString ( "" ), authString ( "" ), dllWebAddress ( "" ), errorMsg ( "" ), schemaCache ( ), m_pSocket ( NULL ) { } TSServer::~TSServer() { schemaCache.EmptyAndDestroyList(); if ( m_pSocket ) { delete m_pSocket; } } int TSServer::Connect( const char* userName, const char* password, const char* serverAddress, const char* proxyAddress /*=NULL*/ ) { int len; char delim; char* host; char* hostptr; const char* from; char szBuffer[1024]; errorMsg = ""; TSClearLastError(); TSSetLastErrorMessage( "" ); // Some basic error checking if ( userName == NULL || *userName == '\0' ) { errorMsg = "TSServer::Connect: No username specified."; TSSetLastError( TS_INVALID_USER ); TSSetLastErrorMessage( errorMsg.GetBuffer() ); return TSGetLastError(); } if ( password == NULL ) { errorMsg = "TSServer::Connect: No password specified."; TSSetLastError( TS_INVALID_USER ); TSSetLastErrorMessage( errorMsg.GetBuffer() ); return TSGetLastError(); } if ( serverAddress == NULL || *serverAddress == '\0' ) { errorMsg = "TSServer::Connect: No server address specified."; TSSetLastError( TS_ERROR ); TSSetLastErrorMessage( errorMsg.GetBuffer() ); return TSGetLastError(); } // Copy the server address, stripping of leading and trailing spaces // and changing backslashes to forward slashes, uppercase to lowercase host = (char*)malloc( strlen( serverAddress ) + 1 ); from = serverAddress; hostptr = host; while ( *from && iswspace( *from ) ) from++; while ( *from && !iswspace( *from ) ) { if ( *from == '\\' ) { *hostptr++ = '/'; from++; } else { *hostptr++ = (char)tolower( *from++ ); } } *hostptr = '\0'; hostptr = host; // Strip protocol if ( strncmp( hostptr, "http://", 7 ) == 0 ) { protocolString = "http"; portNumber = 80; hostptr += 7; } else if ( strncmp( host, "https://", 8 ) == 0 ) { protocolString = "https"; portNumber = 443; hostptr += 8; } else { protocolString = "http"; portNumber = 80; } // Strip server name len = strcspn( hostptr, ":/" ); if ( len == 0 ) { errorMsg = "TSServer::Connect: No server address specified."; TSSetLastError( TS_ERROR ); TSAppendLastErrorMessage( errorMsg.GetBuffer() ); return TSGetLastError(); } delim = hostptr[len]; hostptr[len] = '\0'; serverName = hostptr; hostptr += len; if ( delim != '\0' ) { hostptr++; } // Strip the port number if ( delim == ':' ) { len = strcspn( hostptr, "/" ); if ( len != 0 ) { delim = hostptr[len]; hostptr[len] = '\0'; int nTmpPort = atol( hostptr ); if ( nTmpPort > 0 ) { portNumber = nTmpPort; } hostptr += len; if ( delim != '\0' ) { hostptr++; } } } directoryName = "tmtrack"; dllName = "tmtrack.dll?"; len = strlen( hostptr ); if ( len > 0 ) { // Get the directory and dll names char* cp; // If the last character is a question mark or slash, strip it off cp = &hostptr[ len - 1 ]; if ( *cp == '?' || *cp == '/' ) { len--; hostptr[ len ] = '\0'; } // if a dll is specified if ( ( len > 4 ) && ( strcmp( &hostptr[ len - 4 ], ".dll" ) == 0 ) ) { // Strip off the dll name cp = strrchr( hostptr, '/' ); if ( cp == NULL ) { // No more slashes, rest of string must be the dll dllName = hostptr; directoryName = ""; } else { dllName = &cp[1]; *cp = '\0'; // rest of string must be directory name directoryName = hostptr; } dllName += "?"; } else { directoryName = hostptr; } } free( host ); if ( proxyAddress != NULL ) { proxyString = proxyAddress; } TSString authentication; authentication = userName; authentication += ":"; authentication += password; authString = "Authorization: Basic "; authString += EncodePassword( authentication.GetBuffer()); sprintf( szBuffer, "%s://%s:%d/%s/%s", protocolString.GetBuffer(), serverName.GetBuffer(), portNumber, directoryName.GetBuffer(), dllName.GetBuffer() ); dllWebAddress = szBuffer; int nReturn = ValidateVersion(); if ( nReturn != TS_OK ) { // 0 is a version failure. if ( nReturn == 0 ) { TSSetLastError( TS_INVALID_VERSION ); TSAppendLastErrorMessage( "TSServer::Connect: Error validating version" ); } else // < 0 is another kind of error; { TSSetLastError( nReturn ); TSAppendLastErrorMessage( "TSServer::Connect: Some other kind of error validating version" ); } return TSGetLastError(); } return TS_OK; } TSString TSServer::EncodePassword( const char* password ) { TSString out; unsigned char buf[3]; int idx = 0; static char base64Table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; while ( *password ) { buf[idx++] = *password++; if ( idx == 3 ) { // Output the 4 encoded bytes out += base64Table[buf[0] >> 2]; // first 6-bits of byte 0 out += base64Table[((( buf[0] & 0x03 ) << 4 )) | ( buf[1] >> 4 )]; // last 2-bits of byte 0 + first 4-bits of byte 1 out += base64Table[((( buf[1] & 0x0f ) << 2 )) | ( buf[2] >> 6 )]; // last 4-bits of byte 1 + first 2-bits of byte 2 out += base64Table[buf[2] & 0x3f]; // last 6-bits of byte 2 idx = 0; } } // Special case handling of last 1 or 2 characters if ( idx == 1 ) { out += base64Table[buf[0] >> 2]; // first 6-bits of byte 0 out += base64Table[(( buf[0] & 0x03 ) << 4 )]; // last 2-bits of byte 0 out += "=="; // == pad } else if ( idx == 2 ) { out += base64Table[buf[0] >> 2]; // first 6-bits of byte 0 out += base64Table[((( buf[0] & 0x03 ) << 4 )) | ( buf[1] >> 4 )]; // last 2-bits of byte 0 + first 4-bits of byte 1 out += base64Table[(( buf[1] & 0x0f ) << 2 )]; // last 4-bits of byte 1 out += "="; // = pad } return out; } const char* TSServer::GetDllWebAddress() { return dllWebAddress.GetBuffer(); } const char* TSServer::GetLastErrorMessage() { return errorMsg.GetBuffer(); } TSSocket* TSServer::OpenSocket() { // Clear out the error message string before we get started errorMsg = ""; TSClearLastError(); TSSetLastErrorMessage( "" ); TSSocket* socket = new TSSocket; if ( socket == NULL ) { TSSetLastError( TS_MEMORY_ERROR ); TSSetLastErrorMessage( "TSServer::OpenSocket: Unable to allocate memory" ); return NULL; } if ( !socket->Create( protocolString.GetBuffer(), directoryName.GetBuffer(), dllName.GetBuffer(), authString.GetBuffer(), proxyString.GetBuffer() ) ) { errorMsg = "Socket Create failed."; TSSetLastError( TS_SOCKET_CREATE_FAILED ); TSSetLastErrorMessage( "TSServer::OpenSocket: Failed to Create the socket" ); delete socket; return NULL; } if ( !socket->Connect( serverName.GetBuffer(), portNumber )) { errorMsg = "Socket Connect failed."; TSSetLastError( TS_SOCKET_CONNECT_FAILED ); TSSetLastErrorMessage( "TSServer::OpenSocket: Failed to Connect to the socket" ); delete socket; return NULL; } return socket; } TSSocket* TSServer::GetSocket() { if ( m_pSocket == NULL ) { m_pSocket = OpenSocket(); if ( m_pSocket == NULL ) { return NULL; } } else { // Clear out the error message string just like OpenSocket errorMsg = ""; TSClearLastError(); TSSetLastErrorMessage( "" ); } if ( alternateUser.Length() > 0 ) { // Set the alternate user in the socket m_pSocket->SetAlternateUser( alternateUser ); } return m_pSocket; } int TSServer::Send( TSSocket* socket, const char* str, int len /*=0*/ ) { errorMsg = ""; TSClearLastError(); TSSetLastErrorMessage( "" ); // Send can only return 0, 1 or 2 due to the way the methods // that call it are checking Send's return value ... if ( !Send() ). // 0 == error, 1 == success with error message set, 2 == success. int code = -1; int nTimes = 0; char errmsg[80]; if ( len == 0 ) { len = strlen( str ); } while ( code != 200 ) { if ( socket->Send( str, len ) == SOCKET_ERROR ) { // If we are using the keep-alive socket and we failed, // we probably just timed-out. Try to open a new socket. if ( ( socket == m_pSocket ) && ( nTimes == 0 ) ) { delete socket; m_pSocket = NULL; socket = GetSocket(); if ( socket == NULL ) { TSSetLastError( TS_SOCKET_CREATE_FAILED ); TSSetLastErrorMessage( "TSServer::Send: Failure to recreate socket" ); return 0; // error set in Open(Get)Socket } nTimes++; continue; } TSSetLastError( TS_SOCKET_WRITE_ERROR ); TSSetLastErrorMessage( "TSServer::Send: Failed twice" ); return 0; } if ( !socket->GetHttpStatusCode( code ) || ( code != 200 && code != 400 ) || ( nTimes++ > 10 ) ) { TSSetLastError( TS_SERVER_ERROR ); sprintf( errmsg, "Server Error: %d", code ); errorMsg = errmsg; TSAppendLastErrorMessage( errorMsg.GetBuffer( 0 ) ); return 0; } // Now this is some ugly code. Let me try to explain why I did // this. First of all, the only time I think we will get a 400 // error is when we have previously gotten a 12045 error when // trying to send an http request. This error occurs when the // certificate authority is unknown when connecting through // SSL (https). When this occurs, the only way I was able to // get it to work was to close down the socket connection and // re-open it. When re-opened, it appears to work correctly. // Don't ask me why, I don't know. I just happened upon this // as a solution. See BUG33627 if ( code == 400 ) { socket->Close(); socket->Connect( serverName.GetBuffer(), portNumber ); } } // The stuff coming across the socket looks like: // retCode, "errorMsg", result (s). // Send pulls out the retCode and errorMsg, and leaves // the result(s) for the function that called Send. // RetCode will equal either 1 (DB_ERRWITHRESULTS), or // 2 (DB_SUCCESS). This is set in CAppDbServer::SendErrors // If errorcount is > 0 it is set to 1, else it is set to 2. // If retCode equals 1, then errorMsg has also been set. The // message can be retrieved with GetLastErrorMessage(). // The FIRST result in result(s) is also set in CAppDbServer::SendErrors. // It is equal to SendErrors' second parameter and is typically // set equal to the result of whatever function was called, // e.g., result = pRec->AddRecord(...). // Any further results are set using other send methods, like // pRec->Send( pStream ) or list.Send( pStream ). int retCode; int nReturn = socket->ReceiveInt( &retCode );// retCode will be a 1 or 2 if ( retCode == 0 ) { nReturn = socket->ReceiveString( &errorMsg ); if ( nReturn != TS_OK ) { // Set the error message since we did not get one from the server. errorMsg = "Socket error from initial Send() return code.\n"; errorMsg += "One reason might be your database needs upgrading.\n"; errorMsg += "Check event viewer if possible.\n"; } TSSetLastError( TS_SOCKET_READ_ERROR ); TSAppendLastErrorMessage( errorMsg.GetBuffer( 0 ) ); TSAppendLastErrorMessage( "TSServer::Send: Initial retCode from Server was 0" ); return 0; // Don't return TSGetLastError() here. } if ( nReturn != TS_OK ) { // TSErrorCode is set in ReceiveInt() sprintf( errmsg, "Failure to receive initial retCode from ReceiveInt: %d", nReturn ); errorMsg = errmsg; TSAppendLastErrorMessage( errorMsg.GetBuffer( 0 ) ); return 0; } nReturn = socket->ReceiveString( &errorMsg ); if ( retCode == 1 ) { if ( nReturn != TS_OK ) { // TSErrorCode is set in ReceiveString() sprintf( errmsg, "Failure to receive error message: %d", nReturn ); errorMsg = errmsg; TSAppendLastErrorMessage( errorMsg.GetBuffer( 0 ) ); TSAppendLastErrorMessage( "TSServer::Send: Initial retCode from Server was 1" ); return 0; } else { TSAppendLastErrorMessage( errorMsg.GetBuffer( 0 ) ); TSAppendLastErrorMessage( "TSServer::Send: Initial retCode from Server was 1" ); } } return retCode; // Either a 1 or a 2 } /******************************************************************** DATA ACCESS FUNCTIONS ********************************************************************/ int TSServer::AddField( TSRecord* field, int tableId, int fieldType, int& fieldId ) { // This function will add a record to the FIELDS table. The // tableId parameter will be used to set the TS_TABLEID field // in the new record. There is no need to set this value before // passing it into this function. // The return value is a TS_xxx error code. // NOTE: A return of TS_OK does not necessarily indicate a success // ALWAYS check the fieldId. // The fieldId will be 0 if failed, otherwise it's the TS_ID // for the new FIELDS table record. if ( !field || !field->IsInitialized ( TS_TBLID_FIELDS ) ) { TSSetLastError( TS_INVALID_PARAMETERS ); TSAppendLastErrorMessage( "TSServer::AddField: Invalid parameter (field)" ); return TSGetLastError(); } if ( !( ( fieldType == TS_FLDTYPE_NUMERIC ) || ( fieldType == TS_FLDTYPE_TEXT ) || ( fieldType == TS_FLDTYPE_MEMO ) || ( fieldType == TS_FLDTYPE_DATETIME ) || ( fieldType == TS_FLDTYPE_SELECTION ) || ( fieldType == TS_FLDTYPE_BINARY ) || ( fieldType == TS_FLDTYPE_STATE ) || ( fieldType == TS_FLDTYPE_USER ) || ( fieldType == TS_FLDTYPE_PROJECT ) || ( fieldType == TS_FLDTYPE_SUMMATION ) || ( fieldType == TS_FLDTYPE_MULTIPLE_SELECTION ) || ( fieldType == TS_FLDTYPE_CONTACT ) || ( fieldType == TS_FLDTYPE_INCIDENT ) || ( fieldType == TS_FLDTYPE_FOLDER ) || ( fieldType == TS_FLDTYPE_KEYWORDLIST ) || ( fieldType == TS_FLDTYPE_PRODUCTLIST ) || ( fieldType == TS_FLDTYPE_RELATIONAL ) || ( fieldType == TS_FLDTYPE_SUBRELATIONAL ) || ( fieldType == TS_FLDTYPE_SYSTEM ) || ( fieldType == TS_FLDTYPE_MULTIPLE_RELATIONAL ))) { TSSetLastError( TS_INVALID_PARAMETERS ); TSAppendLastErrorMessage( "TSServer::AddField: Invalid fieldType argument" ); return TSGetLastError(); } // Set the tableid in the record if ( field->SetInt( "tableid", tableId ) != TS_OK ) { // TSErrorCode is set in SetInt() TSAppendLastErrorMessage( "TSServer::AddField: Failure in SetInt" ); return TSGetLastError(); } if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::AddField: Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=AddField2&Params="; TSEncodeInt( fieldType, params ); s += params; field->SocketString( params ); s += params; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::AddField: Failed to Send" ); return TSGetLastError(); } fieldId = 0; int nResult; if ( m_pSocket->ReceiveInt( &nResult ) == TS_OK ) { if ( nResult > 0 ) { fieldId = nResult; } else if ( nResult == 0 ) { errorMsg = "Could not add to database."; TSSetLastError( TS_ERROR ); TSAppendLastErrorMessage( errorMsg.GetBuffer() ); } else if ( nResult == TS_INVALID_PARAMETERS ) { errorMsg = "'tableId' must refer to a primary or auxiliary table."; TSSetLastError( TS_INVALID_PARAMETERS ); TSAppendLastErrorMessage( errorMsg.GetBuffer() ); } else if ( nResult == TS_PARAMETER_NOT_UNIQUE ) { errorMsg = "Field already exists."; TSSetLastError( TS_INVALID_PARAMETERS ); TSAppendLastErrorMessage( errorMsg.GetBuffer() ); } } return TSGetLastError(); } int TSServer::AddRecord( TSRecord* rec, TSRecord* newRecord /*=NULL*/ ) { if ( !rec || !rec->IsInitialized() ) { TSSetLastError( TS_INVALID_PARAMETERS ); TSAppendLastErrorMessage( "TSServer::AddRecord: Invalid parameter (rec)" ); return TSGetLastError(); } if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::AddRecord: Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=AddRecord&Params="; TSEncodeInt( rec->tableId, params ); s += params; TSEncodeInt( rec->fieldType, params ); s += params; rec->SocketString( params ); s += params; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::AddRecord: Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::AddRecord: Failed to ReceiveInt" ); return TSGetLastError(); } if ( newRecord != NULL ) { if ( newRecord->Receive( m_pSocket ) != TS_OK ) { // TSErrorCode is set in Receive() TSAppendLastErrorMessage( "TSServer::AddRecord: Failed to Receive" ); return TSGetLastError(); } } else { TSRecord dummy( rec->tableId, this ); dummy.fieldType = rec->fieldType; if ( dummy.Receive( m_pSocket ) != TS_OK ) { // TSErrorCode is set in Receive() TSAppendLastErrorMessage( "TSServer::AddRecord: Failed to Receive (dummy)" ); return TSGetLastError(); } } return TS_OK; } int TSServer::AddTable( TSRecord* table, TSRecord* solution /*=NULL*/, int optionalFields /*=0*/, int reserved /*=0*/ ) { if ( !table || !table->IsInitialized( TS_TBLID_TABLES ) ) { TSSetLastError( TS_INVALID_PARAMETERS ); TSAppendLastErrorMessage( "TSServer::AddTable: Invalid parameter (table)" ); return TSGetLastError(); } if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::AddTable: Failed to GetSocket" ); return TSGetLastError(); } TSRecord localSolution( TS_TBLID_SOLUTIONS, this ); TSString s; TSString params; s = "Func=AddTable&Params="; table->SocketString( params ); s += params; if ( solution != NULL ) { solution->SocketString( params ); } else { localSolution.SocketString( params ); } s += params; TSEncodeInt( optionalFields, params ); s += params; TSEncodeInt( reserved, params ); s += params; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::AddTable: Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::AddTable: Failed to ReceiveInt" ); return TSGetLastError(); } if ( nResult <= 0 ) { if ( nResult == 0 ) nResult = TS_ERROR; TSSetLastError( nResult ); TSAppendLastErrorMessage( "TSServer::AddTable: Invalid result" ); return TSGetLastError(); } return TS_OK; } int TSServer::BuildFieldList( int tableId, TSFieldList& fieldList ) { TSSchema* schema = GetSchema( tableId ); if ( schema == NULL ) { // TSErrorCode is set in GetSchema() TSAppendLastErrorMessage( "TSServer::BuildFieldList: Invalid parameter (schema)" ); return TSGetLastError(); } if ( schema->fieldList.Duplicate( &fieldList ) != TS_OK ) { // TSErrorCode is set in Duplicate() TSAppendLastErrorMessage( "TSServer::BuildFieldList: Invalid parameter (fieldList)" ); return TSGetLastError(); } return TS_OK; } int TSServer::ClearAlternateUser() { // We need to release any license that the alternate user may be consuming if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::ClearAlternateUser: Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=ClearAlternateUser"; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::ClearAlternateUser: Failed to Send" ); return TSGetLastError(); } // Empty our version of the alternateUser so it is no longer sent // Note: do not do this until after the Send call alternateUser.Empty(); m_pSocket->ClearAlternateUser(); int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::ClearAlternateUser: Failed to ReceiveInt" ); return TSGetLastError(); } // nResult will be the error code, TS_OK on success if ( nResult != TS_OK ) { TSSetLastError( nResult ); TSAppendLastErrorMessage( "TSServer::ClearAlternateUser: Invalid result" ); return TSGetLastError(); } return TS_OK; } int TSServer::CreateIndex( int tableId, TSList *columnNames, const char *indexName) { TSString s, params; TSSocket* socket = OpenSocket(); if ( socket == NULL ) { return TSGetLastError(); } if( columnNames == NULL || indexName == NULL ) { delete socket; return TS_ERROR; } s = "Func=CreateIndex&Params="; TSEncodeInt( tableId, params ); s += params; TSEncodeInt( columnNames->Length(), params); s += params; for( TSPosition *pos = columnNames->GetFirst() ; pos != NULL; pos = columnNames->GetNext( pos ) ) { TSString *columnName = (TSString*)columnNames->GetAt( pos ); if( columnName ) { TSEncodeString( *columnName, params ); s += params; } } TSEncodeString( indexName, params ); s += params; if ( !Send( socket, s )) { delete socket; return TSGetLastError(); } int result; socket->ReceiveInt( &result ); delete socket; if ( !result ) { TSSetLastError( TS_ERROR ); return TS_ERROR; } return TS_OK; } int TSServer::DeleteRecord( int tableId, int id ) { if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::DeleteRecord: Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=DeleteRecord&Params="; TSEncodeInt( tableId, params ); s += params; TSEncodeInt( id, params ); s += params; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::DeleteRecord: Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::DeleteRecord: Failed to ReceiveInt" ); return TSGetLastError(); } if ( !nResult ) { TSSetLastError( TS_ERROR ); TSAppendLastErrorMessage( "TSServer::DeleteRecord: Invalid result" ); return TSGetLastError(); } return TS_OK; } int TSServer::DeleteIndex( int tableId, const char *indexName) { TSString s, params; TSSocket* socket = OpenSocket(); if ( socket == NULL ) { return TSGetLastError(); } s = "Func=DeleteIndex&Params="; TSEncodeInt( tableId, params ); s += params; TSEncodeString( indexName, params ); s += params; if ( !Send( socket, s )) { delete socket; return TSGetLastError(); } int result; socket->ReceiveInt( &result ); delete socket; if ( !result ) { TSSetLastError( TS_ERROR ); return TS_ERROR; } return TS_OK; } int TSServer::ExecuteSQL( TSString& sql ) { if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::ExecuteSQL: Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=ExecuteSQL&Params="; TSEncodeString( sql, params ); s += params; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::ExecuteSQL: Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::ExecuteSQL: Failed to ReceiveInt" ); return TSGetLastError(); } if ( !nResult ) { TSSetLastError( TS_ERROR ); TSAppendLastErrorMessage( "TSServer::ExecuteSQL: Invalid result" ); return TSGetLastError(); } return TS_OK; } int TSServer::GetConnectionInfo( char** dsn, char** databaseName, char** serverName ) { if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::GetConnectionInfo: Failed to GetSocket" ); return TSGetLastError(); } TSString s; s = "Func=GetConnectionInfo&Params="; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::GetConnectionInfo: Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::GetConnectionInfo: Failed to ReceiveInt" ); return TSGetLastError(); } if ( !nResult ) { TSSetLastError( TS_ERROR ); TSAppendLastErrorMessage( "TSServer::GetConnectionInfo: Invalid result" ); return TSGetLastError(); } TSString tmpStr; if ( m_pSocket->ReceiveString( &tmpStr ) != TS_OK ) { // TSErrorCode is set in ReceiveString() TSAppendLastErrorMessage( "TSServer::GetConnectionInfo: Failed to ReceiveString" ); return TSGetLastError(); } *dsn = new char[tmpStr.Length()+1]; if ( *dsn == NULL ) { TSSetLastError( TS_MEMORY_ERROR ); TSSetLastErrorMessage( "TSServer::GetConnectionInfo: Unable to allocate memory" ); return TSGetLastError(); } strcpy( *dsn, tmpStr.GetBuffer() ); tmpStr = ""; if ( m_pSocket->ReceiveString( &tmpStr ) != TS_OK ) { // TSErrorCode is set in ReceiveString() TSAppendLastErrorMessage( "TSServer::GetConnectionInfo: Failed to ReceiveString" ); return TSGetLastError(); } *databaseName = new char[tmpStr.Length()+1]; if ( *databaseName == NULL ) { TSSetLastError( TS_MEMORY_ERROR ); TSSetLastErrorMessage( "TSServer::GetConnectionInfo: Unable to allocate memory" ); return TSGetLastError(); } strcpy( *databaseName, tmpStr.GetBuffer() ); tmpStr = ""; if ( m_pSocket->ReceiveString( &tmpStr ) != TS_OK ) { // TSErrorCode is set in ReceiveString() TSAppendLastErrorMessage( "TSServer::GetConnectionInfo: Failed to ReceiveString" ); return TSGetLastError(); } *serverName = new char[tmpStr.Length()+1]; if ( *serverName == NULL ) { TSSetLastError( TS_MEMORY_ERROR ); TSSetLastErrorMessage( "TSServer::GetConnectionInfo: Unable to allocate memory" ); return TSGetLastError(); } strcpy( *serverName, tmpStr.GetBuffer() ); return TS_OK; } int TSServer::GetConnectionInfo( char* dsn, char* databaseName, char* serverName ) { if ( !dsn || ! databaseName || !serverName ) { TSSetLastError( TS_INVALID_PARAMETERS ); TSAppendLastErrorMessage( "TSServer::GetConnectionInfo: Invalid parameter" ); return TSGetLastError(); } if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::GetConnectionInfo: Failed to GetSocket" ); return TSGetLastError(); } TSString s; s = "Func=GetConnectionInfo&Params="; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::GetConnectionInfo: Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::GetConnectionInfo: Failed to ReceiveInt" ); return TSGetLastError(); } if ( !nResult ) { TSSetLastError( TS_ERROR ); TSAppendLastErrorMessage( "TSServer::GetConnectionInfo: Invalid result" ); return TSGetLastError(); } TSString tmpStr; if ( m_pSocket->ReceiveString( &tmpStr ) != TS_OK ) { // TSErrorCode is set in ReceiveString() TSAppendLastErrorMessage( "TSServer::GetConnectionInfo: Failed to ReceiveString" ); return TSGetLastError(); } strcpy( dsn, tmpStr.GetBuffer() ); tmpStr = ""; if ( m_pSocket->ReceiveString( &tmpStr ) != TS_OK ) { // TSErrorCode is set in ReceiveString() TSAppendLastErrorMessage( "TSServer::GetConnectionInfo: Failed to ReceiveString" ); return TSGetLastError(); } strcpy( databaseName, tmpStr.GetBuffer() ); tmpStr = ""; if ( m_pSocket->ReceiveString( &tmpStr ) != TS_OK ) { // TSErrorCode is set in ReceiveString() TSAppendLastErrorMessage( "TSServer::GetConnectionInfo: Failed to ReceiveString" ); return TSGetLastError(); } strcpy( serverName, tmpStr.GetBuffer() ); return TS_OK; } int TSServer::GetDbInfo( int infoType, void* out ) { if ( !out ) { TSSetLastError( TS_INVALID_PARAMETERS ); TSAppendLastErrorMessage( "TSServer::GetDbInfo: Invalid parameter (out)" ); return TSGetLastError(); } if ( infoType == TS_DBINFO_EXPIRATIONDATE ) { TSSetLastError( TS_INVALID_PARAMETERS ); TSAppendLastErrorMessage( "TSServer::GetDbInfo: Invalid parameter (infoType)" ); return TSGetLastError(); } if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::GetDbInfo: Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=GetDbInfo&Params="; TSEncodeInt( infoType, params ); s += params; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::GetDbInfo: Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::GetDbInfo: Failed to ReceiveInt" ); return TSGetLastError(); } if ( !nResult ) { TSSetLastError( TS_ERROR ); TSAppendLastErrorMessage( "TSServer::GetDbInfo: Invalid result" ); return TSGetLastError(); } int nReturn = 0; switch ( infoType ) { case TS_DBINFO_VERSION: case TS_DBINFO_ROOTPROJECTID: case TS_DBINFO_ROOTFOLDERID: case TS_DBINFO_OBJECTVERSION: case TS_DBINFO_DBMSVER: case TS_DBINFO_VARCHARLENGTH: case TS_DBINFO_LONGVARCHARLENGTH: case TS_DBINFO_ALLOWANONYMOUS: case TS_DBINFO_LITECOMPATIBLE: { nReturn = m_pSocket->ReceiveInt( static_cast( out )); break; } case TS_DBINFO_EXITURL: case TS_DBINFO_ROOTPROJECTNAME: case TS_DBINFO_DBMSNAME: case TS_DBINFO_DBMSVER_FULL: { *( static_cast( out )) = ""; nReturn = m_pSocket->ReceiveString( static_cast( out )); break; } default: break; } if ( nReturn != TS_OK ) { // TSErrorCode is set in ReceiveInt() and ReceiveString() TSAppendLastErrorMessage( "TSServer::GetDbInfo: Failed to Receive???" ); return TSGetLastError(); } return TS_OK; } int TSServer::GetIdentity( const TSString& sql, int& out ) { if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::GetIdentity: Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=GetIdentity&Params="; TSEncodeString( sql, params ); s += params; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::GetIdentity: Failed to Send" ); return TSGetLastError(); } if ( m_pSocket->ReceiveInt( &out ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::GetIdentity: Failed to ReceiveInt" ); } if ( errorMsg.Length() > 0 ) { TSSetLastError( TS_ERROR ); TSAppendLastErrorMessage( "TSServer::GetIdentity: Error in SQL Statement" ); } return TSGetLastError(); } int TSServer::GetIdentityString( const TSString& sql, TSString& out ) { if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::GetIdentityString: Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=GetIdentityString&Params="; TSEncodeString( sql, params ); s += params; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::GetIdentityString: Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::GetIdentityString: Failed to ReceiveInt" ); return TSGetLastError(); } if ( !nResult ) { TSSetLastError( TS_ERROR ); TSAppendLastErrorMessage( "TSServer::GetIdentityString: Invalid result" ); return TSGetLastError(); } // Receive the identity value. out = ""; if ( m_pSocket->ReceiveString( &out ) != TS_OK ) { // TSErrorCode is set in ReceiveString() TSAppendLastErrorMessage( "TSServer::GetIdentityString: Failed to ReceiveString" ); } if ( errorMsg.Length() > 0 ) { TSSetLastError( TS_ERROR ); TSAppendLastErrorMessage( "TSServer::GetIdentityString: Error in SQL Statement" ); } return TSGetLastError(); } int TSServer::GetInt( int tableId, const char* columnName, int recId, int* pInt ) { if ( !columnName || !pInt ) { TSSetLastError( TS_INVALID_PARAMETERS ); TSAppendLastErrorMessage( "TSServer::GetInt: Invalid parameter" ); return TSGetLastError(); } if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::GetInt: Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=GetInt&Params="; TSEncodeInt( tableId, params ); s += params; TSEncodeString( columnName, params ); s += params; TSEncodeInt( recId, params ); s += params; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::GetInt: Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() *pInt = 0; TSAppendLastErrorMessage( "TSServer::GetInt: Failed to ReceiveInt" ); return TSGetLastError(); } *pInt = nResult; // Don't check nResult since any value could be a valid result. // But if we have an error string, then something bad happened. if ( errorMsg.Length() > 0 ) { return TS_ERROR; } return TS_OK; } TSSchema* TSServer::GetSchema( int tableId ) { errorMsg = ""; TSClearLastError(); TSSetLastErrorMessage( "" ); TSSchema* schema; TSPosition* pos = schemaCache.GetFirst(); while ( pos ) { schema = static_cast( schemaCache.GetAt( pos )); if ( schema->tableId == tableId ) { return schema; } pos = schemaCache.GetNext(pos); } // Must not have found the schema for this record type. // Send a message to the server to retrieve it. TSSocket* socket = OpenSocket(); if ( socket == NULL ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::GetSchema: Failed to OpenSocket" ); return NULL; } TSString s; TSString params; s = "Func=ReadSchema&Params="; TSEncodeInt( tableId, params ); s += params; if ( !Send( socket, s ) ) { // TSErrorCode is set in Send() delete socket; TSAppendLastErrorMessage( "TSServer::GetSchema: Failed to Send" ); return NULL; } int nResult; if ( socket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() delete socket; TSAppendLastErrorMessage( "TSServer::GetSchema: Failed to ReceiveInt" ); return NULL; } if ( nResult != TS_OK ) { TSSetLastError( nResult ); TSAppendLastErrorMessage( "TSServer::GetSchema: Invalid result (tableId not found)" ); delete socket; return NULL; } // Receive the id, name and count. int count; int id; TSString name; schema = new TSSchema; if ( schema ) { schema->tableId = tableId; } else { TSSetLastError( TS_MEMORY_ERROR ); TSSetLastErrorMessage( "TSServer::GetSchema: Unable to allocate memory (schema)" ); delete socket; return NULL; } if ( socket->ReceiveInt( &id ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() delete schema; delete socket; TSAppendLastErrorMessage( "TSServer::GetSchema: Failed to ReceiveInt" ); return NULL; } if ( socket->ReceiveString( &schema->name ) != TS_OK ) { // TSErrorCode is set in ReceiveString() delete schema; delete socket; TSAppendLastErrorMessage( "TSServer::GetSchema: Failed to ReceiveString" ); return NULL; } if ( socket->ReceiveInt( &schema->userDefinedFields ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() delete schema; delete socket; TSAppendLastErrorMessage( "TSServer::GetSchema: Failed to ReceiveInt" ); return NULL; } if ( socket->ReceiveInt( &count ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() delete schema; delete socket; TSAppendLastErrorMessage( "TSServer::GetSchema: Failed to ReceiveInt" ); return NULL; } TSField* field; for ( int ii = 0; ii < count; ii++ ) { field = new TSField(); if ( field ) { if ( field->ReceiveSchema( socket ) != TS_OK ) { // TSErrorCode is set in ReceiveSchema() TSAppendLastErrorMessage( "TSServer::GetSchema: Failed to ReceiveSchema" ); delete field; delete schema; delete socket; return NULL; } } else { TSSetLastError( TS_MEMORY_ERROR ); TSSetLastErrorMessage( "TSServer::GetSchema: Unable to allocate memory (field)" ); delete schema; delete socket; return NULL; } if ( schema->fieldList.AddTail( field ) != TS_OK ) { // TSErrorCode is set in AddTail() TSAppendLastErrorMessage( "TSServer::GetSchema: Failed to AddTail" ); delete field; delete schema; delete socket; return NULL; } } if ( schemaCache.AddHead( schema ) != TS_OK ) { // TSErrorCode is set in AddHead() TSAppendLastErrorMessage( "TSServer::GetSchema: Failed to AddHead" ); delete schema; delete socket; return NULL; } delete socket; return schema; } int TSServer::GetPrivilegeName( enum privId_e privId, char** privName ) { if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::GetPrivilegeName: Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=GetPrivilegeName&Params="; TSEncodeInt( privId, params ); s += params; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::GetPrivilegeName: Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::GetPrivilegeName: Failed to ReceiveInt" ); return TSGetLastError(); } if ( !nResult ) { TSSetLastError( TS_ERROR ); TSAppendLastErrorMessage( "TSServer::GetPrivilegeName: Invalid result" ); return TSGetLastError(); } TSString tmpStr; if ( m_pSocket->ReceiveString( &tmpStr ) != TS_OK ) { // TSErrorCode is set in ReceiveString() TSAppendLastErrorMessage( "TSServer::GetPrivilegeName: Failed to ReceiveString" ); return TSGetLastError(); } if ( tmpStr.Length() > 0 ) { *privName = new char[tmpStr.Length() + 1]; if ( *privName == NULL ) { TSSetLastError( TS_MEMORY_ERROR ); TSSetLastErrorMessage( "TSServer::GetPrivilegeName: Unable to allocate memory" ); return TSGetLastError(); } strcpy( *privName, tmpStr.GetBuffer() ); } else { *privName = NULL; } return TS_OK; } int TSServer::GetProjectList( int nTableId, int nProjectsMask, TSProjectList& projectList ) { TSProject* pProject; while ( projectList.size() > 0 ) { pProject = projectList.front(); projectList.pop_front(); delete pProject; } if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::GetProjectList: Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=TSGetProjectList&Params="; TSEncodeInt( nTableId, params ); s += params; TSEncodeInt( nProjectsMask, params ); s += params; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::GetProjectList: Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::GetProjectList: Failed to ReceiveInt" ); return TSGetLastError(); } if ( nResult != TS_OK ) { TSSetLastError( nResult ); TSAppendLastErrorMessage( "TSServer::GetProjectList: Invalid result" ); return TSGetLastError(); } int nErrCode = TS_OK; while ( nErrCode == TS_OK ) { TSProject* pProject = new TSProject( *this ); if ( pProject ) { nErrCode = pProject->Receive( m_pSocket ); if ( nErrCode != TS_OK ) { delete pProject; break; } projectList.push_back( pProject ); } else { TSSetLastError( TS_MEMORY_ERROR ); TSSetLastErrorMessage( "TSServer::GetProjectList: Unable to allocate memory" ); return TSGetLastError(); } } return TS_OK; } int TSServer::GetString( int tableId, const char* columnName, int recId, char** string ) { if ( !columnName ) { TSSetLastError( TS_INVALID_PARAMETERS ); TSAppendLastErrorMessage( "TSServer::GetString: Invalid parameter (columnName)" ); return TSGetLastError(); } if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::GetString: Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=GetString&Params="; TSEncodeInt( tableId, params ); s += params; TSEncodeString( columnName, params ); s += params; TSEncodeInt( recId, params ); s += params; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::GetString: Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::GetString: Failed to ReceiveInt" ); return TSGetLastError(); } if ( !nResult ) { TSSetLastError( TS_ERROR ); TSAppendLastErrorMessage( "TSServer::GetString: Invalid result" ); return TSGetLastError(); } TSString tmpStr; if ( m_pSocket->ReceiveString( &tmpStr ) != TS_OK ) { // TSErrorCode is set in ReceiveString() TSAppendLastErrorMessage( "TSServer::GetString: Failed to ReceiveString" ); return TSGetLastError(); } if ( tmpStr.Length() > 0 ) { *string = new char[tmpStr.Length() + 1]; if ( *string == NULL ) { TSSetLastErrorMessage( "TSServer::GetString: Unable to allocate memory" ); TSSetLastError( TS_MEMORY_ERROR ); return TSGetLastError(); } strcpy( *string, tmpStr.GetBuffer() ); } else { *string = NULL; } // An empty string could be a valid result. // But if we have an error string, then something bad happened. if ( errorMsg.Length() > 0 ) { TSSetLastError( TS_INVALID_PARAMETERS ); return TSGetLastError(); } return TS_OK; } int TSServer::GetString( int tableId, const char* columnName, int recId, char* string, int size ) { if ( !columnName || !string ) { TSSetLastError( TS_INVALID_PARAMETERS ); TSAppendLastErrorMessage( "TSServer::GetString: Invalid parameter" ); return TSGetLastError(); } char* tmp; if ( GetString( tableId, columnName, recId, &tmp ) != TS_OK ) { delete [] tmp; tmp = 0; // TSErrorCode is set in GetString() return TSGetLastError(); } strncpy( string, tmp, size ); delete [] tmp; tmp = 0; return TS_OK; } int TSServer::GetSubmitTransition( int projectId, int* id ) { if ( !id ) { TSSetLastError( TS_INVALID_PARAMETERS ); TSAppendLastErrorMessage( "TSServer::GetSubmitTransition: Invalid parameter (id)" ); return TSGetLastError(); } if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::GetSubmitTransition: Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=GetSubmitTransition&Params="; TSEncodeInt( projectId, params ); s += params; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::GetSubmitTransition: Failed to Send" ); return TSGetLastError(); } if ( m_pSocket->ReceiveInt( id ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::GetSubmitTransition: Failed to ReceiveInt" ); return TSGetLastError(); } return TS_OK; } int TSServer::GetTableIdByDatabaseNameEx( const char* tableDbName, int* tableId ) { if ( !tableDbName ) { TSSetLastError( TS_INVALID_PARAMETERS ); TSAppendLastErrorMessage( "TSServer::GetTableIdByDatabaseNameEx: Invalid parameter (tableDbName)" ); return TSGetLastError(); } if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::GetTableIdByDatabaseNameEx: Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=GetTableIdByDatabaseNameEx&Params="; TSEncodeString( tableDbName, params ); s += params; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::GetTableIdByDatabaseNameEx: Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() *tableId = 0; TSAppendLastErrorMessage( "TSServer::GetTableIdByDatabaseNameEx: Failed to ReceiveInt" ); return TSGetLastError(); } *tableId = nResult; return TS_OK; } int TSServer::HasPrivilege( int userId, int projectId, int maskNumber, int mask ) { if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::HasPrivilege: Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=HasPrivilege&Params="; TSEncodeInt( userId, params ); s += params; TSEncodeInt( projectId, params ); s += params; TSEncodeInt( maskNumber, params ); s += params; TSEncodeInt( mask, params ); s += params; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::HasPrivilege: Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::HasPrivilege: Failed to ReceiveInt" ); return TSGetLastError(); } if ( !nResult ) { TSSetLastError( TS_ERROR ); TSAppendLastErrorMessage( "TSServer::HasPrivilege: Invalid result" ); return TSGetLastError(); } return TS_OK; } int TSServer::HasGroupPrivilege( int groupId, int itemId, enum privId_e privId ) { if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::HasGroupPrivilege: Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=HasGroupPrivilege&Params="; TSEncodeInt( groupId, params ); s += params; TSEncodeInt( itemId, params ); s += params; TSEncodeInt( privId, params ); s += params; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::HasGroupPrivilege: Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::HasGroupPrivilege: Failed to ReceiveInt" ); return TSGetLastError(); } if ( !nResult ) { TSSetLastError( TS_ERROR ); TSAppendLastErrorMessage( "TSServer::HasGroupPrivilege: Invalid result" ); return TSGetLastError(); } return TS_OK; } int TSServer::HasUserPrivilege( int userId, int itemId, enum privId_e privId ) { if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::HasUserPrivilege: Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=HasUserPrivilege&Params="; TSEncodeInt( userId, params ); s += params; TSEncodeInt( itemId, params ); s += params; TSEncodeInt( privId, params ); s += params; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::HasUserPrivilege: Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::HasUserPrivilege: Failed to ReceiveInt" ); return TSGetLastError(); } if ( !nResult ) { TSSetLastError( TS_ERROR ); TSAppendLastErrorMessage( "TSServer::HasUserPrivilege: Invalid result" ); return TSGetLastError(); } return TS_OK; } int TSServer::HasRecordPrivilege( enum recPriv_e recPriv, int userId, int tableId, int recId ) { if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::HasRecordPrivilege: Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=HasRecordPrivilege&Params="; TSEncodeInt( recPriv, params ); s += params; TSEncodeInt( userId, params ); s += params; TSEncodeInt( tableId, params ); s += params; TSEncodeInt( recId, params ); s += params; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::HasRecordPrivilege: Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::HasRecordPrivilege: Failed to ReceiveInt" ); return TSGetLastError(); } if ( !nResult ) { TSSetLastError( TS_ERROR ); TSAppendLastErrorMessage( "TSServer::HasRecordPrivilege: Invalid result" ); return TSGetLastError(); } return TS_OK; } int TSServer::HasValidLicense( const char* solutionIdent ) { if ( !solutionIdent ) { TSSetLastError( TS_INVALID_PARAMETERS ); TSAppendLastErrorMessage( "TSServer::HasValidLicense: Invalid parameter (solutionIdent)" ); return TSGetLastError(); } if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::HasValidLicense: Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=HasValidLicense&Params="; TSEncodeString( solutionIdent, params ); s += params; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::HasValidLicense: Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::HasValidLicense: Failed to ReceiveInt" ); return TSGetLastError(); } if ( !nResult ) { TSSetLastError( TS_ERROR ); TSAppendLastErrorMessage( "TSServer::HasValidLicense: Invalid result" ); return TSGetLastError(); } return TS_OK; } int TSServer::MoveFolder( int folderId, int newParentId, int position ) { if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::MoveFolder: Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=MoveFolder&Params="; TSEncodeInt( folderId, params ); s += params; TSEncodeInt( newParentId, params ); s += params; TSEncodeInt( position, params ); s += params; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::MoveFolder: Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::MoveFolder: Failed to ReceiveInt" ); return TSGetLastError(); } if ( !nResult ) { TSSetLastError( TS_ERROR ); TSAppendLastErrorMessage( "TSServer::MoveFolder: Invalid result" ); return TSGetLastError(); } return TS_OK; } int TSServer::MoveProject( int projectId, int newParentId, int position ) { if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::MoveProject: Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=MoveProject&Params="; TSEncodeInt( projectId, params ); s += params; TSEncodeInt( newParentId, params ); s += params; TSEncodeInt( position, params ); s += params; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::MoveProject: Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::MoveProject: Failed to ReceiveInt" ); return TSGetLastError(); } if ( !nResult ) { TSSetLastError( TS_ERROR ); TSAppendLastErrorMessage( "TSServer::MoveProject: Invalid result" ); return TSGetLastError(); } return TS_OK; } int TSServer::ReadAllRecords( TSRecordList* list, int tableId ) { if ( !list ) { TSSetLastError( TS_INVALID_PARAMETERS ); TSAppendLastErrorMessage( "TSServer::ReadAllRecords: Invalid parameter (list)" ); return TSGetLastError(); } if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::ReadAllRecords: Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=ReadAllRecords&Params="; TSEncodeInt( tableId, params ); s += params; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::ReadAllRecords: Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::ReadAllRecords: Failed to ReceiveInt" ); return TSGetLastError(); } if ( !nResult ) { TSSetLastError( TS_ERROR ); TSAppendLastErrorMessage( "TSServer::ReadAllRecords: Invalid result" ); return TSGetLastError(); } if ( list->Receive( this, m_pSocket ) != TS_OK ) { // TSErrorCode is set in Receive() TSAppendLastErrorMessage( "TSServer::ReadAllRecords: Failed to Receive" ); return TSGetLastError(); } return TS_OK; } int TSServer::ReadAttachmentList( TSRecordList* list, int tableId, int recId ) { if ( !list ) { TSSetLastError( TS_INVALID_PARAMETERS ); TSAppendLastErrorMessage( "TSServer::ReadAttachmentList: Invalid parameter (list)" ); return TSGetLastError(); } if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::ReadAttachmentList: Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=ReadAttachmentList&Params="; TSEncodeInt( tableId, params ); s += params; TSEncodeInt( recId, params ); s += params; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::ReadAttachmentList: Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::ReadAttachmentList: Failed to ReceiveInt" ); return TSGetLastError(); } if ( !nResult ) { TSSetLastError( TS_ERROR ); TSAppendLastErrorMessage( "TSServer::ReadAttachmentList: Invalid result" ); return TSGetLastError(); } if ( list->Receive( this, m_pSocket ) != TS_OK ) { // TSErrorCode is set in Receive() TSAppendLastErrorMessage( "TSServer::ReadAttachmentList: Failed to Receive" ); return TSGetLastError(); } return TS_OK; } int TSServer::ReadAvailableTransitionList( TSRecordList* list, int tableId, int recId ) { if ( !list ) { TSSetLastError( TS_INVALID_PARAMETERS ); TSAppendLastErrorMessage( "TSServer::ReadAvailableTransitionList: Invalid parameter (list)" ); return TSGetLastError(); } if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::ReadAvailableTransitionList: Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=ReadAvailableTransitionList&Params="; TSEncodeInt( tableId, params ); s += params; TSEncodeInt( recId, params ); s += params; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::ReadAvailableTransitionList: Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::ReadAvailableTransitionList: Failed to ReceiveInt" ); return TSGetLastError(); } if ( !nResult ) { TSSetLastError( TS_ERROR ); TSAppendLastErrorMessage( "TSServer::ReadAvailableTransitionList: Invalid result" ); return TSGetLastError(); } if ( list->Receive( this, m_pSocket ) != TS_OK ) { // TSErrorCode is set in Receive() TSAppendLastErrorMessage( "TSServer::ReadAvailableTransitionList: Failed to Receive" ); return TSGetLastError(); } return TS_OK; } int TSServer::ReadChangeList( TSRecordList* list, int caseId, BOOL newFirst /*=FALSE*/ ) { // This method was a hold-over from version 3.0 wherein TS_CASES was the only // table for which changes were tracked. Now that the Changes table holds data // for serveral tables, we must now specify which one. Use ReadChangeList2. return ReadChangeList2( list, TS_TBLID_CASES, caseId, newFirst ); } int TSServer::ReadChangeList2( TSRecordList* list, int tableId, int itemId, BOOL newFirst /*=FALSE*/ ) { if ( !list ) { TSSetLastError( TS_INVALID_PARAMETERS ); TSAppendLastErrorMessage( "TSServer::ReadChangeList: Invalid parameter (list)" ); return TSGetLastError(); } if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::ReadChangeList: Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=ReadChangeList&Params="; TSEncodeInt( tableId, params ); s += params; TSEncodeInt( itemId, params ); s += params; TSEncodeInt( newFirst, params ); s += params; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::ReadChangeList: Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::ReadChangeList: Failed to ReceiveInt" ); return TSGetLastError(); } if ( !nResult ) { TSSetLastError( TS_ERROR ); TSAppendLastErrorMessage( "TSServer::ReadChangeList: Invalid result" ); return TSGetLastError(); } if ( list->Receive( this, m_pSocket ) != TS_OK ) { // TSErrorCode is set in Receive() TSAppendLastErrorMessage( "TSServer::ReadChangeList: Failed to Receive" ); return TSGetLastError(); } return TS_OK; } int TSServer::ReadFieldsByProject( TSRecordList* list, int projectId ) { if ( !list ) { TSSetLastError( TS_INVALID_PARAMETERS ); TSAppendLastErrorMessage( "TSServer::ReadFieldsByProject: Invalid parameter (list)" ); return TSGetLastError(); } if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::ReadFieldsByProject: Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=ReadFieldsByProject&Params="; TSEncodeInt( projectId, params ); s += params; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::ReadFieldsByProject: Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::ReadFieldsByProject: Failed to ReceiveInt" ); return TSGetLastError(); } if ( !nResult ) { TSSetLastError( TS_ERROR ); TSAppendLastErrorMessage( "TSServer::ReadFieldsByProject: Invalid result" ); return TSGetLastError(); } if ( list->Receive( this, m_pSocket ) != TS_OK ) { // TSErrorCode is set in Receive() TSAppendLastErrorMessage( "TSServer::ReadFieldsByProject: Failed to Receive" ); return TSGetLastError(); } return TS_OK; } int TSServer::ReadFieldsByWorkflow( TSRecordList* list, int workflowId ) { if ( !list ) { TSSetLastError( TS_INVALID_PARAMETERS ); TSAppendLastErrorMessage( "TSServer::ReadFieldsByWorkflow: Invalid parameter (list)" ); return TSGetLastError(); } if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::ReadFieldsByWorkflow: Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=ReadFieldsByWorkflow&Params="; TSEncodeInt( workflowId, params ); s += params; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::ReadFieldsByWorkflow: Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::ReadFieldsByWorkflow: Failed to ReceiveInt" ); return TSGetLastError(); } if ( !nResult ) { TSSetLastError( TS_ERROR ); TSAppendLastErrorMessage( "TSServer::ReadFieldsByWorkflow: Invalid result" ); return TSGetLastError(); } if ( list->Receive( this, m_pSocket ) != TS_OK ) { // TSErrorCode is set in Receive() TSAppendLastErrorMessage( "TSServer::ReadFieldsByWorkflow: Failed to Receive" ); return TSGetLastError(); } return TS_OK; } int TSServer::ReadFolderItems( TSRecordList* list, int folderId ) { if ( !list ) { TSSetLastError( TS_INVALID_PARAMETERS ); TSAppendLastErrorMessage( "TSServer::ReadFolderItems: Invalid parameter (list)" ); return TSGetLastError(); } if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::ReadFolderItems: Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=ReadFolderItems&Params="; TSEncodeInt( folderId, params ); s += params; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::ReadFolderItems: Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::ReadFolderItems: Failed to ReceiveInt" ); return TSGetLastError(); } if ( !nResult ) { TSSetLastError( TS_ERROR ); TSAppendLastErrorMessage( "TSServer::ReadFolderItems: Invalid result" ); return TSGetLastError(); } if ( list->Receive( this, m_pSocket ) != TS_OK ) { // TSErrorCode is set in Receive() TSAppendLastErrorMessage( "TSServer::ReadFolderItems: Failed to Receive" ); return TSGetLastError(); } return TS_OK; } int TSServer::ReadFolderList( TSRecordList* list, int owner, int parentId ) { if ( !list ) { TSSetLastError( TS_INVALID_PARAMETERS ); TSAppendLastErrorMessage( "TSServer::ReadFolderList: Invalid parameter (list)" ); return TSGetLastError(); } if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::ReadFolderList: Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=ReadFolderList&Params="; TSEncodeInt( owner, params ); s += params; TSEncodeInt( parentId, params ); s += params; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::ReadFolderList: Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::ReadFolderList: Failed to ReceiveInt" ); return TSGetLastError(); } if ( !nResult ) { TSSetLastError( TS_ERROR ); TSAppendLastErrorMessage( "TSServer::ReadFolderList: Invalid result" ); return TSGetLastError(); } if ( list->Receive( this, m_pSocket ) != TS_OK ) { // TSErrorCode is set in Receive() TSAppendLastErrorMessage( "TSServer::ReadFolderList: Failed to Receive" ); return TSGetLastError(); } return TS_OK; } int TSServer::ReadProjectSelectionList( TSRecordList* list, int selectid ) { if ( !list ) { TSSetLastError( TS_INVALID_PARAMETERS ); TSAppendLastErrorMessage( "TSServer::ReadProjectSelectionList: Invalid parameter (list)" ); return TSGetLastError(); } if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::ReadProjectSelectionList: Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=ReadProjectSelectionList&Params="; TSEncodeInt( selectid, params ); s += params; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::ReadProjectSelectionList: Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::ReadProjectSelectionList: Failed to ReceiveInt" ); return TSGetLastError(); } if ( !nResult ) { TSSetLastError( TS_ERROR ); TSAppendLastErrorMessage( "TSServer::ReadProjectSelectionList: Invalid result" ); return TSGetLastError(); } if ( list->Receive( this, m_pSocket ) != TS_OK ) { // TSErrorCode is set in Receive() TSAppendLastErrorMessage( "TSServer::ReadProjectSelectionList: Failed to Receive" ); return TSGetLastError(); } return TS_OK; } int TSServer::ReadProjectTransitionList( TSRecordList* list, int transId ) { if ( !list ) { TSSetLastError( TS_INVALID_PARAMETERS ); TSAppendLastErrorMessage( "TSServer::ReadProjectTransitionList: Invalid parameter (list)" ); return TSGetLastError(); } if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::ReadProjectTransitionList: Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=ReadProjectTransitionList&Params="; TSEncodeInt( transId, params ); s += params; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::ReadProjectTransitionList: Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::ReadProjectTransitionList: Failed to ReceiveInt" ); return TSGetLastError(); } if ( !nResult ) { TSSetLastError( TS_ERROR ); TSAppendLastErrorMessage( "TSServer::ReadProjectTransitionList: Invalid result" ); return TSGetLastError(); } if ( list->Receive( this, m_pSocket ) != TS_OK ) { // TSErrorCode is set in Receive() TSAppendLastErrorMessage( "TSServer::ReadProjectTransitionList: Failed to Receive" ); return TSGetLastError(); } return TS_OK; } int TSServer::ReadPropertyList( TSRecordList* list, int transId ) { if ( !list ) { TSSetLastError( TS_INVALID_PARAMETERS ); TSAppendLastErrorMessage( "TSServer::ReadPropertyList: Invalid parameter (list)" ); return TSGetLastError(); } if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::ReadPropertyList: Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=ReadPropertyList&Params="; TSEncodeInt( transId, params ); s += params; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::ReadPropertyList: Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::ReadPropertyList: Failed to ReceiveInt" ); return TSGetLastError(); } if ( !nResult ) { TSSetLastError( TS_ERROR ); TSAppendLastErrorMessage( "TSServer::ReadPropertyList: Invalid result" ); return TSGetLastError(); } if ( list->Receive( this, m_pSocket ) != TS_OK ) { // TSErrorCode is set in Receive() TSAppendLastErrorMessage( "TSServer::ReadPropertyList: Failed to Receive" ); return TSGetLastError(); } return TS_OK; } int TSServer::ReadRecord( TSRecord* rec, int id ) { if ( !rec || !rec->IsInitialized() ) { TSSetLastError( TS_INVALID_PARAMETERS ); TSAppendLastErrorMessage( "TSServer::ReadRecord: Invalid parameter (rec)" ); return TSGetLastError(); } if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::ReadRecord: Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=ReadRecord&Params="; TSEncodeInt( rec->tableId, params ); s += params; TSEncodeInt( rec->fieldType, params ); s += params; TSEncodeInt( id, params ); s += params; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::ReadRecord: Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::ReadRecord: Failed to ReceiveInt" ); return TSGetLastError(); } if ( !nResult ) { TSSetLastError( TS_ERROR ); TSAppendLastErrorMessage( "TSServer::ReadRecord: Invalid result" ); return TSGetLastError(); } // Only ignore non-db fields if we are reading the fields table // Server side only sends db & core fields if ( rec->Receive( m_pSocket, ( rec->tableId == TS_TBLID_FIELDS && rec->fieldType == 0 ) ) != TS_OK ) { // TSErrorCode is set in Receive() TSAppendLastErrorMessage( "TSServer::ReadRecord: Failed to Receive" ); return TSGetLastError(); } return TS_OK; } int TSServer::ReadRecordByItemNumber( TSRecord* pRec, TSString sItemNumber, int nProjectId ) { if ( !pRec || !pRec->IsInitialized() ) { TSSetLastError( TS_INVALID_PARAMETERS ); TSAppendLastErrorMessage( "TSServer::ReadRecordByItemNumber: Invalid parameter (pRec)" ); return TSGetLastError(); } if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::ReadRecordByItemNumber: Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=ReadRecordByItemNumber&Params="; TSEncodeString( sItemNumber, params ); s += params; TSEncodeInt( nProjectId, params ); s += params; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::ReadRecordByItemNumber: Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::ReadRecordByItemNumber: Failed to ReceiveInt" ); return TSGetLastError(); } if ( !nResult ) { TSSetLastError( TS_ERROR ); TSAppendLastErrorMessage( "TSServer::ReadRecordByItemNumber: Invalid result" ); return TSGetLastError(); } if ( pRec->Receive( m_pSocket ) != TS_OK ) { // TSErrorCode is set in Receive() TSAppendLastErrorMessage( "TSServer::ReadRecordByItemNumber: Failed to Receive" ); return TSGetLastError(); } return TS_OK; } int TSServer::ReadRecordForId( TSRecord* record, const char* searchId ) { if ( !record || !record->IsInitialized() || !searchId ) { TSSetLastError( TS_INVALID_PARAMETERS ); TSAppendLastErrorMessage( "TSServer::ReadRecordForId: Invalid parameter" ); return TSGetLastError(); } if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::ReadRecordForId: Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=ReadRecordForItemId&Params="; TSEncodeInt( record->tableId, params ); s += params; TSEncodeInt( record->fieldType, params ); s += params; TSEncodeString( searchId, params ); s += params; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::ReadRecordForId: Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::ReadRecordForId: Failed to ReceiveInt" ); return TSGetLastError(); } if ( !nResult ) { TSSetLastError( TS_ERROR ); TSAppendLastErrorMessage( "TSServer::ReadRecordForId: Invalid result" ); return TSGetLastError(); } // Only ignore non-db fields if we are reading the fields table // Server side only sends db & core fields if ( record->Receive( m_pSocket, ( record->tableId == TS_TBLID_FIELDS && record->fieldType == 0 ) ) != TS_OK ) { // TSErrorCode is set in Receive() TSAppendLastErrorMessage( "TSServer::ReadRecordForId: Failed to Receive" ); return TSGetLastError(); } return TS_OK; } int TSServer::ReadRecordListWithWhere( TSRecordList* list, int tableId, const char* whereClause ) { // Entry point need to flush the error message. TSSetLastErrorMessage( "" ); if ( !list || !whereClause ) { TSSetLastError( TS_INVALID_PARAMETERS ); TSAppendLastErrorMessage( "TSServer::ReadRecordListWithWhere: Invalid parameter" ); return TSGetLastError(); } if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::ReadRecordListWithWhere: Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=ReadListWithWhere&Params="; TSEncodeInt( tableId, params ); s += params; TSEncodeInt( 0, params ); s += params; TSEncodeInt( INT_MAX, params ); s += params; TSEncodeString( whereClause, params ); s += params; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::ReadRecordListWithWhere: Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::ReadRecordListWithWhere: Failed to ReceiveInt" ); return TSGetLastError(); } if ( !nResult ) { TSSetLastError( TS_ERROR ); TSAppendLastErrorMessage( "TSServer::ReadRecordListWithWhere: Invalid result" ); return TSGetLastError(); } if ( list->Receive( this, m_pSocket ) != TS_OK ) { // TSErrorCode is set in Receive() TSAppendLastErrorMessage( "TSServer::ReadRecordListWithWhere: Failed to Receive" ); return TSGetLastError(); } return TS_OK; } // Reads a record, filtering by the where clause and returning only the desired fields. int TSServer::ReadRecordListWithWhere( TSRecordList* list, int tableId, const char* whereClause, const std::vector& fields ) { // Entry point need to flush the error message. TSSetLastErrorMessage( "" ); if ( !list || !whereClause ) { TSSetLastError( TS_INVALID_PARAMETERS ); TSAppendLastErrorMessage( "TSServer::ReadRecordListWithWhere(2): Invalid parameter" ); return TSGetLastError(); } if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::ReadRecordListWithWhere(2): Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=ReadListSelectedFieldsWithWhere&Params="; TSEncodeInt( tableId, params ); s += params; TSEncodeInt( 0, params ); s += params; TSEncodeInt( INT_MAX, params ); s += params; TSEncodeString( whereClause, params ); s += params; // Encode the vector of selected fields. TSEncodeInt( fields.size(), params ); s += params; std::vector::const_iterator it = fields.begin(); while ( it != fields.end() ) { TSEncodeInt( *it, params ); s += params; it++; } if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::ReadRecordListWithWhere(2): Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::ReadRecordListWithWhere(2): Failed to ReceiveInt" ); return TSGetLastError(); } if ( !nResult ) { TSSetLastError( TS_ERROR ); TSAppendLastErrorMessage( "TSServer::ReadRecordListWithWhere(2): Invalid result" ); return TSGetLastError(); } if ( list->Receive( this, m_pSocket ) != TS_OK ) { // TSErrorCode is set in Receive() TSAppendLastErrorMessage( "TSServer::ReadRecordListWithWhere(2): Failed to Receive" ); return TSGetLastError(); } return TS_OK; } int TSServer::ReadRecordListWithWhere( TSRecordList* list, int tableId, int firstId, int maxRecords, const char* whereClause ) { // Entry point needs to flush the error message. TSSetLastErrorMessage( "" ); if ( !list || !whereClause ) { TSSetLastError( TS_INVALID_PARAMETERS ); TSAppendLastErrorMessage( "TSServer::ReadRecordListWithWhere(3): Invalid parameter" ); return TSGetLastError(); } if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::ReadRecordListWithWhere(3): Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=ReadListWithWhere&Params="; TSEncodeInt( tableId, params ); s += params; TSEncodeInt( firstId, params ); s += params; TSEncodeInt( maxRecords, params ); s += params; TSEncodeString( whereClause, params ); s += params; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::ReadRecordListWithWhere(3): Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::ReadRecordListWithWhere(3): Failed to ReceiveInt" ); return TSGetLastError(); } if ( !nResult ) { TSSetLastError( TS_ERROR ); TSAppendLastErrorMessage( "TSServer::ReadRecordListWithWhere(3): Invalid result" ); return TSGetLastError(); } if ( list->Receive( this, m_pSocket ) != TS_OK ) { // TSErrorCode is set in Receive() TSAppendLastErrorMessage( "TSServer::ReadRecordListWithWhere(3): Failed to Receive" ); return TSGetLastError(); } return TS_OK; } // Reads a record, filtering by the where clause and returning only the desired fields. int TSServer::ReadRecordListWithWhere( TSRecordList* list, int tableId, int firstId, int maxRecords, const char* whereClause, const std::vector& fields ) { // Entry point needs to flush the error message. TSSetLastErrorMessage( "" ); if ( !list || !whereClause ) { TSSetLastError( TS_INVALID_PARAMETERS ); TSAppendLastErrorMessage( "TSServer::ReadRecordListWithWhere(4): Invalid parameter" ); return TSGetLastError(); } if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::ReadRecordListWithWhere(4): Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=ReadListSelectedFieldsWithWhere&Params="; TSEncodeInt( tableId, params ); s += params; TSEncodeInt( firstId, params ); s += params; TSEncodeInt( maxRecords, params ); s += params; TSEncodeString( whereClause, params ); s += params; // Encode the vector of selected fields. TSEncodeInt( fields.size(), params ); s += params; std::vector::const_iterator it = fields.begin(); while ( it != fields.end() ) { TSEncodeInt( *it, params ); s += params; it++; } if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::ReadRecordListWithWhere(4): Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::ReadRecordListWithWhere(4): Failed to ReceiveInt" ); return TSGetLastError(); } if ( !nResult ) { TSSetLastError( TS_ERROR ); TSAppendLastErrorMessage( "TSServer::ReadRecordListWithWhere(4): Invalid result" ); return TSGetLastError(); } if ( list->Receive( this, m_pSocket ) != TS_OK ) { // TSErrorCode is set in Receive() TSAppendLastErrorMessage( "TSServer::ReadRecordListWithWhere(4): Failed to Receive" ); return TSGetLastError(); } return TS_OK; } int TSServer::ReadRecordWithWhere( TSRecord* record, const char* whereClause ) { // Entry point need to flush the error message. TSSetLastErrorMessage( "" ); if ( !record || !record->IsInitialized() || !whereClause ) { TSSetLastError( TS_INVALID_PARAMETERS ); TSAppendLastErrorMessage( "TSServer::ReadRecordWithWhere(no fields): Invalid parameters" ); return TSGetLastError(); } if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::ReadRecordWithWhere(no fields): Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=ReadRecordWithWhere&Params="; TSEncodeInt( record->tableId, params ); s += params; TSEncodeInt( record->fieldType, params ); s += params; TSEncodeString( whereClause, params ); s += params; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::ReadRecordWithWhere(no fields): Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::ReadRecordWithWhere(no fields): Failed to ReceiveInt" ); return TSGetLastError(); } if ( !nResult ) { TSSetLastError( TS_ERROR ); TSAppendLastErrorMessage( "TSServer::ReadRecordWithWhere(no fields); Invalid result" ); return TSGetLastError(); } // Only ignore non-db fields if we are reading the fields table // Server side only sends db & core fields if ( record->Receive( m_pSocket, ( record->tableId == TS_TBLID_FIELDS && record->fieldType == 0 ) ) != TS_OK ) { // TSErrorCode is set in Receive() TSAppendLastErrorMessage( "TSServer::ReadRecordWithWhere(no fields): Failed in Receive" ); return TSGetLastError(); } return TS_OK; } // Reads a record, filtering by the where clause and returning only the desired fields. int TSServer::ReadRecordWithWhere( TSRecord* record, const char* whereClause, const std::vector& fields ) { // Entry point need to flush the error message. TSSetLastErrorMessage( "" ); if ( !record || !record->IsInitialized() || ! whereClause ) { TSSetLastError( TS_INVALID_PARAMETERS ); TSAppendLastErrorMessage( "TSServer::ReadRecordWithWhere(fields): Invalid parameters" ); return TSGetLastError(); } if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::ReadRecordWithWhere(fields): Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=ReadSelectedFieldsWithWhere&Params="; TSEncodeInt( record->tableId, params ); s += params; TSEncodeInt( record->fieldType, params ); // This is the type. s += params; TSEncodeString( whereClause, params ); s += params; TSEncodeInt( fields.size(), params ); // Encode the vector of selected fields. s += params; std::vector::const_iterator it = fields.begin(); while ( it != fields.end() ) { TSEncodeInt( *it, params ); s += params; it++; } if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::ReadRecordWithWhere(fields): Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::ReadRecordWithWhere(fields): Failed in ReceiveInt" ); return TSGetLastError(); } if ( !nResult ) { TSSetLastError( TS_ERROR ); TSAppendLastErrorMessage( "TSServer::ReadRecordWithWhere(fields): Invalid result" ); return TSGetLastError(); } // Only ignore non-db fields if we are reading the fields table // Server side only sends db & core fields if ( record->Receive( m_pSocket, ( record->tableId == TS_TBLID_FIELDS && record->fieldType == 0 ) ) != TS_OK ) { // TSErrorCode is set in Receive() TSAppendLastErrorMessage( "TSServer::ReadRecordWithWhere(fields): Failed to Receive" ); return TSGetLastError(); } return TS_OK; } int TSServer::ReadReport( TSRecord* report, const char* name ) { if ( !report || !report->IsInitialized( TS_TBLID_REPORTS ) || !name ) { TSSetLastError( TS_INVALID_PARAMETERS ); TSAppendLastErrorMessage( "TSServer::ReadReport: Invalid parameter" ); return TSGetLastError(); } TSString modifiedName; if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::ReadReport: Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=ReadReport&Params="; TSEncodeInt( TS_TBLID_REPORTS, params ); s += params; TSEncodeInt( 0, params ); // reportType, currently needs to be 0. s += params; TSEncodeString( name, params ); s += params; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::ReadReport: Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::ReadReport: Failed to ReceiveInt" ); return TSGetLastError(); } if ( !nResult ) { TSSetLastError( TS_ERROR ); TSAppendLastErrorMessage( "TSServer::ReadReport: Invalid result" ); return TSGetLastError(); } if ( report->Receive( m_pSocket ) != TS_OK ) { // TSErrorCode is set in Receive() TSAppendLastErrorMessage( "TSServer::ReadReport: Failed to Receive" ); return TSGetLastError(); } return TS_OK; } int TSServer::ReadReportList( TSRecordList* list, long userId, int perm ) { if ( !list ) { TSSetLastError( TS_INVALID_PARAMETERS ); TSAppendLastErrorMessage( "TSServer::ReadReportList: Invalid parameter (list)" ); return TSGetLastError(); } if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::ReadReportList: Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=ReadReportList&Params="; TSEncodeInt( userId, params ); s += params; TSEncodeInt( perm, params ); s += params; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::ReadReportList: Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::ReadReportList: Failed to ReceiveInt" ); return TSGetLastError(); } if ( !nResult ) { TSSetLastError( TS_ERROR ); TSAppendLastErrorMessage( "TSServer::ReadReportList: Invalid result" ); return TSGetLastError(); } if ( list->Receive( this, m_pSocket ) != TS_OK ) { // TSErrorCode is set in Receive() TSAppendLastErrorMessage( "TSServer::ReadReportList: Failed to Receive" ); return TSGetLastError(); } return TS_OK; } int TSServer::ReadSelectionList( TSRecordList* list, int fieldId, int projectId ) { if ( !list ) { TSSetLastError( TS_INVALID_PARAMETERS ); TSAppendLastErrorMessage( "TSServer::ReadSelectionList: Invalid parameter (list)" ); return TSGetLastError(); } if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::ReadSelectionList: Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=ReadSelectionList2&Params="; TSEncodeInt( fieldId, params ); s += params; TSEncodeInt( projectId, params ); s += params; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::ReadSelectionList: Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::ReadSelectionList: Failed to ReceiveInt" ); return TSGetLastError(); } if ( !nResult ) { TSSetLastError( TS_ERROR ); TSAppendLastErrorMessage( "TSServer::ReadSelectionList: Invalid result" ); return TSGetLastError(); } if ( list->Receive( this, m_pSocket ) != TS_OK ) { // TSErrorCode is set in Receive() TSAppendLastErrorMessage( "TSServer::ReadSelectionList: Failed to Receive" ); return TSGetLastError(); } return TS_OK; } int TSServer::ReadStateList( TSRecordList* list, int workflowId, BOOL incParent /*=TRUE*/ ) { if ( !list ) { TSSetLastError( TS_INVALID_PARAMETERS ); TSAppendLastErrorMessage( "TSServer::ReadStateList: Invalid parameter (list)" ); return TSGetLastError(); } if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::ReadStateList: Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=ReadStateList&Params="; TSEncodeInt( workflowId, params ); s += params; TSEncodeInt( incParent, params ); s += params; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::ReadStateList: Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::ReadStateList: Failed to ReceiveInt" ); return TSGetLastError(); } if ( !nResult ) { TSSetLastError( TS_ERROR ); TSAppendLastErrorMessage( "TSServer::ReadStateList: Invalid result" ); return TSGetLastError(); } if ( list->Receive( this, m_pSocket ) != TS_OK ) { // TSErrorCode is set in Receive() TSAppendLastErrorMessage( "TSServer::ReadStateList: Failed to Receive" ); return TSGetLastError(); } return TS_OK; } int TSServer::ReadTransitionList( TSRecordList* list, int projectId ) { if ( !list ) { TSSetLastError( TS_INVALID_PARAMETERS ); TSAppendLastErrorMessage( "TSServer::ReadTransitionList: Invalid parameter (list)" ); return TSGetLastError(); } if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::ReadTransitionList: Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=ReadTransitionListEx&Params="; TSEncodeInt( projectId, params ); s += params; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::ReadTransitionList: Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::ReadTransitionList: Failed to ReceiveInt" ); return TSGetLastError(); } if ( !nResult ) { TSSetLastError( TS_ERROR ); TSAppendLastErrorMessage( "TSServer::ReadTransitionList: Invalid result" ); return TSGetLastError(); } if ( list->Receive( this, m_pSocket ) != TS_OK ) { // TSErrorCode is set in Receive() TSAppendLastErrorMessage( "TSServer::ReadTransitionList: Failed to Receive" ); return TSGetLastError(); } return TS_OK; } int TSServer::ReadUserDefinedFields( TSRecordList* list, int tableId ) { if ( !list ) { TSSetLastError( TS_INVALID_PARAMETERS ); TSAppendLastErrorMessage( "TSServer::ReadUserDefinedFields: Invalid parameter (list)" ); return TSGetLastError(); } TSSocket* socket = OpenSocket(); if ( socket == NULL ) { // TSErrorCode is set in Open(Get)Socket return TSGetLastError(); } TSString s; TSString params; s = "Func=ReadUserDefinedFields&Params="; TSEncodeInt( tableId, params ); s += params; if ( !Send( socket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::ReadUserDefinedFields: Failed to Send" ); delete socket; return TSGetLastError(); } int nResult; if ( socket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::ReadUserDefinedFields: Failed to ReceiveInt" ); delete socket; return TSGetLastError(); } if ( !nResult ) { TSSetLastError( TS_ERROR ); TSAppendLastErrorMessage( "TSServer::ReadUserDefinedFields: Invalid result" ); delete socket; return TSGetLastError(); } if ( list->Receive( this, socket ) != TS_OK ) { // TSErrorCode is set in Receive() TSAppendLastErrorMessage( "TSServer::ReadUserDefinedFields: Failed to Receive" ); delete socket; return TSGetLastError(); } delete socket; return TS_OK; } int TSServer::ReadUserListForPrivilege( TSRecordList* list, int userid, TSRecordList* fieldList, int mask ) { if ( !list || !fieldList ) { TSSetLastError( TS_INVALID_PARAMETERS ); TSAppendLastErrorMessage( "TSServer::ReadUserListForPrivilege: Invalid parameter" ); return TSGetLastError(); } if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::ReadUserListForPrivilege: Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=ReadUserListForPrivilege&Params="; TSEncodeInt( userid, params ); s += params; fieldList->SocketString( params ); s += params; TSEncodeInt( mask, params ); s += params; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::ReadUserListForPrivilege: Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::ReadUserListForPrivilege: Failed to ReceiveInt" ); return TSGetLastError(); } if ( !nResult ) { TSSetLastError( TS_ERROR ); TSAppendLastErrorMessage( "TSServer::ReadUserListForPrivilege: Invalid result" ); return TSGetLastError(); } if ( list->Receive( this, m_pSocket ) != TS_OK ) { // TSErrorCode is set in Receive() TSAppendLastErrorMessage( "TSServer::ReadUserListForPrivilege: Failed to Receive" ); return TSGetLastError(); } return TS_OK; } int TSServer::ReadUserSelectionList( TSRecordList* list, int fieldId, int projectId, BOOL incDeleted /*=FALSE*/ ) { if ( !list ) { TSSetLastError( TS_INVALID_PARAMETERS ); TSAppendLastErrorMessage( "TSServer::ReadUserSelectionList: Invalid parameter (list)" ); return TSGetLastError(); } if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::ReadUserSelectionList: Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=ReadUserSelectionList&Params="; TSEncodeInt( fieldId, params ); s += params; TSEncodeInt( projectId, params ); s += params; TSEncodeInt( incDeleted, params ); s += params; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::ReadUserSelectionList: Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::ReadUserSelectionList: Failed to ReceiveInt" ); return TSGetLastError(); } if ( !nResult ) { TSSetLastError( TS_ERROR ); TSAppendLastErrorMessage( "TSServer::ReadUserSelectionList: Invalid result" ); return TSGetLastError(); } if ( list->Receive( this, m_pSocket ) != TS_OK ) { // TSErrorCode is set in Receive() TSAppendLastErrorMessage( "TSServer::ReadUserSelectionList: Failed to Receive" ); return TSGetLastError(); } return TS_OK; } int TSServer::ReadVCActions( TSRecordList* list, int caseId ) { if ( !list ) { TSSetLastError( TS_INVALID_PARAMETERS ); TSAppendLastErrorMessage( "TSServer::ReadVCActions: Invalid parameter (list)" ); return TSGetLastError(); } if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::ReadVCActions: Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=ReadVCActions&Params="; TSEncodeInt( caseId, params ); s += params; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::ReadVCActions: Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::ReadVCActions: Failed to ReceiveInt" ); return TSGetLastError(); } if ( !nResult ) { TSSetLastError( TS_ERROR ); TSAppendLastErrorMessage( "TSServer::ReadVCActions: Invalid result" ); return TSGetLastError(); } if ( list->Receive( this, m_pSocket ) != TS_OK ) { // TSErrorCode is set in Receive() TSAppendLastErrorMessage( "TSServer::ReadVCActions: Failed to Receive" ); return TSGetLastError(); } return TS_OK; } int TSServer::ReadVCActionsForModule( TSRecordList* list, const char* filename, int userid, int action2 ) { if ( !list || !filename ) { TSSetLastError( TS_INVALID_PARAMETERS ); TSAppendLastErrorMessage( "TSServer::ReadVCActionsForModule: Invalid parameter" ); return TSGetLastError(); } if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::ReadVCActionsForModule: Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=ReadVCActionsForModule&Params="; TSEncodeString( filename, params ); s += params; TSEncodeInt( userid, params ); s += params; TSEncodeInt( action2, params ); s += params; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::ReadVCActionsForModule: Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::ReadVCActionsForModule: Failed to ReceiveInt" ); return TSGetLastError(); } if ( !nResult ) { TSSetLastError( TS_ERROR ); TSAppendLastErrorMessage( "TSServer::ReadVCActionsForModule: Invalid result" ); return TSGetLastError(); } if ( list->Receive( this, m_pSocket ) != TS_OK ) { // TSErrorCode is set in Receive() TSAppendLastErrorMessage( "TSServer::ReadVCActionsForModule: Failed to Receive" ); return TSGetLastError(); } return TS_OK; } int TSServer::RefreshCache( int tableId ) { if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::RefreshCache: Failed to GetSocket" ); return TSGetLastError(); } TSString s, params; s = "Func=RefreshCache&Params="; TSEncodeInt( tableId, params ); s += params; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::RefreshCache: Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::RefreshCache: Failed to ReceiveInt" ); return TSGetLastError(); } if ( !nResult ) { TSSetLastError( TS_ERROR ); TSAppendLastErrorMessage( "TSServer::RefreshCache: Invalid result" ); return TSGetLastError(); } return TS_OK; } int TSServer::ReleaseRecordLock( int nTableId, int nItemId, int nProjectId /* = 0 */, int nItemNumber /* = 0 */ ) { if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::ReleaseRecordLock: Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=ReleaseRecordLock&Params="; TSEncodeInt( nTableId, params ); s += params; TSEncodeInt( nItemId, params ); s += params; TSEncodeInt( nProjectId, params ); s += params; TSEncodeInt( nItemNumber, params ); s += params; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::ReleaseRecordLock: Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::ReleaseRecordLock: Failed to ReceiveInt" ); return TSGetLastError(); } if ( nResult != TS_OK ) { TSSetLastError( nResult ); TSAppendLastErrorMessage( "TSServer::ReleaseRecordLock: Invalid result" ); return TSGetLastError(); } return TS_OK; } int TSServer::ReleaseRecordLockById( int nTableId, int nItemId ) { return ReleaseRecordLock( nTableId, nItemId ); } int TSServer::ReleaseRecordLockByNumber( int nProjectId, int nItemNumber ) { return ReleaseRecordLock( 0, 0, nProjectId, nItemNumber ); } int TSServer::SetAlternateUser( const char* loginid, const char* pwd, bool bValidatePwd /* = true */ ) { if ( !loginid ) { TSSetLastError( TS_INVALID_PARAMETERS ); TSAppendLastErrorMessage( "TSServer::SetAlternateUser: Invalid parameter (loginid)" ); return TSGetLastError(); } if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::SetAlternateUser: Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=SetAlternateUser&Params="; TSString userName( loginid ); if ( bValidatePwd ) { userName += ":"; userName += pwd; } userName = EncodePassword( userName ); TSEncodeString( userName, params ); s += params; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::SetAlternateUser: Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::SetAlternateUser: Failed to ReceiveInt" ); return TSGetLastError(); } // nResult will be the error code, TS_OK on success if ( nResult != TS_OK ) { TSSetLastError( nResult ); TSAppendLastErrorMessage( "TSServer::SetAlternateUser: Invalid result" ); return TSGetLastError(); } alternateUser = userName; return TS_OK; } int TSServer::SetExitUrl( const char* exiturl ) { if ( !exiturl ) { TSSetLastError( TS_INVALID_PARAMETERS ); TSAppendLastErrorMessage( "TSServer::SetExitUrl: Invalid parameter (exiturl)" ); return TSGetLastError(); } if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::SetExitUrl: Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=SetExitUrl&Params="; TSEncodeString( exiturl, params ); s += params; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::SetExitUrl: Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::SetExitUrl: Failed to ReceiveInt" ); return TSGetLastError(); } if ( !nResult ) { TSSetLastError( TS_ERROR ); TSAppendLastErrorMessage( "TSServer::SetExitUrl: Invalid result" ); return TSGetLastError(); } return TS_OK; } int TSServer::SetGroupPrivilege( int groupId, int itemId, enum privId_e privId, bool bGrant ) { if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::SetGroupPrivilege: Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=SetGroupPrivilege&Params="; TSEncodeInt( groupId, params ); s += params; TSEncodeInt( itemId, params ); s += params; TSEncodeInt( privId, params ); s += params; TSEncodeInt( bGrant, params ); s += params; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::SetGroupPrivilege: Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::SetGroupPrivilege: Failed to ReceiveInt" ); return TSGetLastError(); } if ( !nResult ) { TSSetLastError( TS_ERROR ); TSAppendLastErrorMessage( "TSServer::SetGroupPrivilege: Invalid result" ); return TSGetLastError(); } return TS_OK; } int TSServer::SetRecordLock( int nTableId, int nItemId, bool bStealLockFlag, int nProjectId /* = 0 */, int nItemNumber /* = 0 */ ) { if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::SetRecordLock: Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=SetRecordLock&Params="; TSEncodeInt( nTableId, params ); s += params; TSEncodeInt( nItemId, params ); s += params; TSEncodeInt( nProjectId, params ); s += params; TSEncodeInt( nItemNumber, params ); s += params; TSEncodeInt( bStealLockFlag, params ); s += params; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::SetRecordLock: Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::SetRecordLock: Failed to ReceiveInt" ); return TSGetLastError(); } if ( nResult != TS_OK ) { TSSetLastError( nResult ); TSAppendLastErrorMessage( "TSServer::SetRecordLock: Invalid result" ); return TSGetLastError(); } return TS_OK; } int TSServer::SetRecordLockById( int nTableId, int nItemId, bool bStealLockFlag /* = false */ ) { return SetRecordLock( nTableId, nItemId, bStealLockFlag ); } int TSServer::SetRecordLockByNumber( int nProjectId, int nItemNumber, bool bStealLockFlag /* = false */ ) { return SetRecordLock( 0, 0, bStealLockFlag, nProjectId, nItemNumber ); } int TSServer::SetUserPrivilege( int userId, int itemId, enum privId_e privId, bool bGrant ) { if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::SetUserPrivilege: Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=SetUserPrivilege&Params="; TSEncodeInt( userId, params ); s += params; TSEncodeInt( itemId, params ); s += params; TSEncodeInt( privId, params ); s += params; TSEncodeInt( bGrant, params ); s += params; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::SetUserPrivilege: Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::SetUserPrivilege: Failed to ReceiveInt" ); return TSGetLastError(); } if ( !nResult ) { TSSetLastError( TS_ERROR ); TSAppendLastErrorMessage( "TSServer::SetUserPrivilege: Invalid result" ); return TSGetLastError(); } return TS_OK; } int TSServer::Submit( int* nIssueId, TSString& sLoginid, TSRecord* pRec, int nTableId, int nProjectId, int nFolderId, int /*nType*/ ) { if ( !nIssueId || !pRec || !pRec->IsInitialized() ) { TSSetLastError( TS_INVALID_PARAMETERS ); TSAppendLastErrorMessage( "TSServer::Submit(1): Invalid parameter" ); return TSGetLastError(); } return TSServer::Submit( nIssueId, sLoginid, pRec, nTableId, nProjectId, nFolderId ); } // This version of submit returns the issue id as an int. int TSServer::Submit( int* nIssueId, TSString& sLoginid, TSRecord* pRec, int nTableId, int nProjectId, int nFolderId ) { if ( !nIssueId || !pRec || !pRec->IsInitialized() ) { TSSetLastError( TS_INVALID_PARAMETERS ); TSAppendLastErrorMessage( "TSServer::Submit(2): Invalid parameter" ); return TSGetLastError(); } if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::Submit(2): Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=Submit&Params="; TSEncodeString( sLoginid, params ); s += params; TSEncodeInt( nProjectId, params ); s += params; TSEncodeInt( nTableId, params ); s += params; TSEncodeInt( nFolderId, params ); s += params; pRec->SocketString( params ); s += params; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::Submit(2): Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::Submit(2): Failed to ReceiveInt" ); return TSGetLastError(); } if ( !nResult ) { TSSetLastError( TS_ERROR ); TSAppendLastErrorMessage( "TSServer::Submit(2): Invalid result" ); return TSGetLastError(); } // Receive the issue id if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::Submit(2): Failed to ReceiveInt" ); return TSGetLastError(); } *nIssueId = nResult; return TS_OK; } // This version of submit returns both the issue id as an int, and the // ts_id as an int. This is probably the one you want to use if you will // need the ts_id. int TSServer::Submit( int* nId, int* nIssueId, TSString& sLoginid, TSRecord* pRec, int nTableId, int nProjectId, int nFolderId ) { if ( !nId || !nIssueId || !pRec || !pRec->IsInitialized() ) { TSSetLastError( TS_INVALID_PARAMETERS ); TSAppendLastErrorMessage( "TSServer::Submit(3): Invalid parameter" ); return TSGetLastError(); } if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::Submit(3): Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=SubmitReturnId&Params="; TSEncodeString( sLoginid, params ); s += params; TSEncodeInt( nProjectId, params ); s += params; TSEncodeInt( nTableId, params ); s += params; TSEncodeInt( nFolderId, params ); s += params; pRec->SocketString( params ); s += params; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::Submit(3): Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::Submit(3): Failed to ReceiveInt" ); return TSGetLastError(); } if ( !nResult ) { TSSetLastError( TS_ERROR ); TSAppendLastErrorMessage( "TSServer::Submit(3): Invalid result" ); return TSGetLastError(); } // First receive the issue id if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::Submit(3): Failed to ReceiveInt" ); return TSGetLastError(); } *nIssueId = nResult; // Next, receive the ts_id if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::Submit(3): Failed to ReceiveInt" ); return TSGetLastError(); } *nId = nResult; return TS_OK; } int TSServer::Transition( TSString& sLoginid, TSRecord* pRec, int nProjectId, int nTableId, int nRecordId, int nTransition ) { if ( !pRec || !pRec->IsInitialized() ) { TSSetLastError( TS_INVALID_PARAMETERS ); TSAppendLastErrorMessage( "TSServer::Transition: Invalid parameter (pRec)" ); return TSGetLastError(); } if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::Transition: Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=Transition&Params="; TSEncodeString( sLoginid, params ); s += params; TSEncodeInt( nProjectId, params ); s += params; TSEncodeInt( nTableId, params ); s += params; TSEncodeInt( nRecordId, params ); s += params; TSEncodeInt( nTransition, params ); s += params; pRec->SocketString( params ); s += params; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::Transition: Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::Transition: Failed to ReceiveInt" ); return TSGetLastError(); } if ( !nResult ) { TSSetLastError( TS_ERROR ); TSAppendLastErrorMessage( "TSServer::Transition: Invalid result" ); return TSGetLastError(); } return nResult; } int TSServer::UpdateList( TSRecordList* list, int tableId, int recid1, int recid2 ) { if ( !list ) { TSSetLastError( TS_INVALID_PARAMETERS ); TSAppendLastErrorMessage( "TSServer::UpdateList: Invalid parameter (list)" ); return TSGetLastError(); } if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::UpdateList: Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=UpdateList&Params="; TSEncodeInt( tableId, params ); s += params; TSEncodeInt( recid1, params ); s += params; TSEncodeInt( recid2, params ); s += params; list->SocketString( params ); s += params; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::UpdateList: Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::UpdateList: Failed to ReceiveInt" ); return TSGetLastError(); } if ( !nResult ) { TSSetLastError( TS_ERROR ); TSAppendLastErrorMessage( "TSServer::UpdateList: Invalid result" ); return TSGetLastError(); } if ( list->Receive( this, m_pSocket ) != TS_OK ) { // TSErrorCode is set in Receive() TSAppendLastErrorMessage( "TSServer::UpdateList: Failed to Receive" ); return TSGetLastError(); } return TS_OK; } int TSServer::UpdateRecord( TSRecord* rec, TSRecord* newRecord /*=NULL*/ ) { if ( !rec || !rec->IsInitialized() ) { TSSetLastError( TS_INVALID_PARAMETERS ); TSAppendLastErrorMessage( "TSServer::UpdateRecord: Invalid parameter (rec)" ); return TSGetLastError(); } if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::UpdateRecord: Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=UpdateRecord&Params="; TSEncodeInt( rec->tableId, params ); s += params; TSEncodeInt( rec->fieldType, params ); s += params; rec->SocketString( params ); s += params; if ( !Send( m_pSocket, s ) ) { // TSErrorCode is set in Send() TSAppendLastErrorMessage( "TSServer::UpdateRecord: Failed to Send" ); return TSGetLastError(); } int nResult; if ( m_pSocket->ReceiveInt( &nResult ) != TS_OK ) { // TSErrorCode is set in ReceiveInt() TSAppendLastErrorMessage( "TSServer::UpdateRecord: Failed to ReceiveInt" ); return TSGetLastError(); } if ( !nResult ) { TSSetLastError( TS_ERROR ); TSAppendLastErrorMessage( "TSServer::UpdateRecord: Invalid result" ); return TSGetLastError(); } if ( newRecord != NULL ) { if ( newRecord->Receive( m_pSocket ) != TS_OK ) { // TSErrorCode is set in Receive() TSAppendLastErrorMessage( "TSServer::UpdateRecord: Failed to Receive" ); return TSGetLastError(); } } else { TSRecord dummy( rec->tableId, this ); dummy.fieldType = rec->fieldType; if ( dummy.Receive( m_pSocket ) != TS_OK ) { // TSErrorCode is set in Receive() TSAppendLastErrorMessage( "TSServer::UpdateRecord: Failed to Receive (dummy)" ); return TSGetLastError(); } } return TS_OK; } int TSServer::ValidateUser( const char* loginid, const char* pwd, int authFlags /*=TS_AUTH_TEAMTRACK*/, int* userId /*=NULL*/ ) { if ( !loginid ) { TSSetLastError( TS_INVALID_PARAMETERS ); TSAppendLastErrorMessage( "TSServer::ValidateUser: Invalid parameter (loginid)" ); return TSGetLastError(); } if ( !GetSocket() ) { // TSErrorCode is set in Open(Get)Socket TSAppendLastErrorMessage( "TSServer::ValidateUser: Failed to GetSocket" ); return TSGetLastError(); } TSString s; TSString params; s = "Func=ValidateUser&Params="; TSEncodeString( loginid, params ); s