00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include "SessionManager.h"
00039 #include "StreamManager.h"
00040 #include "SystemManager.h"
00041 #include "RioError.h"
00042 #include "DataConversion.h"
00043 #include "RioProxy.h"
00044 #include "RioTCPTypes.h"
00045 #include "Router.h"
00046 #include "DiskMgr.h"
00047 #include "MonitorTable.h"
00048 #include "NATMap.h"
00049 #include <arpa/inet.h>
00050 #include <stdio.h>
00051 #include <stdlib.h>
00052
00053 #include <string.h>
00054 #include <errno.h>
00055 #include <pthread.h>
00056 #include <unistd.h>
00057 #include <netdb.h>
00058 #include <sys/types.h>
00059 #include <sys/socket.h>
00060 #include <netinet/in.h>
00061 #include <time.h>
00062 #include <signal.h>
00063
00064
00065 #include <sys/syscall.h>
00066
00067 #ifdef USE_GRID
00068 #include <sys/stat.h>
00069 #endif
00070
00071
00072 #include "CommonLibraries.h"
00073
00074 extern CEventManager EventManager;
00075
00076
00077
00078 class RioStream;
00079 class RioObject;
00080
00081 const char* const LOGFILE = "RIOSessionManager.log";
00082
00083
00084
00085 CSessionManager::CSessionManager()
00086 {
00087 m_BlockSize = 0;
00088 m_NumberOfDisks = 0;
00089 m_NumberOfStorageNodes = 0;
00090 m_DiskMgr = NULL;
00091 m_FileRoot = NULL;
00092 m_MaxSessions = 0;
00093 m_StreamManager = NULL;
00094 m_ObjectManager = NULL;
00095 m_SystemManager = NULL;
00096 m_UserManager = NULL;
00097 m_Router = NULL;
00098 m_TCPconnection = NULL;
00099 m_NetMgr = NULL;
00100 m_used = 0;
00101 m_SessionTable = NULL;
00102 pthread_mutex_init( &m_mutex, NULL );
00103 m_initialized = false;
00104
00105 m_ConnectionThreadId = 0;
00106 m_threadStopEvent = false;
00107
00108
00109
00110 m_ServerAddress = NULL;
00111 m_ServerAddressSize = 0;
00112
00113
00114
00115 m_ClientsTimeOut = 0;
00116
00117
00118
00119 m_LogRotation = NULL;
00120
00121
00122
00123 m_SearchLogs = NULL;
00124
00125
00126 m_NetInterface = NULL;
00127 }
00128
00129 CSessionManager::~CSessionManager()
00130 {
00131 if( m_SessionTable != 0 )
00132 {
00133 delete[] m_SessionTable;
00134 m_SessionTable = 0;
00135 }
00136 pthread_mutex_destroy( &m_mutex );
00137 CleanUp();
00138 m_log.close();
00139
00140
00141
00142 if( m_ServerAddress != NULL )
00143 delete[] m_ServerAddress;
00144
00145
00146 if( m_LogRotation != NULL )
00147 delete m_LogRotation;
00148
00149
00150 if( m_SearchLogs != NULL )
00151 delete m_SearchLogs;
00152 }
00153
00154
00155
00156
00157 int CSessionManager::Initialize( SessionManagerConfig *Config )
00158 {
00159 pthread_attr_t attrib;
00160
00161
00162 if( m_initialized )
00163 {
00164 if( m_log.is_open() )
00165 m_log << "Initialize(): Tried to initialize component "
00166 << " already initialized" << endl;
00167
00168 return ERROR_SESSIONMANAGER + ERROR_INITIALIZED;
00169 }
00170
00171 m_LogsDirectory = Config->LogsDirectory;
00172
00173 if( Config->GenerateLogs )
00174 {
00175
00176 char LogFileName[ MaxPathSize ];
00177
00178 strcpy( LogFileName, m_LogsDirectory );
00179 strcat( LogFileName, LOGFILE );
00180 m_log.open( LogFileName );
00181
00182 if( !m_log.is_open() )
00183 {
00184 return ERROR_SESSIONMANAGER + ERROR_LOGFILE ;
00185 }
00186 }
00187
00188 m_SystemManager = Config->SystemManager;
00189 m_StreamManager = Config->StreamManager;
00190 m_ObjectManager = Config->ObjectManager;
00191 m_UserManager = Config->UserManager;
00192 m_Router = Config->Router;
00193 m_DiskMgr = Config->diskMgr;
00194 m_NumberOfDisks = Config->NumberOfDisks;
00195 m_NumberOfStorageNodes = Config->NumberOfStorageNodes;
00196
00197 RioErr << "Config->FileRoot " << Config->FileRoot<< endl;
00198 m_FileRoot = new char[ strlen( Config->FileRoot ) + 1 ];
00199 strcpy( m_FileRoot, Config->FileRoot );
00200 RioErr << "m_FileRoot " << m_FileRoot << endl;
00201
00202 m_MaxSessions = Config->MaxSessions;
00203 m_BlockSize = Config->BlockSize;
00204
00205
00206 m_SessionTable = new SessionEntry[Config->MaxSessions];
00207 if( m_SessionTable == 0 )
00208 {
00209 if( m_log.is_open() )
00210 m_log << "Initialize(): Failed to allocate memory" << endl;
00211
00212 m_ObjectManager = 0;
00213 m_StreamManager = 0;
00214 return ERROR_SESSIONMANAGER + ERROR_MEMORY;
00215 }
00216
00217
00218 for( int i = 0; i < Config->MaxSessions; i++ )
00219 {
00220 m_SessionTable[i].Session.Index = -1;
00221 m_SessionTable[i].Session.Version = 0;
00222 m_SessionTable[i].s_ptr = 0;
00223 }
00224
00225 m_used = 0;
00226
00227
00228
00229 m_DiskMgr->GetNumberOfStorageNodes( &m_ServerAddressSize );
00230
00231 m_ServerAddressSize = m_ServerAddressSize + 1;
00232
00233
00234
00235 m_ServerAddress = new SOCKADDR_IN[ m_ServerAddressSize ];
00236 if( m_ServerAddress == NULL )
00237 {
00238 if( m_log.is_open() )
00239 m_log << "Initialize(): Failed to allocate memory" << endl;
00240 return ERROR_SESSIONMANAGER + ERROR_MEMORY;
00241 }
00242
00243
00244
00245
00246
00247 m_ServerAddress[ 0 ].sin_family = AF_INET;
00248 m_ServerAddress[ 0 ].sin_port = htons( RIOSERVERUDPPORT );
00249
00250 m_ServerAddress[ 0 ].sin_addr.s_addr = m_StreamManager->
00251 GetNetInterfaceIPAddr();
00252
00253
00254
00255 m_DiskMgr->GetStorageServersAddress( &m_ServerAddress[ 1 ] );
00256
00257
00258
00259
00260 m_ClientsTimeOut = Config->ClientsTimeOut;
00261
00262 m_TCPconnection = new CRioTCP;
00263
00264 int hResult = m_TCPconnection->InitServer( RioTCPport );
00265 if( FAILED( hResult) )
00266 {
00267 if( m_log.is_open() )
00268 m_log << "Initialize(): Failed to Initialize server TCP connection,"
00269 << " rc: " << hResult << endl;
00270 CleanUp();
00271 return hResult;
00272 }
00273
00274 pthread_attr_init( &attrib );
00275 pthread_attr_setstacksize( &attrib, 2*PTHREAD_STACK_MIN );
00276
00277 if( pthread_create( &m_ConnectionThreadId, &attrib, &ConnectionThread,
00278 this ) )
00279 {
00280 if( m_log.is_open() )
00281 {
00282 m_log << "Start(): Failed to create thread (connection thread)"
00283 << endl << " ERROR: " << strerror(errno) << endl;
00284 }
00285 CleanUp();
00286 return ERROR_SESSIONMANAGER + ERROR_CREATE_THREAD;
00287 }
00288
00289
00290
00291 m_NetMgr = m_StreamManager->getNetMgr();
00292
00293
00294
00295
00296 m_NetInterface = m_StreamManager->getNetInterface();
00297
00298
00299
00300
00301 m_LogRotation = new CLogRotation;
00302 if( m_LogRotation == NULL )
00303 {
00304 if( m_log.is_open() )
00305 m_log << "Initialize(): erro ao criar o objeto com os logs."
00306 << endl;
00307 CleanUp();
00308 return ERROR_SESSIONMANAGER + ERROR_MEMORY;
00309 }
00310 else
00311 {
00312
00313 char LogFileNamePrefix[ MaxPathSize ];
00314 strcpy( LogFileNamePrefix, Config->LogsDirectory );
00315 strcat( LogFileNamePrefix, "ServerLog_" );
00316
00317
00318 strcat( LogFileNamePrefix, inet_ntoa( m_ServerAddress[ 0 ].sin_addr ) );
00319
00320 #ifdef RIO_DEBUG2
00321 RioErr << "CSessionManager::Initialize LogFileNamePrefix = "
00322 << LogFileNamePrefix << endl;
00323 #endif
00324
00325 if( m_LogRotation->Initialize( LogFileNamePrefix,
00326 Config->MaxLogFileSize,
00327 Config->MaxCombinedLogFilesSize,
00328 Config->SaveLogs ) != S_OK )
00329 {
00330 if( m_log.is_open() )
00331 m_log << "Initialize(): erro ao inicializar o objeto com os "
00332 << "logs." << endl;
00333 delete m_LogRotation;
00334 m_LogRotation = NULL;
00335 CleanUp();
00336 return ERROR_SESSIONMANAGER + ERROR_INITIALIZE_LOGROTATION;
00337 }
00338
00339 m_SearchLogs = new CSearchLogs;
00340 if( m_SearchLogs == NULL )
00341 {
00342
00343 if( m_log.is_open() )
00344 m_log << "Initialize(): erro ao criar o objeto de busca nos "
00345 << "logs."
00346 << endl;
00347 delete m_LogRotation;
00348 m_LogRotation = NULL;
00349 CleanUp();
00350 return ERROR_SESSIONMANAGER + ERROR_MEMORY;
00351 }
00352 if( m_SearchLogs->Initialize( m_LogRotation, m_NetMgr, m_LogsDirectory,
00353 "Server-", m_BlockSize, m_NetInterface )
00354 != S_OK )
00355 {
00356
00357 if( m_log.is_open() )
00358 m_log << "Initialize(): erro ao inicializar o objeto de busca "
00359 << "nos logs."
00360 << endl;
00361 delete m_LogRotation;
00362 m_LogRotation = NULL;
00363 delete m_SearchLogs;
00364 m_SearchLogs = NULL;
00365 CleanUp();
00366 return ERROR_SESSIONMANAGER + ERROR_INITIALIZE_SEARCHLOGS;
00367 }
00368 }
00369
00370 m_initialized = true;
00371
00372 return S_OK;
00373 }
00374
00375 int CSessionManager::CleanUp()
00376 {
00377 KillConnectionThread();
00378
00379 if( m_TCPconnection != 0 )
00380 {
00381 m_TCPconnection->Disconnect();
00382 delete m_TCPconnection;
00383 m_TCPconnection = 0;
00384 }
00385
00386 if( m_FileRoot != NULL )
00387 delete[] m_FileRoot;
00388 m_FileRoot = NULL;
00389
00390 m_initialized = false;
00391
00392 return S_OK;
00393 }
00394
00395 void CSessionManager::KillConnectionThread()
00396 {
00397 if( m_ConnectionThreadId != 0 )
00398 {
00399
00400 m_threadStopEvent = 1;
00401
00402
00403 char LocalName[256];
00404 hostent* LocalAddress;
00405 struct in_addr LocalIPaddress;
00406 int x_sock;
00407 if( gethostname( LocalName, 256 ) != 0 )
00408 {
00409 RioErr << "SessionManager.KillConnectionThread: gethostname failed "
00410 << strerror(errno) << endl;
00411 goto closeit;
00412 }
00413
00414
00415 LocalAddress = gethostbyname(LocalName);
00416 if( LocalAddress == 0 )
00417 {
00418 RioErr << "SessionManager.KillConnectionThread: gethostbyname failed "
00419 << strerror(errno) << endl;
00420 goto closeit;
00421 }
00422
00423 memcpy( &LocalIPaddress, LocalAddress->h_addr,
00424 sizeof( LocalIPaddress ) );
00425
00426
00427
00428
00429
00430
00431
00432
00433 x_sock = socket( AF_INET, SOCK_STREAM, 0 );
00434 SOCKADDR_IN xaddr;
00435 memset( &xaddr, 0, sizeof( xaddr ));
00436 xaddr.sin_family = AF_INET;
00437 xaddr.sin_addr.s_addr = LocalIPaddress.s_addr;
00438 xaddr.sin_port = htons(RioTCPport);
00439
00440 connect( x_sock, (SOCKADDR*) &xaddr, sizeof( xaddr ));
00441
00442 closeit:
00443
00444
00445
00446 m_TCPconnection->CloseSocket();
00447
00448
00449 pthread_join( m_ConnectionThreadId, NULL );
00450
00451 m_ConnectionThreadId = 0;
00452 }
00453 }
00454
00455
00456 void * CSessionManager::ConnectionThread( void * Param )
00457 {
00458 CRioTCP* TCPconnection;
00459 SOCKET ConnectedSocket;
00460
00461 RioErr << "CONNECTIONTHREADID " << syscall( SYS_gettid ) << endl;
00462
00463
00464 CSessionManager *SessionManager = (CSessionManager *) Param;
00465
00466
00467 TCPconnection = SessionManager->m_TCPconnection;
00468 while( true )
00469 {
00470
00471 HRESULT hResult = TCPconnection->WaitConnection(&ConnectedSocket);
00472
00473
00474 if( SessionManager->m_threadStopEvent )
00475 {
00476 TCPconnection->Disconnect();
00477 return(0);
00478 }
00479
00480
00481 if( FAILED( hResult ) )
00482 {
00483 if( SessionManager->m_log.is_open() )
00484 SessionManager->m_log << "ConnectionThread: "
00485 << "Connection waiting failed" << endl;
00486 if( hResult != ( ( HRESULT ) ( ERROR_RIOTCP + ERROR_SOCKET_ACCEPT )
00487 ) )
00488 {
00489 RioErr << "[ConnectionThread] Erro critico 0x" << hex
00490 << hResult << dec << " ("
00491 << GetErrorDescription( hResult ) << ") gerado. "
00492 << "Forcando a finalizacao do servidor com um sinal "
00493 << "SIGTERM." << endl;
00494 raise( SIGTERM );
00495 }
00496 }
00497
00498 else
00499 {
00500 ClientThreadParameter *Param = new ClientThreadParameter();
00501 Param->Socket = ConnectedSocket;
00502 Param->SessionManager = SessionManager;
00503 pthread_t junk;
00504 pthread_attr_t attrib;
00505
00506
00507
00508 Param->RemoteAddress = TCPconnection->m_RemoteAddress;
00509
00510 pthread_attr_init( &attrib );
00511 pthread_attr_setstacksize( &attrib, 6*PTHREAD_STACK_MIN );
00512
00513
00514 if( pthread_create( &junk, &attrib, &ClientThread, (void*) Param ) )
00515 {
00516 delete Param;
00517 if( SessionManager->m_log.is_open() )
00518 SessionManager->m_log << "ConnectionThread: "
00519 << "Failed to create client thread"
00520 << endl;
00521 shutdown( ConnectedSocket, 2 );
00522 }
00523 else
00524 pthread_detach( junk );
00525 }
00526 }
00527
00528 return 0;
00529 }
00530
00531
00532 void * CSessionManager::ClientThread( void * Param )
00533 {
00534 ClientThreadParameter *ClientParam = ( ClientThreadParameter * ) Param;
00535 SOCKET sock = ClientParam->Socket;
00536 SOCKADDR_IN remoteAddress = ClientParam->RemoteAddress;
00537 CSessionManager* SessionManager = ClientParam->SessionManager;
00538 unsigned int Class = 0;
00539 unsigned int Method = 0;
00540 unsigned int Size = 0;
00541 HRESULT Status = 0;
00542 char *Parameter = (char*) malloc( MaxTCPDataSize*sizeof(char) );
00543 char *Result = (char*) malloc( MaxTCPDataSize*sizeof(char) );
00544 unsigned int ParameterSize = MaxTCPDataSize;
00545 unsigned int ResultSize = MaxTCPDataSize;
00546 CRioTCP TCPconnection;
00547
00548 #ifdef RIO_DEBUG2
00549 RioErr << "CLIENTTHREADID " << syscall( SYS_gettid ) << endl;
00550 #endif
00551
00552
00553 memset( Parameter, 0, MaxTCPDataSize*sizeof( char ) );
00554 memset( Result , 0, MaxTCPDataSize*sizeof( char ) );
00555
00556
00557 Status = TCPconnection.AcceptConnection( sock,
00558 SessionManager->m_ClientsTimeOut );
00559 if( FAILED( Status ) )
00560 {
00561 RioErr << "[ClientThread] Erro ao aceitar a conexao do cliente a "
00562 << "partir do IP "
00563 << inet_ntoa( ClientParam->RemoteAddress.sin_addr )
00564 << " e da porta " << ntohs( ClientParam->RemoteAddress.sin_port )
00565 << ". Terminando a thread do cliente!" << endl;
00566
00567 if( SessionManager->m_log.is_open() )
00568 {
00569 char *info = myInfo();
00570 SessionManager->m_log << info
00571 << "Error accepting TCP connection at "
00572 << "ClienThread. Exiting Session thread."
00573 << endl;
00574 free( info );
00575 }
00576 free( Parameter );
00577 free( Result );
00578
00579 delete ClientParam;
00580
00581 return( 0 );
00582 }
00583
00584
00585
00586
00587
00588 RioSession Session( SessionManager, remoteAddress );
00589
00590
00591 pthread_mutex_lock( &SessionManager->m_mutex );
00592 int i = SessionManager->m_MaxSessions;
00593 if( SessionManager->m_used < SessionManager->m_MaxSessions )
00594 {
00595 for( i = 0; i < SessionManager->m_MaxSessions; i++ )
00596 {
00597 if( SessionManager->m_SessionTable[i].Session.Index != -1 )
00598 continue;
00599 break;
00600 }
00601 }
00602
00603
00604 if( i >= SessionManager->m_MaxSessions )
00605 {
00606 RioErr << "[ClientThread] Erro ao criar a sessao do cliente a "
00607 << "partir do IP "
00608 << inet_ntoa( ClientParam->RemoteAddress.sin_addr )
00609 << " e da porta " << ntohs( ClientParam->RemoteAddress.sin_port )
00610 << ": numero maximo de sessoes " << SessionManager->m_MaxSessions
00611 << " atingido! Terminando a thread do cliente!" << endl;
00612
00613 if( SessionManager->m_log.is_open() )
00614 {
00615 char *info = myInfo();
00616 SessionManager->m_log << info
00617 << "Too many sessions opened."
00618 << " Refusing new session" << endl;
00619 free( info );
00620 }
00621 pthread_mutex_unlock( &SessionManager->m_mutex );
00622 Status = TCPconnection.ReceiveCall( &Class, &Method,
00623 Parameter, ParameterSize );
00624 Status = ERROR_SESSIONMANAGER + ERROR_MAX_SESSIONS;
00625
00626 TCPconnection.SendCallError(Status);
00627 if( SessionManager->m_log.is_open() )
00628 {
00629 char *info = myInfo();
00630 SessionManager->m_log << info
00631 << "Exiting Session thread" << endl;
00632 free( info );
00633 }
00634
00635 free( Parameter );
00636 free( Result );
00637
00638 delete ClientParam;
00639
00640 return 0;
00641 }
00642
00643 Session.s_id = i;
00644 SessionManager->m_used++;
00645
00646 Session.SaveLogLine( "Connected", "<<open session>>" );
00647 SessionManager->m_SessionTable[i].Session.Index = i;
00648
00649 #ifdef RIO_DEBUG2
00650 struct tm *date;
00651 time_t segundos;
00652
00653 struct in_addr clientip;
00654 clientip.s_addr = remoteAddress.sin_addr.s_addr;
00655
00656 if( SessionManager->m_log.is_open() )
00657 {
00658 time( &segundos );
00659 date = localtime( &segundos );
00660
00661 char *info = myInfo();
00662 SessionManager->m_log << info
00663 << " New connection accepted. Active Sessions "
00664 << SessionManager->m_used
00665 << ". New client ip: " << inet_ntoa(clientip)
00666 << " port: " << htons( remoteAddress.sin_port )
00667 << endl;
00668 free( info );
00669 }
00670 #endif
00671
00672
00673
00674
00675
00676
00677 SessionManager->m_SessionTable[i].s_ptr = &Session;
00678
00679 pthread_mutex_unlock( &SessionManager->m_mutex );
00680
00681 while( true )
00682 {
00683
00684 Status = TCPconnection.ReceiveCall( &Class, &Method, Parameter,
00685 ParameterSize );
00686
00687
00688 if( FAILED( Status ) )
00689 {
00690 if( Status == (int )(ERROR_RIOTCP + ERROR_CLOSED_CONNECTION) )
00691 {
00692 #ifdef RIO_DEBUG2
00693 RioErr << "[ClientThread] Fechando a conexao do cliente com o "
00694 << "IP "
00695 << inet_ntoa( ClientParam->RemoteAddress.sin_addr )
00696 << " e a porta "
00697 << ntohs( ClientParam->RemoteAddress.sin_port )
00698 << ". Terminando a thread do cliente!" << endl;
00699 #endif
00700
00701 if( SessionManager->m_log.is_open() )
00702 {
00703 char *info = myInfo();
00704 SessionManager->m_log << info
00705 << "Client exiting ... "
00706 << "Closing Connection." << endl;
00707 free( info );
00708 }
00709 }
00710 else
00711 {
00712 #ifdef RIO_DEBUG2
00713 RioErr << "[ClientThread] Erro 0x" << hex << Status << dec
00714 << " (" << GetErrorDescription( Status) << ") ao "
00715 << "executar a funcao ReceiveCall para o cliente com o "
00716 << "IP "
00717 << inet_ntoa( ClientParam->RemoteAddress.sin_addr )
00718 << " e a porta "
00719 << ntohs( ClientParam->RemoteAddress.sin_port )
00720 << ". Terminando a thread do cliente!" << endl;
00721 #endif
00722
00723 if( SessionManager->m_log.is_open() )
00724 {
00725 char *info = myInfo();
00726 SessionManager->m_log << info
00727 << "ERROR on TCP connection receive. "
00728 << "Closing Connection: "
00729 << GetErrorDescription( Status )
00730 << endl;
00731 free( info );
00732 }
00733 }
00734
00735 TCPconnection.Disconnect();
00736 if( SessionManager->m_log.is_open() )
00737 {
00738 char *info = myInfo();
00739 SessionManager->m_log << info
00740 << "Exiting Session thread" << endl;
00741 free( info );
00742 }
00743
00744 free( Parameter );
00745 free( Result );
00746
00747 delete ClientParam;
00748
00749 return(0);
00750 }
00751 else
00752 {
00753 Size = ResultSize;
00754
00755 Status = Session.ExecuteCall( Class, Method,
00756 Parameter, ParameterSize,
00757 &Result, &Size );
00758
00759 #ifdef RIO_DEBUG2
00760 RioErr << "CSessionManager::ClientThread enviando uma mensagem "
00761 << "de " << Size << " bytes." << endl;
00762 #endif
00763
00764 if( FAILED( Status ) )
00765 {
00766 char *info = myInfo();
00767 SessionManager->m_log << info
00768 << "Failed executing call. " << endl;
00769 free( info );
00770
00771 Status = TCPconnection.SendCallError( Status );
00772 }
00773 else
00774 {
00775 Status = TCPconnection.SendResult(Result, Size);
00776 }
00777
00778
00779
00780 if( Size > ResultSize )
00781 {
00782 #ifdef RIO_DEBUG2
00783 RioErr << "CSessionManager::ClientThread Reduzindo tamanho "
00784 << "alocado de " << Size << " bytes para " << ResultSize
00785 << " bytes " << endl;
00786 #endif
00787 char *NewResult = ( char * ) realloc( Result, ResultSize );
00788 if( NewResult == NULL )
00789 RioErr << "CSessionManager::ClientThread falhou em reduzir "
00790 << "o tamanho da area alocada de " << Size
00791 << " para " << ResultSize << ". Tamanho mantido!"
00792 << endl;
00793 else
00794 Result = NewResult;
00795 }
00796
00797 if( FAILED( Status ) )
00798 {
00799 RioErr << "[ClientThread] Erro ao enviar os resultados ao "
00800 << "cliente com o IP "
00801 << inet_ntoa( ClientParam->RemoteAddress.sin_addr )
00802 << " e a porta "
00803 << ntohs( ClientParam->RemoteAddress.sin_port )
00804 << ". Terminando a thread do cliente!" << endl;
00805
00806
00807
00808 TCPconnection.Disconnect();
00809 RioErr << "SessionManager - Exiting Session thread" << endl;
00810
00811 free( Parameter );
00812 free( Result );
00813
00814 delete ClientParam;
00815
00816 return(0);
00817 }
00818 }
00819 }
00820
00821 free( Parameter );
00822 free( Result );
00823
00824 RioErr << "[ClientThread] A thread para o IP "
00825 << inet_ntoa( ClientParam->RemoteAddress.sin_addr )
00826 << " e a porta "
00827 << ntohs( ClientParam->RemoteAddress.sin_port )
00828 << "for terminada no final!" << endl;
00829
00830 delete ClientParam;
00831
00832 return( 0 );
00833 }
00834
00835
00836 int CSessionManager::SaveMeasures()
00837 {
00838 int result1;
00839
00840 result1 = m_StreamManager->SaveMeasures();
00841
00842 return result1;
00843 }
00844
00845
00846 void CSessionManager::GetMonitorTable( vector<ClientData> &clientTable,
00847 vector<StorageData> &storageTable )
00848 {
00849 m_SystemManager->GetMonitorTable( clientTable, storageTable );
00850 }
00851
00852
00853 void CSessionManager::PostITEvent( MonitorEvent *event )
00854 {
00855 m_SystemManager->PostITEvent( event );
00856 }
00857
00858 int CSessionManager::GetVideoDuration( char *VideoName )
00859 {
00860 int video_duration = 0;
00861 double aux_video_duration = 0;
00862 double sum = 0;
00863
00864 char *auxpath;
00865 auxpath = new char[255];
00866 auxpath = strtok( VideoName, "." );
00867
00868 char *path;
00869 path = new char[255];
00870
00871 sprintf( path, "%s/%s.cactimes", m_FileRoot, auxpath );
00872
00873 FILE *CACFile;
00874
00875 if( ( CACFile = fopen ( path, "r" ) ) == NULL )
00876 {
00877 Rioperror( "fopen" );
00878 }
00879 else
00880 {
00881 while( 1 )
00882 {
00883 if( fscanf( CACFile, "%lf", &aux_video_duration ) != 1 )
00884 {
00885 RioErr << "CSessionManager::GetVideoDuration: aviso - erro ao "
00886 << "ler o arquivo " << path << endl;
00887 }
00888 sum += aux_video_duration;
00889
00890 if( feof( CACFile ) )
00891 break;
00892 }
00893 }
00894
00895 video_duration = ( int ) sum;
00896
00897 return( video_duration );
00898 }
00899
00900
00901
00902
00903 void CSessionManager::SetNATMapping( NATData server_map, int stor_id,
00904 NATData stor_map )
00905 {
00906 m_Router->SetNATMapping( server_map, stor_id, stor_map );
00907 }
00908
00909
00910
00911
00912
00913
00914
00915 void CSessionManager::InvalidateStorageNatMappings( int StorageId )
00916 {
00917 NATData StorageNat;
00918
00919
00920 pthread_mutex_lock( &m_mutex );
00921
00922
00923 for( int i = 0; i < m_MaxSessions; i++ )
00924 if( m_SessionTable[ i ].Session.Index != -1 )
00925 {
00926 StorageNat = m_Router->GetNATMapping(
00927 m_SessionTable[ i ].s_ptr->s_ServerNat,
00928 StorageId );
00929
00930 #ifdef RIO_DEBUG2
00931 in_addr ip;
00932 ip.s_addr = StorageNat.nat_addr;
00933 RioErr << "CSessionManager::InvalidateStorageNatMappings "
00934 << " alterando endereco do servidor com a Id "
00935 << StorageId << " do IP " << inet_ntoa( ip ) << " e a porta "
00936 << ntohs( StorageNat.nat_port ) << " para 0.0.0.0 e 0"
00937 << endl;
00938 #endif
00939
00940
00941 StorageNat.nat_addr = -1;
00942 StorageNat.nat_port = 0;
00943 m_Router->SetNATMapping( m_SessionTable[ i ].s_ptr->s_ServerNat,
00944 StorageId, StorageNat );
00945
00946 StorageNat = m_Router->GetNATMapping(
00947 m_SessionTable[ i ].s_ptr->s_ServerNat,
00948 StorageId );
00949
00950 #ifdef RIO_DEBUG2
00951 ip.s_addr = StorageNat.nat_addr;
00952 RioErr << "CSessionManager::InvalidateStorageNatMappings "
00953 << " novo endereco para o servidor com a Id "
00954 << StorageId << ": IP " << inet_ntoa( ip ) << " e a porta "
00955 << ntohs( StorageNat.nat_port ) << endl;
00956 #endif
00957
00958
00959
00960
00961
00962
00963
00964 if( m_Router->FindNATMapping(
00965 m_SessionTable[ i ].s_ptr->s_ServerNat,
00966 StorageId + m_NumberOfStorageNodes ) )
00967 {
00968 StorageNat = m_Router->GetNATMapping(
00969 m_SessionTable[ i ].s_ptr->s_ServerNat,
00970 StorageId + m_NumberOfStorageNodes );
00971
00972 #ifdef RIO_DEBUG2
00973 in_addr ip;
00974 ip.s_addr = StorageNat.nat_addr;
00975 RioErr << "CSessionManager::InvalidateStorageNatMappings "
00976 << " alterando endereco do servidor com a Id "
00977 << StorageId + m_NumberOfStorageNodes << " do IP "
00978 << inet_ntoa( ip ) << " e a porta "
00979 << ntohs( StorageNat.nat_port ) << " para 0.0.0.0 e 0"
00980 << endl;
00981 #endif
00982
00983
00984 StorageNat.nat_addr = -1;
00985 StorageNat.nat_port = 0;
00986 m_Router->SetNATMapping( m_SessionTable[ i ].s_ptr->s_ServerNat,
00987 StorageId + m_NumberOfStorageNodes,
00988 StorageNat );
00989
00990 StorageNat = m_Router->GetNATMapping(
00991 m_SessionTable[ i ].s_ptr->s_ServerNat,
00992 StorageId + m_NumberOfStorageNodes );
00993
00994 #ifdef RIO_DEBUG2
00995 ip.s_addr = StorageNat.nat_addr;
00996 RioErr << "CSessionManager::InvalidateStorageNatMappings "
00997 << " novo endereco para o servidor com a Id "
00998 << StorageId + m_NumberOfStorageNodes << ": IP "
00999 << inet_ntoa( ip ) << " e a porta "
01000 << ntohs( StorageNat.nat_port ) << endl;
01001 #endif
01002 }
01003
01004 }
01005
01006 pthread_mutex_unlock( &m_mutex );
01007 }
01008
01009
01010
01011
01012 void CSessionManager::SetNumberOfDisks( unsigned int NumberOfDisks )
01013 {
01014 m_NumberOfDisks = NumberOfDisks;
01015 }
01016
01017
01018
01019 RioSession::RioSession( CSessionManager *mgr )
01020 {
01021 unsigned int i;
01022
01023 s_CurrentDir[ 0 ] = '\0';
01024 m_alreadyClosed = false;
01025 memset( (char *)&s_remoteAddress, 0, sizeof( SOCKADDR_IN ) );
01026 s_mgr = mgr;
01027 s_user = NULL;
01028 s_id = -1;
01029
01030 for( i = 0; i < s_idmax; i++ )
01031 {
01032 s_idtable[i].id_type = idt_invalid;
01033 s_idtable[i].id_object = 0;
01034 }
01035
01036
01037
01038 s_ServerNat.nat_addr = 0;
01039 s_ServerNat.nat_port = 0;
01040 }
01041
01042
01043
01044 RioSession::RioSession( CSessionManager *mgr, SOCKADDR_IN remoteAddress )
01045 {
01046 unsigned int i;
01047
01048 s_CurrentDir[ 0 ] = '\0';
01049 m_alreadyClosed = false;
01050 s_remoteAddress = remoteAddress;
01051 s_mgr = mgr;
01052 s_user = NULL;
01053 s_id = -1;
01054
01055 for( i = 0; i < s_idmax; i++ )
01056 {
01057 s_idtable[i].id_type = idt_invalid;
01058 s_idtable[i].id_object = 0;
01059 }
01060 }
01061
01062
01063 RioSession::~RioSession()
01064 {
01065 Close();
01066 }
01067
01068
01069
01070
01071
01072
01073
01074
01075
01076
01077
01078
01079
01080
01081
01082
01083
01084
01085
01086
01087
01088
01089
01090
01091
01092
01093
01094
01095
01096
01097
01098
01099 int RioSession::Close()
01100 {
01101 unsigned int i;
01102
01103 if( m_alreadyClosed == false )
01104 {
01105 m_alreadyClosed = true;
01106 }
01107 else
01108 {
01109 return S_OK;
01110 }
01111
01112
01113 #ifdef RIO_DEBUG2
01114 struct in_addr clientip;
01115 clientip.s_addr = s_remoteAddress.sin_addr.s_addr;
01116 s_mgr->m_log << " ip: " << inet_ntoa(clientip)
01117 << " port: " << htons( s_remoteAddress.sin_port )
01118 << " Closing Session." << endl;
01119 #endif
01120
01121
01122 #ifdef RIO_DEBUG2
01123
01124 s_mgr->m_Router->PrintNATMapping();
01125 #endif
01126
01127
01128 if( s_ServerNat.nat_addr != 0 )
01129 {
01130
01131
01132
01133 for( unsigned int i = 0; i <= s_mgr->m_NumberOfStorageNodes; i++ )
01134 s_mgr->m_Router->RemoveNATMapping( s_ServerNat, i );
01135
01136
01137
01138
01139 if( s_mgr->m_Router->FindNATMapping( s_ServerNat,
01140 s_mgr->m_NumberOfStorageNodes + 1 ) )
01141 {
01142 for( unsigned int i = s_mgr->m_NumberOfStorageNodes + 1;
01143 i <= ( 2 * s_mgr->m_NumberOfStorageNodes + 1); i++ )
01144 s_mgr->m_Router->RemoveNATMapping( s_ServerNat, i );
01145
01146 }
01147 }
01148
01149 #ifdef RIO_DEBUG2
01150
01151 s_mgr->m_Router->PrintNATMapping();
01152 #endif
01153
01154
01155 for( i = 0; i < s_idmax; i++ )
01156 {
01157 if( s_idtable[i].id_type == idt_directory )
01158 {
01159 CloseObject(i);
01160 }
01161 }
01162
01163 for( i = 0; i < s_idmax; i++ )
01164 {
01165 if( s_idtable[i].id_type == idt_streamobj )
01166 {
01167 CloseObject(i);
01168 }
01169 }
01170
01171
01172 for( i = 0; i < s_idmax; i++ )
01173 {
01174 if( s_idtable[i].id_type == idt_stream )
01175 {
01176 CloseStream(i);
01177 }
01178 }
01179
01180 if( s_user != 0 )
01181 {
01182 delete s_user;
01183 s_user = 0;
01184 }
01185
01186
01187 if( s_id != -1 )
01188 {
01189 pthread_mutex_lock( &s_mgr->m_mutex );
01190 s_mgr->m_used--;
01191
01192 SaveLogLine( "Disconnected", "<<close session>>" );
01193 s_mgr->m_SessionTable[s_id].Session.Index = -1;
01194 s_mgr->m_SessionTable[s_id].Session.Version = 0;
01195 s_mgr->m_SessionTable[s_id].s_ptr = 0;
01196 s_id = -1;
01197 pthread_mutex_unlock(&s_mgr->m_mutex);
01198 }
01199
01200 return S_OK;
01201 }
01202
01203
01204
01205
01206
01207 void *RioSession::checkid( int id, idtype type )
01208 {
01209 if( ( unsigned ) id > ( unsigned ) s_idmax )
01210 {
01211 RioErr << " Session " << this << " Error: id (" << id
01212 << ") > s_idmax (" << s_idmax << ")"
01213 << endl;
01214 return 0;
01215 }
01216 if( s_idtable[id].id_type != type )
01217 {
01218 return 0;
01219 }
01220 return s_idtable[id].id_object;
01221 }
01222
01223
01224
01225
01226 void **RioSession::newid( int *id, idtype type )
01227 {
01228 unsigned int i;
01229
01230
01231 for( i = 0; i < s_idmax; i++ )
01232 {
01233 if( s_idtable[i].id_type == idt_invalid )
01234 {
01235 s_idtable[i].id_type = type;
01236 *id = i;
01237 return &s_idtable[i].id_object;
01238 }
01239 }
01240 RioErr << "Error: Could not create id " << -1 << endl;
01241 *id = -1;
01242 return 0;
01243 }
01244
01245
01246
01247 int RioSession::DataRequest( u32 reqid, u32 ipaddr, u32 objid, u32 block,
01248 u32 repbits, u16 port, u16 operation )
01249 {
01250 RioStreamObj *op;
01251
01252 #ifdef RIO_DEBUG2
01253 unsigned long long int curTime;
01254 struct timeval arriv_time;
01255 struct in_addr LocalIPaddress;
01256 LocalIPaddress.s_addr = ipaddr;
01257 gettimeofday( &arriv_time, NULL );
01258 curTime = arriv_time.tv_sec * 1000000 + arriv_time.tv_usec;
01259
01260 RioErr << "RioSession.DataRequest: "
01261 << " ipaddr " << inet_ntoa(LocalIPaddress )
01262 << " port " << ntohs( port )
01263 << " reqid " << reqid
01264 << " objid " << objid
01265 << " block " << block
01266 << " operation " << operation
01267 << " curTime " << curTime << endl;
01268 #endif
01269
01270
01271
01272
01273
01274
01275
01276
01277
01278
01279
01280 if( objid > RioSession::s_idmax )
01281 {
01282 return ERROR_SESSIONMANAGER + 0xfa;
01283 }
01284 if( s_idtable[objid].id_type != idt_streamobj )
01285 {
01286 return ERROR_SESSIONMANAGER + 0xfb;
01287 }
01288
01289 op = ( RioStreamObj * )s_idtable[objid].id_object;
01290
01291 return( op->DataRequest( reqid, operation, ipaddr, port, block, repbits ));
01292 }
01293
01294
01295
01296 int RioSession::SaveMeasures()
01297 {
01298 return( s_mgr->SaveMeasures());
01299 }
01300
01301 int RioSession::GetMonitorTable( vector<ClientData> &clientTable,
01302 vector<StorageData> &storageTable )
01303 {
01304 s_mgr->GetMonitorTable( clientTable, storageTable );
01305 return 0;
01306 }
01307
01308
01309 int RioSession::ExecuteCall( unsigned int Class,
01310 unsigned int Method,
01311 char* Parameter,
01312 unsigned int ParameterSize,
01313 char** Result,
01314 unsigned int *ResultSize )
01315 {
01316 #ifdef RIO_DEBUG2
01317 RioErr << "RioSession::ExecuteCall executando chamada da classe com id "
01318 << "igual a " << Class << ", e o metodo com id " << Method
01319 << " desta classe." << endl;
01320 #endif
01321
01322 switch(Class)
01323 {
01324 case RioClassSessionManager:
01325 {
01326 return ExecuteSessionManager( Method, Parameter, ParameterSize,
01327 Result, ResultSize );
01328 }
01329 case RioClassStreamManager:
01330 {
01331 return ExecuteStreamManager ( Method, Parameter, ParameterSize,
01332 Result, ResultSize );
01333 }
01334 case RioClassObjectManager:
01335 {
01336 return ExecuteObjectManager ( Method, Parameter, ParameterSize,
01337 Result, ResultSize );
01338 }
01339 case RioClassRouter:
01340 {
01341 return ExecuteRouter( Method, Parameter, ParameterSize,
01342 Result, ResultSize );
01343 }
01344
01345 case RioClassUserManager:
01346 {
01347 return ExecuteUserManager( Method, Parameter, ParameterSize,
01348 Result, ResultSize );
01349 }
01350
01351 default:
01352 {
01353 RioErr << "Executecall: invalid class " << endl;
01354 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_CLASS;
01355 }
01356 }
01357
01358 return S_OK;
01359 }
01360
01361
01362 int RioSession::ExecuteSessionManager( unsigned int Method,
01363 char* Parameter,
01364 unsigned int ParameterSize,
01365 char** Result,
01366 unsigned int *ResultSize )
01367 {
01368 int offset = 0;
01369 unsigned int Size;
01370
01371 switch( Method )
01372 {
01373
01374 case RioMethodSessionManagerOpen:
01375 {
01376 char* UserName;
01377 char* Password;
01378 bool CanRead, CanWrite;
01379 HRESULT hresult;
01380
01381 offset = 0;
01382
01383 #ifdef RIO_DEBUG2
01384 struct in_addr clientip;
01385 clientip.s_addr = s_remoteAddress.sin_addr.s_addr;
01386 if( s_mgr->m_log.is_open() )
01387 s_mgr->m_log << " ip: " << inet_ntoa(clientip )
01388 << " port: " << htons( s_remoteAddress.sin_port )
01389 << " opening session " << endl;
01390 #endif
01391
01392
01393
01394
01395
01396 if(!GetString( Parameter, ParameterSize, &UserName, &offset ))
01397 {
01398 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
01399 }
01400
01401 if(!GetString( Parameter, ParameterSize, &Password, &offset ))
01402 {
01403 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
01404 }
01405
01406
01407
01408
01409
01410 s_mgr->m_Router->GetStorageInfo( s_ServerNat, &CanRead, &CanWrite );
01411
01412 if( ( CanRead ) && ( CanWrite ) )
01413 {
01414
01415 hresult = Open( UserName, Password );
01416 }
01417 else
01418 hresult = ERROR_SESSIONMANAGER +
01419 ERROR_SERVICE_TEMPORARY_UNAVAILABLE;
01420
01421
01422 Size = 3 * MAX_LONG_STRING_SIZE;
01423 if( Size > *ResultSize )
01424 {
01425 Close();
01426 return ERROR_CONNECTIONMANAGER + ERROR_RESULT_MESSAGE_OVERFLOW;
01427 }
01428 offset = 0;
01429
01430
01431 SetLong( *Result, hresult, &offset );
01432
01433 SetLong( *Result, 2000, &offset );
01434 SetLong( *Result, 1, &offset );
01435
01436 unsigned int BlockSize;
01437
01438 GetBlockSize( &BlockSize );
01439
01440
01441 SetULong( *Result, BlockSize, &offset );
01442
01443
01444
01445 *ResultSize = offset;
01446 return S_OK;
01447 }
01448
01449 case RioMethodSessionManagerClose:
01450 {
01451 RioSessionId Session;
01452 offset = 0;
01453
01454 #ifdef RIO_DEBUG2
01455 struct in_addr clientip;
01456 clientip.s_addr = s_remoteAddress.sin_addr.s_addr;
01457 if( s_mgr->m_log.is_open() )
01458 s_mgr->m_log << " ip: " << inet_ntoa(clientip )
01459 << " port: " << htons( s_remoteAddress.sin_port )
01460 << " closing session " << endl;
01461 #endif
01462
01463
01464
01465
01466
01467 if(!GetLong( Parameter, ParameterSize,
01468 &(Session.Version), &offset )
01469 )
01470 {
01471 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
01472 }
01473 if(!GetLong( Parameter, ParameterSize, &(Session.Index), &offset ))
01474 {
01475 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
01476 }
01477
01478
01479 HRESULT hresult = Close();
01480
01481
01482 Size = MAX_LONG_STRING_SIZE;
01483 if( Size > *ResultSize )
01484 {
01485 return ERROR_CONNECTIONMANAGER + ERROR_RESULT_MESSAGE_OVERFLOW;
01486 }
01487 offset = 0;
01488
01489
01490 SetLong( *Result, hresult, &offset );
01491
01492
01493 *ResultSize = offset;
01494
01495 return S_OK;
01496 }
01497
01498 case RioMethodSessionManagerOpenStream:
01499 {
01500 RioSessionId Session;
01501 RioStreamTraffic Traffic;
01502 RioStreamId Stream;
01503 offset = 0;
01504
01505 #ifdef RIO_DEBUG2
01506 struct in_addr clientip;
01507 clientip.s_addr = s_remoteAddress.sin_addr.s_addr;
01508 if( s_mgr->m_log.is_open() )
01509 s_mgr->m_log << " ip: " << inet_ntoa(clientip )
01510 << " port: " << htons( s_remoteAddress.sin_port )
01511 << " opening stream " << endl;
01512 #endif
01513
01514
01515
01516
01517
01518 if(!GetLong( Parameter, ParameterSize,
01519 &(Session.Version), &offset )
01520 )
01521 {
01522 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
01523 }
01524 if(!GetLong( Parameter, ParameterSize, &(Session.Index), &offset ))
01525 {
01526 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
01527 }
01528
01529
01530 short shortvalue;
01531 if(!GetShort( Parameter, ParameterSize, &shortvalue, &offset ))
01532 {
01533 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
01534 }
01535 Traffic.Type = ( RioTrafficType ) shortvalue;
01536
01537 if(!GetShort( Parameter, ParameterSize, &shortvalue, &offset ))
01538 {
01539 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
01540 }
01541 Traffic.Direction = ( RioStreamDirection ) shortvalue;
01542
01543 if( !GetULong( Parameter, ParameterSize,
01544 &(Traffic.LogicalBlockSize), &offset )
01545 )
01546 {
01547 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
01548 }
01549 if( !GetLong( Parameter, ParameterSize, &(Traffic.MaxRequests),
01550 &offset ))
01551 {
01552 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
01553 }
01554
01555 if( Traffic.Type == RIO_TRAFFIC_CBR )
01556 {
01557 if( !GetDouble( Parameter, ParameterSize,
01558 &(Traffic.TrafficCBR.Rate), &offset ))
01559 {
01560 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
01561 }
01562 }
01563 if( Traffic.Type == RIO_TRAFFIC_VBR )
01564 {
01565 if( !GetDouble( Parameter, ParameterSize,
01566 &(Traffic.TrafficVBR.Rate), &offset ))
01567 {
01568 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
01569 }
01570 }
01571 if( Traffic.Type == RIO_TRAFFIC_NRT )
01572 {
01573 if( !GetULong( Parameter, ParameterSize,
01574 &(Traffic.TrafficNRT.Reserved), &offset ))
01575 {
01576 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
01577 }
01578 }
01579
01580
01581 HRESULT hresult = OpenStream( &Traffic, &Stream.Index );
01582
01583
01584 Size = 3 * MAX_LONG_STRING_SIZE;
01585 if( Size > *ResultSize )
01586 {
01587 return ERROR_CONNECTIONMANAGER + ERROR_RESULT_MESSAGE_OVERFLOW;
01588 }
01589 offset = 0;
01590
01591
01592 SetLong( *Result, hresult, &offset );
01593
01594
01595 SetLong( *Result, Stream.Version, &offset );
01596 SetLong( *Result, Stream.Index, &offset );
01597
01598
01599 hresult = StreamMaxRequests( Stream.Index );
01600 SetLong( *Result, hresult, &offset );
01601
01602
01603
01604 *ResultSize = offset;
01605 return S_OK;
01606
01607 }
01608
01609 case RioMethodSessionManagerCreateObject:
01610 {
01611 RioSessionId Session;
01612 char* ObjectName;
01613 short Type;
01614
01615 offset = 0;
01616
01617 #ifdef RIO_DEBUG2
01618 struct in_addr clientip;
01619 clientip.s_addr = s_remoteAddress.sin_addr.s_addr;
01620 if( s_mgr->m_log.is_open() )
01621 s_mgr->m_log << " ip: " << inet_ntoa(clientip )
01622 << " port: " << htons( s_remoteAddress.sin_port )
01623 << " creating object " << endl;
01624 #endif
01625
01626
01627
01628
01629 if( !GetLong( Parameter, ParameterSize,
01630 &(Session.Version), &offset )
01631 )
01632 {
01633 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
01634 }
01635 if( !GetLong( Parameter, ParameterSize,
01636 &(Session.Index), &offset )
01637 )
01638 {
01639 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
01640 }
01641
01642
01643 if( !GetString(Parameter, ParameterSize, &ObjectName, &offset ) )
01644 {
01645 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
01646 }
01647
01648 short shortvalue;
01649 if( !GetShort(Parameter, ParameterSize, &shortvalue, &offset ) )
01650 {
01651 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
01652 }
01653 Type = shortvalue;
01654
01655
01656 HRESULT hresult = CreateObject( ObjectName, Type );
01657
01658
01659 Size = MAX_LONG_STRING_SIZE;
01660 if( Size > *ResultSize )
01661 {
01662 return ERROR_CONNECTIONMANAGER + ERROR_RESULT_MESSAGE_OVERFLOW;
01663 }
01664 offset = 0;
01665
01666
01667 SetLong( *Result, hresult, &offset );
01668
01669
01670 *ResultSize = offset;
01671
01672 return S_OK;
01673
01674 }
01675
01676 case RioMethodSessionManagerDeleteObject:
01677 {
01678 RioSessionId Session;
01679 char* ObjectName;
01680
01681 #ifdef RIO_DEBUG2
01682 struct in_addr clientip;
01683 clientip.s_addr = s_remoteAddress.sin_addr.s_addr;
01684 if( s_mgr->m_log.is_open() )
01685 s_mgr->m_log << " ip: " << inet_ntoa(clientip )
01686 << " port: " << htons( s_remoteAddress.sin_port )
01687 << " deleting object " << endl;
01688 #endif
01689
01690
01691 offset = 0;
01692
01693
01694
01695 if( !GetLong( Parameter, ParameterSize,
01696 &(Session.Version), &offset )
01697 )
01698 {
01699 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
01700 }
01701 if( !GetLong( Parameter, ParameterSize,
01702 &(Session.Index), &offset )
01703 )
01704 {
01705 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
01706 }
01707
01708
01709 if( !GetString(Parameter, ParameterSize, &ObjectName, &offset ) )
01710 {
01711 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
01712 }
01713
01714
01715 HRESULT hresult = DeleteObject( ObjectName );
01716
01717
01718 Size = MAX_LONG_STRING_SIZE;
01719 if( Size > *ResultSize )
01720 {
01721 return ERROR_CONNECTIONMANAGER + ERROR_RESULT_MESSAGE_OVERFLOW;
01722 }
01723 offset = 0;
01724
01725
01726 SetLong( *Result, hresult, &offset );
01727
01728
01729 *ResultSize = offset;
01730
01731 return S_OK;
01732
01733 }
01734
01735 case RioMethodSessionManagerRenameObject:
01736 {
01737 RioSessionId Session;
01738 char* CurrentName;
01739 char* NewName;
01740
01741 #ifdef RIO_DEBUG2
01742 struct in_addr clientip;
01743 clientip.s_addr = s_remoteAddress.sin_addr.s_addr;
01744 if( s_mgr->m_log.is_open() )
01745 s_mgr->m_log << " ip: " << inet_ntoa(clientip )
01746 << " port: " << htons( s_remoteAddress.sin_port )
01747 << " rename object " << endl;
01748 #endif
01749
01750 offset = 0;
01751
01752
01753
01754 if( !GetLong( Parameter, ParameterSize, &(Session.Version),
01755 &offset ) )
01756 {
01757 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
01758 }
01759 if( !GetLong( Parameter, ParameterSize, &(Session.Index),
01760 &offset ) )
01761 {
01762 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
01763 }
01764
01765
01766 if( !GetString( Parameter, ParameterSize, &CurrentName, &offset ) )
01767 {
01768 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
01769 }
01770
01771
01772 if( !GetString( Parameter, ParameterSize, &NewName, &offset ) )
01773 {
01774 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
01775 }
01776
01777
01778 HRESULT hresult = RenameObject( CurrentName, NewName );
01779
01780
01781 Size = MAX_LONG_STRING_SIZE;
01782 if( Size > *ResultSize )
01783 {
01784 return ERROR_CONNECTIONMANAGER + ERROR_RESULT_MESSAGE_OVERFLOW;
01785 }
01786 offset = 0;
01787
01788
01789 SetLong( *Result, hresult, &offset );
01790
01791
01792 *ResultSize = offset;
01793
01794 return S_OK;
01795
01796 }
01797
01798 case RioMethodSessionManagerGetBlockSize:
01799 {
01800 RioSessionId Session;
01801 unsigned int BlockSize;
01802
01803 #ifdef RIO_DEBUG2
01804 struct in_addr clientip;
01805 clientip.s_addr = s_remoteAddress.sin_addr.s_addr;
01806 if( s_mgr->m_log.is_open() )
01807 s_mgr->m_log << " ip: " << inet_ntoa(clientip )
01808 << " port: " << htons( s_remoteAddress.sin_port )
01809 << " getting block size " << endl;
01810 #endif
01811
01812
01813 offset = 0;
01814
01815
01816
01817 if( !GetLong( Parameter, ParameterSize, &(Session.Version),
01818 &offset ) )
01819 {
01820 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
01821 }
01822 if( !GetLong( Parameter, ParameterSize, &(Session.Index),
01823 &offset ) )
01824 {
01825 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
01826 }
01827
01828
01829 HRESULT hresult = GetBlockSize( &BlockSize );
01830
01831
01832 Size = MAX_LONG_STRING_SIZE + MAX_ULONG_STRING_SIZE;
01833 if( Size > *ResultSize )
01834 {
01835 return ERROR_CONNECTIONMANAGER + ERROR_RESULT_MESSAGE_OVERFLOW;
01836 }
01837 offset = 0;
01838
01839
01840 SetLong( *Result, hresult, &offset );
01841
01842 SetULong( *Result, BlockSize, &offset );
01843
01844
01845 *ResultSize = offset;
01846 return S_OK;
01847
01848 }
01849
01850 case RioMethodSessionManagerFirstObject:
01851 {
01852 RioSessionId Session;
01853 char* DirectoryName;
01854 int BufferSize;
01855 ObjectHandle Handle;
01856 int IsDirectory;
01857
01858 #ifdef RIO_DEBUG2
01859 struct in_addr clientip;
01860 clientip.s_addr = s_remoteAddress.sin_addr.s_addr;
01861 if( s_mgr->m_log.is_open() )
01862 s_mgr->m_log << " ip: " << inet_ntoa(clientip )
01863 << " port: " << htons( s_remoteAddress.sin_port )
01864 << " first object " << endl;
01865 #endif
01866
01867
01868 offset = 0;
01869
01870
01871
01872 if( !GetLong( Parameter, ParameterSize, &(Session.Version),
01873 &offset ) )
01874 {
01875 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
01876 }
01877 if( !GetLong( Parameter, ParameterSize, &(Session.Index),
01878 &offset ) )
01879 {
01880 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
01881 }
01882
01883
01884 if( !GetString(Parameter, ParameterSize, &DirectoryName, &offset ) )
01885 {
01886 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
01887 }
01888
01889
01890 if( !GetLong(Parameter, ParameterSize, &BufferSize, &offset ) )
01891 {
01892 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
01893 }
01894
01895 char *ObjectName = new char [BufferSize];
01896
01897
01898 HRESULT hresult = FirstObject( DirectoryName, &Handle.Index,
01899 &IsDirectory, BufferSize,
01900 ObjectName );
01901
01902
01903 Size = 4 * MAX_LONG_STRING_SIZE + BufferSize + 1;
01904 if( Size > *ResultSize )
01905 {
01906 delete[] ObjectName;
01907 return ERROR_CONNECTIONMANAGER + ERROR_RESULT_MESSAGE_OVERFLOW;
01908 }
01909 offset = 0;
01910
01911
01912 SetLong( *Result, hresult, &offset );
01913
01914 SetLong( *Result, Handle.Version, &offset );
01915 SetLong( *Result, Handle.Index, &offset );
01916
01917
01918 SetLong( *Result, IsDirectory, &offset );
01919
01920
01921 SetString( *Result, ObjectName, &offset );
01922
01923
01924 *ResultSize = offset;
01925
01926 delete[] ObjectName;
01927
01928 return S_OK;
01929 }
01930
01931
01932 case RioMethodSessionManagerChangeDir:
01933 {
01934 RioSessionId Session;
01935 char* DirectoryName;
01936
01937 #ifdef RIO_DEBUG2
01938 struct in_addr clientip;
01939 clientip.s_addr = s_remoteAddress.sin_addr.s_addr;
01940 if( s_mgr->m_log.is_open() ) s_mgr->m_log << " ip: " << inet_ntoa(clientip )
01941 << " port: " << htons( s_remoteAddress.sin_port )
01942 << " change Dir " << endl;
01943 #endif
01944
01945
01946 offset = 0;
01947
01948
01949
01950 if( !GetLong( Parameter, ParameterSize, &(Session.Version),
01951 &offset ) )
01952 {
01953 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
01954 }
01955 if( !GetLong( Parameter, ParameterSize, &(Session.Index),
01956 &offset ) )
01957 {
01958 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
01959 }
01960
01961
01962 if( !GetString(Parameter, ParameterSize, &DirectoryName, &offset ) )
01963 {
01964 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
01965 }
01966
01967
01968 HRESULT hresult = ChangeDir( DirectoryName );
01969
01970
01971 Size = MAX_LONG_STRING_SIZE + 1;
01972 if( Size > *ResultSize )
01973 {
01974 return ERROR_CONNECTIONMANAGER + ERROR_RESULT_MESSAGE_OVERFLOW;
01975 }
01976 offset = 0;
01977
01978
01979 SetLong( *Result, hresult, &offset );
01980
01981
01982 *ResultSize = offset;
01983
01984 return S_OK;
01985 }
01986
01987
01988 case RioMethodSessionManagerGetCurrentDir:
01989 {
01990 RioSessionId Session;
01991 int BufferSize;
01992
01993 #ifdef RIO_DEBUG2
01994 struct in_addr clientip;
01995 clientip.s_addr = s_remoteAddress.sin_addr.s_addr;
01996 if( s_mgr->m_log.is_open() )
01997 s_mgr->m_log << " ip: " << inet_ntoa(clientip )
01998 << " port: " << htons( s_remoteAddress.sin_port )
01999 << " get current Dir " << endl;
02000 #endif
02001
02002
02003 offset = 0;
02004
02005
02006
02007 if( !GetLong( Parameter, ParameterSize, &(Session.Version),
02008 &offset ) )
02009 {
02010 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
02011 }
02012 if( !GetLong( Parameter, ParameterSize, &(Session.Index),
02013 &offset ) )
02014 {
02015 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
02016 }
02017
02018
02019 if( !GetLong( Parameter, ParameterSize, &BufferSize, &offset ) )
02020 {
02021 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
02022 }
02023
02024 char *DirName = new char [BufferSize];
02025
02026
02027
02028 HRESULT hresult = GetCurrentDir( BufferSize, DirName );
02029
02030
02031 Size = MAX_LONG_STRING_SIZE + BufferSize + 1;
02032 if( Size > *ResultSize )
02033 {
02034 delete[] DirName;
02035 return ERROR_CONNECTIONMANAGER + ERROR_RESULT_MESSAGE_OVERFLOW;
02036 }
02037 offset = 0;
02038
02039
02040 SetLong( *Result, hresult, &offset );
02041
02042
02043 SetString( *Result, DirName, &offset );
02044
02045
02046 *ResultSize = offset;
02047
02048 delete[] DirName;
02049
02050 return S_OK;
02051 }
02052
02053 case RioMethodSessionManagerGetObjectInfo:
02054 {
02055 RioSessionId Session;
02056 char* ObjectName;
02057
02058 char md5sum[33];
02059
02060 ObjectInfo ObjectInfo;
02061
02062 #ifdef RIO_DEBUG2
02063 struct in_addr clientip;
02064 clientip.s_addr = s_remoteAddress.sin_addr.s_addr;
02065 if( s_mgr->m_log.is_open() )
02066 s_mgr->m_log << " ip: " << inet_ntoa(clientip )
02067 << " port: " << htons( s_remoteAddress.sin_port )
02068 << " get object info" << endl;
02069 #endif
02070
02071
02072 offset = 0;
02073
02074
02075
02076 if( !GetLong( Parameter, ParameterSize, &(Session.Version),
02077 &offset ) )
02078 {
02079 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
02080 }
02081 if( !GetLong( Parameter, ParameterSize, &(Session.Index),
02082 &offset ) )
02083 {
02084 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
02085 }
02086
02087
02088 if( !GetString( Parameter, ParameterSize, &ObjectName, &offset ) )
02089 {
02090 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
02091 }
02092
02093
02094 HRESULT hresult = GetObjectInfo( ObjectName, &ObjectInfo );
02095
02096
02097 ObjectInfo.getMd5sum( md5sum );
02098
02099 Size = MAX_LONG_STRING_SIZE +
02100 MAX_SHORT_STRING_SIZE +
02101 MAX_SHORT_STRING_SIZE +
02102 3 * MAX_ULONG_STRING_SIZE +
02103
02104
02105
02106
02107 6 * MAX_SHORT_STRING_SIZE +
02108 strlen( ( char * ) ObjectInfo.getOwner().c_str() ) + 1 +
02109 strlen( ( char * ) ObjectInfo.getGroup().c_str() ) + 1 +
02110 MD5SIZE + 1 +
02111 1;
02112 if( Size > *ResultSize )
02113 {
02114 return ERROR_CONNECTIONMANAGER + ERROR_RESULT_MESSAGE_OVERFLOW;
02115 }
02116 offset = 0;
02117
02118
02119 SetLong( *Result, hresult, &offset );
02120
02121
02122
02123
02124 SetShort( *Result, ObjectInfo.getType(), &offset );
02125
02126
02127 SetShort( *Result, ObjectInfo.getPermission(), &offset );
02128
02129
02130 unsigned int highpart =
02131 ( unsigned int )(( ObjectInfo.getSize() >> 32 )
02132 & 0xffffffff );
02133 unsigned int lowpart = ( unsigned int )( ObjectInfo.getSize()
02134 & 0xffffffff );
02135 SetULong( *Result, highpart, &offset );
02136 SetULong( *Result, lowpart, &offset );
02137
02138
02139
02140 SetShort( *Result, ObjectInfo.getTime().Year, &offset );
02141
02142 SetShort( *Result, ObjectInfo.getTime().Month, &offset );
02143
02144 SetShort( *Result, ObjectInfo.getTime().DayOfWeek, &offset );
02145
02146 SetShort( *Result, ObjectInfo.getTime().Day, &offset );
02147
02148 SetShort( *Result, ObjectInfo.getTime().Hour, &offset );
02149
02150 SetShort( *Result, ObjectInfo.getTime().Minute, &offset );
02151
02152
02153 SetString( *Result, (char*)ObjectInfo.getOwner().c_str(), &offset );
02154
02155 SetString( *Result, (char*)ObjectInfo.getGroup().c_str(), &offset );
02156
02157
02158
02159 SetULong( *Result, ObjectInfo.getVideoRate(), &offset );
02160
02161
02162 SetString( *Result, md5sum, &offset );
02163
02164
02165 *ResultSize = offset;
02166
02167 return S_OK;
02168 }
02169
02170
02171 case RioMethodSessionManagerGetNumberOfDisks:
02172 {
02173 RioSessionId Session;
02174 unsigned int NumberOfDisks;
02175
02176 #ifdef RIO_DEBUG2
02177 struct in_addr clientip;
02178 clientip.s_addr = s_remoteAddress.sin_addr.s_addr;
02179 if( s_mgr->m_log.is_open() )
02180 s_mgr->m_log << " ip: " << inet_ntoa(clientip )
02181 << " port: " << htons( s_remoteAddress.sin_port )
02182 << " get number of disks " << endl;
02183 #endif
02184
02185 offset = 0;
02186
02187
02188
02189 if( !GetLong( Parameter, ParameterSize, &(Session.Version),
02190 &offset ) )
02191 {
02192 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
02193 }
02194 if( !GetLong( Parameter, ParameterSize, &(Session.Index),
02195 &offset ) )
02196 {
02197 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
02198 }
02199
02200
02201 HRESULT hresult = GetNumberOfDisks( &NumberOfDisks );
02202
02203
02204 Size = MAX_LONG_STRING_SIZE + MAX_ULONG_STRING_SIZE;
02205 if( Size > *ResultSize )
02206 {
02207 return ERROR_CONNECTIONMANAGER + ERROR_RESULT_MESSAGE_OVERFLOW;
02208 }
02209 offset = 0;
02210
02211
02212 SetLong( *Result, hresult, &offset );
02213
02214 SetULong( *Result, NumberOfDisks, &offset );
02215
02216
02217 *ResultSize = offset;
02218
02219 return S_OK;
02220 }
02221
02222
02223 case RioMethodSessionManagerGetNumberOfStorageNodes:
02224 {
02225 RioSessionId Session;
02226 unsigned int NumberOfStorageNodes;
02227
02228 #ifdef RIO_DEBUG2
02229 struct in_addr clientip;
02230 clientip.s_addr = s_remoteAddress.sin_addr.s_addr;
02231 if( s_mgr->m_log.is_open() )
02232 s_mgr->m_log << " ip: " << inet_ntoa(clientip )
02233 << " port: " << htons( s_remoteAddress.sin_port )
02234 << " get number of storage nodes " << endl;
02235 #endif
02236
02237 offset = 0;
02238
02239
02240
02241 if( !GetLong( Parameter, ParameterSize, &(Session.Version),
02242 &offset ) )
02243 {
02244 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
02245 }
02246 if( !GetLong( Parameter, ParameterSize, &(Session.Index),
02247 &offset ) )
02248 {
02249 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
02250 }
02251
02252
02253 HRESULT hresult = GetNumberOfStorageNodes( &NumberOfStorageNodes );
02254
02255
02256 Size = MAX_LONG_STRING_SIZE + MAX_ULONG_STRING_SIZE;
02257 if( Size > *ResultSize )
02258 {
02259 return ERROR_CONNECTIONMANAGER + ERROR_RESULT_MESSAGE_OVERFLOW;
02260 }
02261 offset = 0;
02262
02263
02264 SetLong( *Result, hresult, &offset );
02265
02266 SetULong( *Result, NumberOfStorageNodes, &offset );
02267
02268
02269 *ResultSize = offset;
02270
02271 return S_OK;
02272 }
02273
02274
02275 case RioMethodSessionManagerGetStorageNodeInfo:
02276 {
02277 RioSessionId Session;
02278 unsigned int StorageNodeIndex;
02279 RioStorageNodeInfo StorageNodeInfo;
02280
02281 #ifdef RIO_DEBUG2
02282 struct in_addr clientip;
02283 clientip.s_addr = s_remoteAddress.sin_addr.s_addr;
02284 if( s_mgr->m_log.is_open() )
02285 s_mgr->m_log << " ip: " << inet_ntoa(clientip )
02286 << " port: " << htons( s_remoteAddress.sin_port )
02287 << " get storage node info " << endl;
02288 #endif
02289
02290 offset = 0;
02291
02292
02293
02294 if( !GetLong( Parameter, ParameterSize, &(Session.Version),
02295 &offset ) )
02296 {
02297 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
02298 }
02299 if( !GetLong( Parameter, ParameterSize, &(Session.Index),
02300 &offset ) )
02301 {
02302 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
02303 }
02304
02305 if( !GetULong( Parameter, ParameterSize, &StorageNodeIndex,
02306 &offset ) )
02307 {
02308 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
02309 }
02310
02311
02312 HRESULT hresult = GetStorageNodeInfo( StorageNodeIndex,
02313 &StorageNodeInfo );
02314
02315
02316 Size = MAX_LONG_STRING_SIZE +
02317 60 + MAX_SHORT_STRING_SIZE +
02318 4* ( 60 + ( 3 * MAX_ULONG_STRING_SIZE )) + 1;
02319
02320 if( Size > *ResultSize )
02321 {
02322 return ERROR_CONNECTIONMANAGER + ERROR_RESULT_MESSAGE_OVERFLOW;
02323 }
02324 offset = 0;
02325
02326
02327 SetLong( *Result, hresult, &offset );
02328
02329
02330
02331
02332 SetString( *Result, (char*)StorageNodeInfo.Hostname, &offset );
02333
02334 SetShort( *Result, StorageNodeInfo.NumberOfDisks, &offset );
02335
02336 int i;
02337
02338 for( i = 0; i < (int) StorageNodeInfo.NumberOfDisks; i++ )
02339 {
02340
02341 SetString( *Result, ( char* )StorageNodeInfo.Disks[i].DiskName,
02342 &offset );
02343
02344 unsigned int highpart = ( unsigned int )
02345 (( StorageNodeInfo.Disks[i].Size >> 32 ) & 0xffffffff );
02346 unsigned int lowpart = ( unsigned int )
02347 ( StorageNodeInfo.Disks[i].Size & 0xffffffff );
02348 SetULong( *Result, highpart, &offset );
02349 SetULong( *Result, lowpart, &offset );
02350
02351 SetULong( *Result, StorageNodeInfo.Disks[i].NumberOfFreeBlocks,
02352 &offset );
02353 }
02354
02355 *ResultSize = offset;
02356
02357 return S_OK;
02358 }
02359
02360
02361 case RioMethodSessionManagerGetNumberOfActiveAndMaxSessions:
02362 {
02363 RioSessionId Session;
02364 unsigned int NumberOfActiveSessions;
02365 unsigned int NumberOfMaxSessions;
02366
02367 #ifdef RIO_DEBUG2
02368 struct in_addr clientip;
02369 clientip.s_addr = s_remoteAddress.sin_addr.s_addr;
02370 if( s_mgr->m_log.is_open() )
02371 s_mgr->m_log << " ip: " << inet_ntoa(clientip )
02372 << " port: " << htons( s_remoteAddress.sin_port )
02373 << " get number of active and max sessions "
02374 << endl;
02375 #endif
02376
02377 offset = 0;
02378
02379
02380
02381 if( !GetLong( Parameter, ParameterSize, &(Session.Version),
02382 &offset ) )
02383 {
02384 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
02385 }
02386 if( !GetLong( Parameter, ParameterSize, &(Session.Index),
02387 &offset ) )
02388 {
02389 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
02390 }
02391
02392
02393 HRESULT hresult = GetNumberOfActiveAndMaxSessions(
02394 &NumberOfActiveSessions,
02395 &NumberOfMaxSessions );
02396
02397
02398 Size = MAX_LONG_STRING_SIZE + 2 * MAX_ULONG_STRING_SIZE;
02399 if( Size > *ResultSize )
02400 {
02401 return ERROR_CONNECTIONMANAGER + ERROR_RESULT_MESSAGE_OVERFLOW;
02402 }
02403 offset = 0;
02404
02405
02406 SetLong( *Result, hresult, &offset );
02407
02408 SetULong( *Result, NumberOfActiveSessions, &offset );
02409
02410 SetULong( *Result, NumberOfMaxSessions, &offset );
02411
02412
02413 *ResultSize = offset;
02414
02415 return S_OK;
02416 }
02417
02418
02419 case RioMethodSessionManagerSaveMeasures:
02420 {
02421 RioSessionId Session;
02422
02423 #ifdef RIO_DEBUG2
02424 struct in_addr clientip;
02425 clientip.s_addr = s_remoteAddress.sin_addr.s_addr;
02426 if( s_mgr->m_log.is_open() )
02427 s_mgr->m_log << " ip: " << inet_ntoa(clientip )
02428 << " port: " << htons( s_remoteAddress.sin_port )
02429 << " save measures " << endl;
02430 #endif
02431
02432 offset = 0;
02433
02434
02435 if( !GetLong( Parameter, ParameterSize, &(Session.Version),
02436 &offset ) )
02437 {
02438 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
02439 }
02440 if(!GetLong( Parameter, ParameterSize, &(Session.Index), &offset ))
02441 {
02442 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
02443 }
02444
02445
02446 HRESULT hresult = SaveMeasures();
02447
02448 Size = 3 * MAX_LONG_STRING_SIZE;
02449 if( Size > *ResultSize )
02450 {
02451 Close();
02452 return ERROR_CONNECTIONMANAGER + ERROR_RESULT_MESSAGE_OVERFLOW;
02453 }
02454 offset = 0;
02455
02456
02457 SetLong( *Result, hresult, &offset );
02458
02459
02460 *ResultSize = offset;
02461 return S_OK;
02462 }
02463
02464
02465 case RioMethodSessionManagerGetServerAddress:
02466 {
02467
02468
02469
02470
02471
02472
02473 Size = s_mgr->m_ServerAddressSize * MAX_USHORT_STRING_SIZE +
02474 (s_mgr->m_ServerAddressSize + 1) * MAX_ULONG_STRING_SIZE;
02475 if( Size > *ResultSize )
02476 {
02477 RioErr << "Error: Message too int." << endl;
02478 return ERROR_CONNECTIONMANAGER + ERROR_RESULT_MESSAGE_OVERFLOW;
02479 }
02480 offset = 0;
02481
02482
02483
02484 SetULong( *Result, s_mgr->m_ServerAddressSize, &offset );
02485
02486 for( unsigned int i = 0; i < s_mgr->m_ServerAddressSize; i++ )
02487 {
02488
02489 SetULong( *Result,
02490 ntohl( s_mgr->m_ServerAddress[ i ].sin_addr.s_addr ),
02491 &offset );
02492 SetUShort( *Result, ntohs ( s_mgr->m_ServerAddress[ i ].sin_port ),
02493 &offset );
02494 }
02495
02496 *ResultSize = offset;
02497 return S_OK;
02498 }
02499
02500
02501 case RioMethodSessionManagerGetMonitorTable:
02502 {
02503 char *UserName;
02504 if( !GetString(Parameter, ParameterSize, &UserName, &offset ) )
02505 {
02506 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
02507 }
02508
02509 if( strcmp( UserName, "root") != 0 )
02510 {
02511 return ERROR_CONNECTIONMANAGER + ERROR_PERMISSION_DENIED;
02512 }
02513
02514 vector<ClientData> clientTable;
02515 vector<StorageData> storageTable;
02516 GetMonitorTable( clientTable, storageTable );
02517
02518 time_t currentTime;
02519 time( ¤tTime );
02520
02521
02522
02523 unsigned int MessageSize;
02524
02525
02526 char BufferAux[ 22 ];
02527
02528 sprintf( BufferAux, "%hu", (unsigned short) clientTable.size() );
02529 MessageSize = strlen( BufferAux ) + 1;
02530 sprintf( BufferAux, "%hu", (unsigned short) storageTable.size() );
02531 MessageSize += strlen( BufferAux ) + 1;
02532
02533
02534 for( vector<ClientData>::iterator c_it = clientTable.begin();
02535 c_it != clientTable.end(); c_it++ )
02536 {
02537
02538 MessageSize += strlen( (*c_it).m_ip.c_str() ) + 1;
02539
02540 sprintf( BufferAux, "%hu", (unsigned short) (*c_it).m_port );
02541 MessageSize += strlen( BufferAux ) + 1;
02542
02543 MessageSize += strlen( (*c_it).m_video.c_str() ) + 1;
02544
02545 double connection_time = difftime( currentTime, (*c_it).m_time );
02546 sprintf( BufferAux, "%hu", (unsigned short) connection_time );
02547 MessageSize += strlen( BufferAux ) + 1;
02548
02549 sprintf( BufferAux, "%hu", (unsigned short) (*c_it).m_queue );
02550 MessageSize += strlen( BufferAux ) + 1;
02551 }
02552
02553 for( vector<StorageData>::iterator s_it = storageTable.begin();
02554 s_it != storageTable.end(); s_it++ )
02555 {
02556
02557 MessageSize += strlen( (*s_it).m_ip.c_str() ) + 1;
02558
02559
02560 MessageSize += strlen( (*s_it).m_hostname.c_str() ) + 1;
02561
02562 MessageSize += strlen( (*s_it).m_diskname.c_str() ) + 1;
02563
02564 sprintf( BufferAux, "%hu", (unsigned short) (*s_it).m_queue );
02565 MessageSize += strlen( BufferAux ) + 1;
02566 }
02567
02568 #ifdef RIO_DEBUG2
02569 RioErr << "RioSession::ExecuteSessionManager tamanho computado para"
02570 << " a mensagem foi de " << " bytes." << endl;
02571 #endif
02572 if( MessageSize > *ResultSize )
02573 {
02574
02575 #ifdef RIO_DEBUG2
02576 RioErr << "RioSession::ExecuteSessionManager realocando a"
02577 << " memoria de " << *ResultSize << " bytes para "
02578 << MessageSize << " bytes." << endl;
02579 #endif
02580 char *NewResult = ( char * ) realloc( *Result, MessageSize );
02581 if( NewResult == NULL )
02582 {
02583 return ERROR_CONNECTIONMANAGER +
02584 ERROR_RESULT_MESSAGE_OVERFLOW;
02585 }
02586 *Result = NewResult;
02587 }
02588
02589 offset = 0;
02590
02591
02592 SetUShort( *Result, (unsigned short) clientTable.size(), &offset );
02593 SetUShort( *Result, (unsigned short) storageTable.size(), &offset );
02594 for( vector<ClientData>::iterator c_it = clientTable.begin();
02595 c_it != clientTable.end(); c_it++ )
02596 {
02597 double connection_time = difftime( currentTime, (*c_it).m_time );
02598 SetString( *Result, (*c_it).m_ip.c_str(), &offset );
02599 SetUShort( *Result, (unsigned short)(*c_it).m_port, &offset );
02600 SetString( *Result, (*c_it).m_video.c_str(), &offset );
02601 SetUShort( *Result, (unsigned short) connection_time, &offset );
02602 SetUShort( *Result, (unsigned short)(*c_it).m_queue, &offset );
02603 }
02604 for( vector<StorageData>::iterator s_it = storageTable.begin();
02605 s_it != storageTable.end(); s_it++ )
02606 {
02607 SetString( *Result, (*s_it).m_ip.c_str(), &offset );
02608 SetString( *Result, (*s_it).m_hostname.c_str(), &offset );
02609 SetString( *Result, (*s_it).m_diskname.c_str(), &offset );
02610 SetUShort( *Result, (unsigned short)(*s_it).m_queue, &offset );
02611 }
02612
02613
02614 *ResultSize = offset;
02615
02616 #ifdef RIO_DEBUG2
02617 RioErr << "CSessionManager::ExecuteSessionMananger o tamanho da "
02618 << "mensagem e de " << offset << " bytes." << endl;
02619
02620 struct in_addr clientip;
02621 clientip.s_addr = s_remoteAddress.sin_addr.s_addr;
02622 if( s_mgr->m_log.is_open() )
02623 s_mgr->m_log << " ip: " << inet_ntoa(clientip )
02624 << " port: " << htons( s_remoteAddress.sin_port )
02625 << " set interface " << endl;
02626 #endif
02627
02628 return S_OK;
02629 }
02630
02631
02632 case RioMethodSessionManagerCheckStreamControl:
02633 {
02634 offset = 0;
02635
02636 Size = MAX_LONG_STRING_SIZE;
02637 if( Size > *ResultSize )
02638 {
02639 Close();
02640 return ERROR_CONNECTIONMANAGER + ERROR_RESULT_MESSAGE_OVERFLOW;
02641 }
02642
02643
02644 SetLong( *Result, S_OK, &offset );
02645
02646
02647 *ResultSize = offset;
02648 return S_OK;
02649 break;
02650 }
02651
02652
02653
02654 default:
02655 {
02656 #ifdef RIO_DEBUG2
02657 RioErr << "[CRioSession] Trying to execute invalid method"
02658 << endl;
02659 #endif
02660 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD;
02661 };
02662 }
02663 }
02664
02665
02666 int RioSession::ExecuteStreamManager( unsigned int Method,
02667 char* Parameter,
02668 unsigned int ParameterSize,
02669 char** Result,
02670 unsigned int* ResultSize )
02671 {
02672 int offset = 0;
02673 unsigned int Size;
02674
02675 switch( Method )
02676 {
02677
02678 case RioMethodStreamManagerClose:
02679 {
02680 RioStreamId Stream;
02681 offset = 0;
02682
02683 #ifdef RIO_DEBUG2
02684 struct in_addr clientip;
02685 clientip.s_addr = s_remoteAddress.sin_addr.s_addr;
02686 if( s_mgr->m_log.is_open() )
02687 s_mgr->m_log << " ip: " << inet_ntoa(clientip )
02688 << " port: " << htons( s_remoteAddress.sin_port )
02689 << " closing stream " << endl;
02690 #endif
02691
02692
02693
02694
02695
02696 if( !GetLong( Parameter, ParameterSize, &(Stream.Version),
02697 &offset ) )
02698 {
02699 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
02700 }
02701 if( !GetLong( Parameter, ParameterSize, &(Stream.Index), &offset ) )
02702 {
02703 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
02704 }
02705
02706
02707 HRESULT hresult = CloseStream( Stream.Index );
02708
02709
02710 Size = MAX_LONG_STRING_SIZE;
02711 if( Size > *ResultSize )
02712 {
02713 return ERROR_CONNECTIONMANAGER + ERROR_RESULT_MESSAGE_OVERFLOW;
02714 }
02715 offset = 0;
02716
02717
02718 SetLong( *Result, hresult, &offset );
02719
02720
02721 *ResultSize = offset;
02722
02723 return S_OK;
02724
02725 }
02726
02727 case RioMethodStreamManagerOpenObject:
02728 {
02729 RioStreamId Stream;
02730 char* ObjectName;
02731 RioAccess Access;
02732 ObjectHandle Handle;
02733 int hresult;
02734 bool AccessGranted;
02735 bool CanRead, CanWrite;
02736
02737 #ifdef RIO_DEBUG2
02738 struct in_addr clientip;
02739 clientip.s_addr = s_remoteAddress.sin_addr.s_addr;
02740 if( s_mgr->m_log.is_open() )
02741 s_mgr->m_log << " ip: " << inet_ntoa(clientip )
02742 << " port: " << htons( s_remoteAddress.sin_port )
02743 << " opening object " << endl;
02744 #endif
02745
02746
02747 offset = 0;
02748
02749
02750
02751
02752 if( !GetLong( Parameter, ParameterSize, &(Stream.Version),
02753 &offset ) )
02754 {
02755 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
02756 }
02757 if( !GetLong( Parameter, ParameterSize, &(Stream.Index), &offset ) )
02758 {
02759 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
02760 }
02761
02762
02763 if( !GetString( Parameter, ParameterSize, &ObjectName, &offset ) )
02764 {
02765 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
02766 }
02767
02768
02769 if( !GetULong( Parameter, ParameterSize, &Access, &offset ) )
02770 {
02771 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
02772 }
02773
02774
02775
02776 s_mgr->m_Router->GetStorageInfo( s_ServerNat, &CanRead, &CanWrite );
02777
02778
02779
02780
02781
02782
02783
02784
02785
02786
02787
02788
02789 AccessGranted = true;
02790 if( ( Access & RIO_WRITE_MASK ) != 0 )
02791 {
02792 AccessGranted = CanWrite;
02793 }
02794 if( AccessGranted )
02795 {
02796
02797 hresult = StreamOpenObject( Stream.Index, ObjectName, Access,
02798 &Handle.Index );
02799
02800
02801
02802 if( FAILED( hresult ) )
02803 {
02804 int rc;
02805 rc = RemoveIdEntryFromTable( Handle.Index, idt_streamobj );
02806 if( rc )
02807 RioErr << "Error: Object does not exist. Could not "
02808 "remove. Did not find id on ta ble." << endl;
02809 }
02810 }
02811 else
02812 hresult = ERROR_SESSIONMANAGER +
02813 ERROR_SERVICE_TEMPORARY_UNAVAILABLE;
02814
02815
02816
02817
02818 Size = 3 * MAX_LONG_STRING_SIZE;
02819 if( Size > *ResultSize )
02820 {
02821 return ERROR_CONNECTIONMANAGER + ERROR_RESULT_MESSAGE_OVERFLOW;
02822 }
02823 offset = 0;
02824
02825
02826 SetLong( *Result, hresult, &offset );
02827
02828 SetLong( *Result, Handle.Version, &offset );
02829 SetLong( *Result, Handle.Index, &offset );
02830
02831
02832 *ResultSize = offset;
02833
02834 return S_OK;
02835 }
02836
02837
02838 case RioMethodStreamManagerOpenObjectSubmitToCAC:
02839 {
02840 RioStreamId Stream;
02841 char* ObjectName;
02842 RioAccess Access;
02843 ObjectHandle Handle;
02844 struct timeval average_RTT;
02845 int BufferSize;
02846 RioObjectSize ObjectSize;
02847 int hresult;
02848 bool AccessGranted;
02849 bool CanRead, CanWrite;
02850 unsigned int highpart = 0;
02851 unsigned int lowpart = 0;
02852 int m_FlagRequests;
02853 int AuxInt;
02854
02855
02856
02857
02858 #ifdef RIO_DEBUG2
02859 struct in_addr clientip;
02860 clientip.s_addr = s_remoteAddress.sin_addr.s_addr;
02861 if( s_mgr->m_log.is_open() )
02862 s_mgr->m_log << " ip: " << inet_ntoa(clientip )
02863 << " port: " << htons( s_remoteAddress.sin_port )
02864 << " opening object (submit to cac) ";
02865 #endif
02866
02867 offset = 0;
02868
02869
02870
02871
02872 if( !GetLong( Parameter, ParameterSize, &(Stream.Version),
02873 &offset ) )
02874 {
02875 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
02876 }
02877 if( !GetLong( Parameter, ParameterSize, &(Stream.Index), &offset ) )
02878 {
02879 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
02880 }
02881
02882
02883 if( !GetString( Parameter, ParameterSize, &ObjectName, &offset ) )
02884 {
02885 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
02886 }
02887
02888
02889 if( !GetULong( Parameter, ParameterSize, &Access, &offset ) )
02890 {
02891 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
02892 }
02893
02894
02895
02896 if( !GetLong( Parameter, ParameterSize, &AuxInt, &offset ) )
02897 {
02898 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
02899 }
02900 average_RTT.tv_sec = AuxInt;
02901 if( !GetLong( Parameter, ParameterSize, &AuxInt, &offset ) )
02902 {
02903 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
02904 }
02905 average_RTT.tv_usec = AuxInt;
02906
02907 if( !GetLong( Parameter, ParameterSize, &(BufferSize), &offset ) )
02908 {
02909 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
02910 }
02911
02912 #ifdef RIO_DEBUG2
02913 if( s_mgr->m_log.is_open() )
02914 s_mgr->m_log << " get from client RTT: "
02915 << average_RTT.tv_sec << " : "
02916 << average_RTT.tv_usec
02917 << " BufferSize : " << BufferSize << endl;
02918 #endif
02919
02920
02921 s_mgr->m_Router->GetStorageInfo( s_ServerNat, &CanRead, &CanWrite );
02922
02923
02924
02925
02926
02927
02928
02929
02930
02931
02932
02933
02934 AccessGranted = true;
02935 if( ( Access & RIO_WRITE_MASK ) != 0 )
02936 {
02937 AccessGranted = CanWrite;
02938
02939 }
02940 if( AccessGranted )
02941 {
02942 hresult = StreamOpenObject( Stream.Index, ObjectName,
02943 average_RTT, BufferSize,
02944 Access, &Handle.Index );
02945
02946 if( FAILED( hresult ) )
02947 {
02948 int rc;
02949 rc = RemoveIdEntryFromTable( Handle.Index, idt_streamobj );
02950 if( rc )
02951 RioErr << "Error: Object does not exist. Could not "
02952 " remove. Did not find id on table." << endl;
02953 }
02954 else
02955 {
02956
02957 hresult = GetSize( Handle.Index, &ObjectSize );
02958
02959
02960 highpart = ( unsigned int ) ( ( ObjectSize >> 32 ) &
02961 0xffffffff );
02962 lowpart = ( unsigned int ) ( ObjectSize & 0xffffffff);
02963
02964 if( FAILED( hresult ) )
02965 {
02966 RioErr << "Error: Could not get size of Object "
02967 << ObjectName << " Index " << Handle.Index
02968 << endl;
02969 }
02970 }
02971 }
02972 else
02973 hresult = ERROR_SESSIONMANAGER +
02974 ERROR_SERVICE_TEMPORARY_UNAVAILABLE;
02975
02976
02977
02978
02979 Size = 4 * MAX_LONG_STRING_SIZE + MAX_LONG_STRING_SIZE +
02980 2 * MAX_ULONG_STRING_SIZE;
02981 if( Size > *ResultSize )
02982 {
02983 RioErr << "Error: Message too int." << endl;
02984 return ERROR_CONNECTIONMANAGER + ERROR_RESULT_MESSAGE_OVERFLOW;
02985 }
02986 offset = 0;
02987
02988
02989 SetLong( *Result, hresult, &offset );
02990
02991
02992 SetLong( *Result, Handle.Version, &offset );
02993 SetLong( *Result, Handle.Index, &offset );
02994
02995
02996 SetULong( *Result, highpart, &offset );
02997 SetULong( *Result, lowpart, &offset );
02998
02999 m_FlagRequests = 2;
03000
03001 SetLong( *Result, m_FlagRequests, &offset );
03002
03003
03004
03005
03006 *ResultSize = offset;
03007
03008 return S_OK;
03009 }
03010
03011
03012 case RioMethodStreamManagerMaxRequests:
03013 {
03014 RioStreamId Stream;
03015
03016 #ifdef RIO_DEBUG2
03017 struct in_addr clientip;
03018 clientip.s_addr = s_remoteAddress.sin_addr.s_addr;
03019 if( s_mgr->m_log.is_open() )
03020 s_mgr->m_log << " ip: " << inet_ntoa(clientip )
03021 << " port: " << htons( s_remoteAddress.sin_port )
03022 << " get max requests " << endl;
03023 #endif
03024
03025
03026 offset = 0;
03027
03028
03029
03030
03031 if( !GetLong( Parameter, ParameterSize, &(Stream.Version),
03032 &offset ) )
03033 {
03034 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
03035 }
03036 if( !GetLong( Parameter, ParameterSize, &(Stream.Index), &offset ) )
03037 {
03038 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
03039 }
03040 int hresult = StreamMaxRequests( Stream.Index );
03041
03042
03043 Size = MAX_LONG_STRING_SIZE;
03044 if( Size > *ResultSize )
03045 {
03046 return ERROR_CONNECTIONMANAGER + ERROR_RESULT_MESSAGE_OVERFLOW;
03047 }
03048 offset = 0;
03049
03050
03051 SetLong( *Result, hresult, &offset );
03052
03053
03054 *ResultSize = offset;
03055 return S_OK;
03056 }
03057
03058 case RioMethodStreamManagerClientCanStart:
03059 {
03060 RioStreamId Stream;
03061
03062 #ifdef RIO_DEBUG2
03063 struct in_addr clientip;
03064 clientip.s_addr = s_remoteAddress.sin_addr.s_addr;
03065 if( s_mgr->m_log.is_open() )
03066 s_mgr->m_log << " ip: " << inet_ntoa(clientip )
03067 << " port: " << htons( s_remoteAddress.sin_port )
03068 << " can start? " << endl;
03069 #endif
03070
03071 offset = 0;
03072
03073
03074
03075
03076 if( !GetLong( Parameter, ParameterSize, &(Stream.Version),
03077 &offset ) )
03078 {
03079 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
03080 }
03081 if( !GetLong( Parameter, ParameterSize, &(Stream.Index), &offset ) )
03082 {
03083 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
03084 }
03085
03086 int hresult = ClientCanStart( Stream.Index );
03087
03088
03089 Size = MAX_LONG_STRING_SIZE;
03090 if( Size > *ResultSize )
03091 {
03092 return ERROR_CONNECTIONMANAGER + ERROR_RESULT_MESSAGE_OVERFLOW;
03093 }
03094 offset = 0;
03095
03096
03097 SetLong( *Result, hresult, &offset );
03098
03099
03100 *ResultSize = offset;
03101
03102 return S_OK;
03103 }
03104
03105
03106
03107 default:
03108 {
03109 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD;
03110 }
03111 }
03112 }
03113
03114 int RioSession::StreamOpenObject( int StreamId, char *ObjectName,
03115 RioAccess Access, int *StreamObjId )
03116 {
03117 int rc;
03118 char Path[MaxPathSize + 1];
03119
03120
03121 rc = ObjectToPath( ObjectName, Path, sizeof( Path ));
03122 if( rc )
03123 {
03124 RioErr << "Error: Invalid Path " << Path << endl;
03125 return rc;
03126 }
03127
03128
03129 RioStream *sp = ( RioStream * )checkid( StreamId, idt_stream );
03130 if( sp == 0 )
03131 {
03132 RioErr << "Error: Invalid Stream " << endl;
03133 return ERROR_SESSIONMANAGER + ERROR_INVALID_STREAM;
03134 }
03135
03136 RioStreamObj **idp = (RioStreamObj **) newid( StreamObjId, idt_streamobj );
03137 if( idp == 0 )
03138 {
03139 RioErr << "Error: Max Opened Objects " << endl;
03140 return ERROR_SESSIONMANAGER + ERROR_MAX_OPENED_OBJECTS;
03141 }
03142
03143
03144 if( sp->getDirection() == RioStreamDirectionRead )
03145 {
03146 rc = s_user->CheckAccess( Path );
03147 }
03148 else
03149 {
03150 rc = s_user->CheckAccess( Path, 1 );
03151 }
03152
03153 if( rc )
03154 return rc;
03155
03156 rc = sp->OpenObject( Path, Access, idp );
03157 if( rc )
03158 return rc;
03159
03160 struct in_addr clientip;
03161 clientip.s_addr = s_remoteAddress.sin_addr.s_addr;
03162
03163 ConnectEvent *it_event = new ConnectEvent( inet_ntoa(clientip),
03164 htons( s_remoteAddress.sin_port ), Path );
03165 s_mgr->PostITEvent( (MonitorEvent *)it_event );
03166
03167
03168
03169
03170 SaveLogLine( "Open", ObjectName );
03171
03172 return S_OK;
03173 }
03174
03175
03176 int RioSession::StreamOpenObject( int StreamId, char *ObjectName,
03177 struct timeval average_RTT,
03178 int BufferSize, RioAccess Access,
03179 int *StreamObjId )
03180 {
03181 int rc;
03182 char Path[MaxPathSize + 1];
03183
03184
03185 rc = ObjectToPath( ObjectName, Path, sizeof( Path ));
03186 if( rc )
03187 {
03188 RioErr << "Error: Invalid Path " << Path << endl;
03189 return rc;
03190 }
03191
03192
03193 RioStream *sp = ( RioStream * )checkid( StreamId, idt_stream );
03194 if( sp == 0 )
03195 {
03196 RioErr << "Error: Invalid Stream " << endl;
03197 return ERROR_SESSIONMANAGER + ERROR_INVALID_STREAM;
03198 }
03199
03200 RioStreamObj **idp = (RioStreamObj **) newid( StreamObjId, idt_streamobj );
03201 if( idp == 0 )
03202 {
03203 RioErr << "Error: Max Opened Objects " << endl;
03204 return ERROR_SESSIONMANAGER + ERROR_MAX_OPENED_OBJECTS;
03205 }
03206
03207 rc = sp->OpenObject( Path, Access, average_RTT, BufferSize, idp );
03208
03209 if( rc )
03210 return rc;
03211
03212 struct in_addr clientip;
03213 clientip.s_addr = s_remoteAddress.sin_addr.s_addr;
03214
03215 ConnectEvent *it_event = new ConnectEvent( inet_ntoa(clientip),
03216 htons( s_remoteAddress.sin_port ), Path );
03217 s_mgr->PostITEvent( (MonitorEvent *)it_event );
03218
03219
03220
03221
03222 SaveLogLine( "OpenCAC", ObjectName );
03223
03224 return S_OK;
03225 }
03226
03227 int RioSession::CloseStream( int StreamId )
03228 {
03229 RioStream *sp = ( RioStream * )checkid( StreamId, idt_stream );
03230 if( sp == 0 )
03231 {
03232 return ERROR_SESSIONMANAGER + ERROR_INVALID_STREAM;
03233 }
03234
03235 RioStream *stream;
03236
03237
03238
03239 for( unsigned int i = 0; i < s_idmax; i++ )
03240 {
03241 if( s_idtable[i].id_type == idt_streamobj )
03242 {
03243 stream = ((RioStreamObj *)(s_idtable[i].id_object))->Stream();
03244 if( stream == sp )
03245 CloseObject(i);
03246 }
03247 }
03248 sp->Close();
03249 s_idtable[StreamId].id_type = idt_invalid;
03250 s_idtable[StreamId].id_object = 0;
03251
03252 return S_OK;
03253 }
03254
03255
03256 int RioSession::StreamMaxRequests( int StreamId )
03257 {
03258 RioStream *sp = ( RioStream * )checkid( StreamId, idt_stream );
03259 if( sp == 0 )
03260 {
03261 return ERROR_SESSIONMANAGER + ERROR_INVALID_STREAM;
03262 }
03263
03264 return ( sp->MaxRequests() );
03265 }
03266
03267
03268
03269 int RioSession::ClientCanStart( int StreamId )
03270 {
03271 RioStream *sp = ( RioStream * )checkid( StreamId, idt_stream );
03272 if( sp == 0 )
03273 {
03274 return ERROR_SESSIONMANAGER + ERROR_INVALID_STREAM;
03275 }
03276
03277 return ( sp->ClientCanStart() );
03278 }
03279
03280
03281 int RioSession::ExecuteObjectManager( unsigned int Method,
03282 char* Parameter,
03283 unsigned int ParameterSize,
03284 char** Result,
03285 unsigned int* ResultSize )
03286 {
03287 int offset = 0;
03288 unsigned int Size;
03289
03290 switch( Method )
03291 {
03292 case RioMethodObjectManagerClose:
03293 {
03294 ObjectHandle Handle;
03295 offset = 0;
03296
03297 #ifdef RIO_DEBUG2
03298 struct in_addr clientip;
03299 clientip.s_addr = s_remoteAddress.sin_addr.s_addr;
03300 if( s_mgr->m_log.is_open() )
03301 s_mgr->m_log << " ip: " << inet_ntoa(clientip )
03302 << " port: " << htons( s_remoteAddress.sin_port )
03303 << " closing object " << endl;
03304 #endif
03305
03306
03307
03308
03309
03310 if( !GetLong( Parameter, ParameterSize, &(Handle.Version),
03311 &offset ) )
03312 {
03313 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
03314 }
03315 if( !GetLong( Parameter, ParameterSize, &(Handle.Index), &offset ) )
03316 {
03317 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
03318 }
03319
03320
03321 HRESULT hresult = CloseObject( Handle.Index );
03322
03323
03324 Size = MAX_LONG_STRING_SIZE;
03325 if( Size > *ResultSize )
03326 {
03327 return ERROR_CONNECTIONMANAGER + ERROR_RESULT_MESSAGE_OVERFLOW;
03328 }
03329 offset = 0;
03330
03331
03332 SetLong( *Result, hresult, &offset );
03333
03334
03335 *ResultSize = offset;
03336
03337 return S_OK;
03338 }
03339
03340 case RioMethodObjectManagerGetSize:
03341 {
03342 ObjectHandle Handle;
03343 RioObjectSize ObjectSize;
03344 offset = 0;
03345
03346 #ifdef RIO_DEBUG2
03347 struct in_addr clientip;
03348 clientip.s_addr = s_remoteAddress.sin_addr.s_addr;
03349 if( s_mgr->m_log.is_open() )
03350 s_mgr->m_log << " ip: " << inet_ntoa(clientip )
03351 << " port: " << htons( s_remoteAddress.sin_port )
03352 << " getting object size " << endl;
03353 #endif
03354
03355
03356
03357
03358
03359 if( !GetLong( Parameter, ParameterSize, &(Handle.Version),
03360 &offset ) )
03361 {
03362 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
03363 }
03364 if( !GetLong( Parameter, ParameterSize, &(Handle.Index), &offset ) )
03365 {
03366 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
03367 }
03368
03369
03370 HRESULT hresult = GetSize( Handle.Index, &ObjectSize );
03371
03372
03373 Size = MAX_LONG_STRING_SIZE + 2 * MAX_ULONG_STRING_SIZE;
03374 if( Size > *ResultSize )
03375 {
03376 return ERROR_CONNECTIONMANAGER + ERROR_RESULT_MESSAGE_OVERFLOW;
03377 }
03378 offset = 0;
03379
03380
03381 SetLong( *Result, hresult, &offset );
03382
03383 unsigned int highpart = ( unsigned int )(( ObjectSize >> 32 )
03384 & 0xffffffff);
03385 unsigned int lowpart = ( unsigned int )( ObjectSize
03386 & 0xffffffff);
03387 SetULong( *Result, highpart, &offset );
03388 SetULong( *Result, lowpart, &offset );
03389
03390
03391 *ResultSize = offset;
03392
03393 return S_OK;
03394 }
03395
03396 case RioMethodObjectManagerSetSize:
03397 {
03398 ObjectHandle Handle;
03399 RioObjectSize ObjectSize;
03400 unsigned long long int ExcludeStorages;
03401
03402 char* md5sum;
03403
03404 offset = 0;
03405
03406 #ifdef RIO_DEBUG2
03407 struct in_addr clientip;
03408 clientip.s_addr = s_remoteAddress.sin_addr.s_addr;
03409 if( s_mgr->m_log.is_open() )
03410 s_mgr->m_log << " ip: " << inet_ntoa(clientip )
03411 << " port: " << htons( s_remoteAddress.sin_port )
03412 << " setting object size " << endl;
03413 #endif
03414
03415
03416
03417
03418
03419 if( !GetLong( Parameter, ParameterSize, &(Handle.Version),
03420 &offset ) )
03421 {
03422 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
03423 }
03424 if( !GetLong( Parameter, ParameterSize, &(Handle.Index), &offset ) )
03425 {
03426 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
03427 }
03428
03429
03430 unsigned int highpart;
03431 unsigned int lowpart;
03432 if( !GetULong( Parameter, ParameterSize, &highpart, &offset ) )
03433 {
03434 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
03435 }
03436 if( !GetULong( Parameter, ParameterSize, &lowpart, &offset ) )
03437 {
03438 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
03439 }
03440 ObjectSize = ( ((RioObjectSize) highpart) << 32 ) | lowpart ;
03441
03442
03443 if( Handle.Version != 0 )
03444 {
03445 if( !GetString(Parameter, ParameterSize, &md5sum, &offset ) )
03446 {
03447 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
03448 }
03449 }
03450 else
03451 {
03452
03453 md5sum = strdup("0123456789abcdef0123456789abcdef");
03454 }
03455
03456
03457
03458 if( strcmp( md5sum, "0" ) == 0 )
03459 md5sum = NULL;
03460
03461
03462
03463 ExcludeStorages = s_mgr->m_Router->GetInvalidStorages(
03464 s_ServerNat );
03465
03466
03467 HRESULT hresult = SetSize( Handle.Index, ObjectSize, md5sum,
03468 ExcludeStorages );
03469 if( Handle.Version == 0 )
03470
03471
03472
03473 free( md5sum );
03474
03475
03476 Size = MAX_LONG_STRING_SIZE;
03477 if( Size > *ResultSize )
03478 {
03479 return ERROR_CONNECTIONMANAGER + ERROR_RESULT_MESSAGE_OVERFLOW;
03480 }
03481 offset = 0;
03482
03483
03484 SetLong( *Result, hresult, &offset );
03485
03486
03487 *ResultSize = offset;
03488 return S_OK;
03489
03490 }
03491
03492 case RioMethodObjectManagerGetType:
03493 {
03494 ObjectHandle Handle;
03495 short Type;
03496
03497 #ifdef RIO_DEBUG2
03498 struct in_addr clientip;
03499 clientip.s_addr = s_remoteAddress.sin_addr.s_addr;
03500 if( s_mgr->m_log.is_open() )
03501 s_mgr->m_log << " ip: " << inet_ntoa(clientip )
03502 << " port: " << htons( s_remoteAddress.sin_port )
03503 << " get object type " << endl;
03504 #endif
03505
03506
03507 offset = 0;
03508
03509
03510
03511
03512 if( !GetLong( Parameter, ParameterSize, &(Handle.Version),
03513 &offset ) )
03514 {
03515 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
03516 }
03517 if( !GetLong( Parameter, ParameterSize, &(Handle.Index), &offset ) )
03518 {
03519 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
03520 }
03521
03522
03523 HRESULT hresult = GetType( Handle.Index, &Type );
03524
03525
03526 Size = MAX_LONG_STRING_SIZE + MAX_SHORT_STRING_SIZE;
03527 if( Size > *ResultSize )
03528 {
03529 return ERROR_CONNECTIONMANAGER + ERROR_RESULT_MESSAGE_OVERFLOW;
03530 }
03531 offset = 0;
03532
03533
03534 SetLong( *Result, hresult, &offset );
03535
03536 SetShort( *Result, (short) Type, &offset );
03537
03538
03539 *ResultSize = offset;
03540 return S_OK;
03541 }
03542
03543
03544 case RioMethodObjectManagerGetnBlocks:
03545 {
03546 ObjectHandle Handle;
03547 RioBlock nBlocks;
03548
03549 #ifdef RIO_DEBUG2
03550 struct in_addr clientip;
03551 clientip.s_addr = s_remoteAddress.sin_addr.s_addr;
03552 if( s_mgr->m_log.is_open() )
03553 s_mgr->m_log << " ip: " << inet_ntoa(clientip )
03554 << " port: " << htons( s_remoteAddress.sin_port )
03555 << " get n blocks " << endl;
03556 #endif
03557
03558
03559 offset = 0;
03560
03561
03562
03563
03564 if( !GetLong( Parameter, ParameterSize, &(Handle.Version),
03565 &offset ) )
03566 {
03567 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
03568 }
03569 if( !GetLong( Parameter, ParameterSize, &(Handle.Index), &offset ) )
03570 {
03571 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
03572 }
03573
03574
03575 HRESULT hresult = GetnBlocks( Handle.Index, &nBlocks );
03576
03577
03578 Size = MAX_LONG_STRING_SIZE + MAX_ULONG_STRING_SIZE;
03579 if( Size > *ResultSize )
03580 {
03581 return ERROR_CONNECTIONMANAGER + ERROR_RESULT_MESSAGE_OVERFLOW;
03582 }
03583 offset = 0;
03584
03585
03586 SetLong( *Result, hresult, &offset );
03587
03588 SetULong( *Result, nBlocks, &offset );
03589
03590
03591 *ResultSize = offset;
03592
03593 return S_OK;
03594 }
03595
03596
03597
03598
03599
03600
03601
03602
03603
03604
03605
03606
03607
03608
03609
03610
03611
03612
03613
03614
03615
03616
03617
03618
03619
03620
03621
03622
03623
03624
03625
03626
03627
03628
03629
03630
03631
03632
03633
03634
03635
03636
03637
03638
03639
03640
03641
03642
03643
03644
03645
03646
03647
03648
03649
03650
03651
03652
03653
03654
03655
03656
03657
03658
03659
03660
03661
03662
03663
03664
03665
03666
03667 case RioMethodObjectManagerNextObject:
03668 {
03669 ObjectHandle Handle;
03670 int BufferSize;
03671 int IsDirectory;
03672
03673 #ifdef RIO_DEBUG2
03674 struct in_addr clientip;
03675 clientip.s_addr = s_remoteAddress.sin_addr.s_addr;
03676 if( s_mgr->m_log.is_open() )
03677 s_mgr->m_log << " ip: " << inet_ntoa(clientip )
03678 << " port: " << htons( s_remoteAddress.sin_port )
03679 << " get next object " << endl;
03680 #endif
03681
03682
03683 offset = 0;
03684
03685
03686
03687
03688 if( !GetLong( Parameter, ParameterSize, &(Handle.Version),
03689 &offset ) )
03690 {
03691 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
03692 }
03693 if( !GetLong( Parameter, ParameterSize, &(Handle.Index), &offset ) )
03694 {
03695 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
03696 }
03697
03698
03699 if( !GetLong( Parameter, ParameterSize, &BufferSize, &offset ) )
03700 {
03701 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
03702 }
03703
03704 char *ObjectName = new char [BufferSize];
03705
03706
03707
03708 HRESULT hresult = NextObject( Handle.Index, &IsDirectory,
03709 BufferSize, ObjectName );
03710
03711
03712 Size = MAX_LONG_STRING_SIZE + BufferSize + 1;
03713 if( Size > *ResultSize )
03714 {
03715 delete[] ObjectName;
03716 return ERROR_CONNECTIONMANAGER + ERROR_RESULT_MESSAGE_OVERFLOW;
03717 }
03718 offset = 0;
03719
03720
03721 SetLong( *Result, hresult, &offset );
03722
03723
03724 SetLong( *Result, IsDirectory, &offset );
03725
03726
03727 SetString( *Result, ObjectName, &offset );
03728
03729
03730 *ResultSize = offset;
03731
03732 delete[] ObjectName;
03733
03734 return S_OK;
03735
03736 }
03737
03738
03739
03740
03741
03742 case RioMethodObjectManagerGetVideoRate:
03743 {
03744
03745
03746 unsigned int VideoRate;
03747 ObjectHandle Handle;
03748 offset = 0;
03749
03750 #ifdef RIO_DEBUG2
03751 struct in_addr clientip;
03752 clientip.s_addr = s_remoteAddress.sin_addr.s_addr;
03753 if( s_mgr->m_log.is_open() )
03754 s_mgr->m_log << " ip: " << inet_ntoa(clientip )
03755 << " port: " << htons( s_remoteAddress.sin_port )
03756 << " getting object video rate " << endl;
03757 #endif
03758
03759
03760
03761
03762
03763 if( !GetLong( Parameter, ParameterSize, &(Handle.Version),
03764 &offset ) )
03765 {
03766 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
03767 }
03768 if( !GetLong( Parameter, ParameterSize, &(Handle.Index), &offset ) )
03769 {
03770 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
03771 }
03772
03773
03774 HRESULT hresult = GetVideoRate( Handle.Index, &VideoRate );
03775
03776
03777 Size = MAX_LONG_STRING_SIZE + MAX_ULONG_STRING_SIZE;
03778 if( Size > *ResultSize )
03779 {
03780 return ERROR_CONNECTIONMANAGER + ERROR_RESULT_MESSAGE_OVERFLOW;
03781 }
03782 offset = 0;
03783
03784
03785 SetLong( *Result, hresult, &offset );
03786
03787 SetULong( *Result, VideoRate, &offset );
03788
03789
03790 *ResultSize = offset;
03791
03792 return S_OK;
03793 }
03794
03795
03796 case RioMethodObjectManagerSetVideoRate:
03797 {
03798
03799
03800 unsigned int VideoRate;
03801 ObjectHandle Handle;
03802 offset = 0;
03803
03804 #ifdef RIO_DEBUG2
03805 struct in_addr clientip;
03806 clientip.s_addr = s_remoteAddress.sin_addr.s_addr;
03807 if( s_mgr->m_log.is_open() )
03808 s_mgr->m_log << " ip: " << inet_ntoa(clientip )
03809 << " port: " << htons( s_remoteAddress.sin_port )
03810 << " setting object video rate " << endl;
03811 #endif
03812
03813
03814
03815
03816
03817 if( !GetLong( Parameter, ParameterSize, &(Handle.Version),
03818 &offset ) )
03819 {
03820 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
03821 }
03822 if( !GetLong( Parameter, ParameterSize, &(Handle.Index), &offset ) )
03823 {
03824 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
03825 }
03826
03827
03828 if( !GetULong( Parameter, ParameterSize, &VideoRate, &offset ) )
03829 {
03830 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
03831 }
03832
03833 HRESULT hresult = SetVideoRate( Handle.Index, VideoRate );
03834
03835
03836 Size = MAX_LONG_STRING_SIZE;
03837 if( Size > *ResultSize )
03838 {
03839 return ERROR_CONNECTIONMANAGER + ERROR_RESULT_MESSAGE_OVERFLOW;
03840 }
03841 offset = 0;
03842
03843
03844 SetLong( *Result, hresult, &offset );
03845
03846
03847 *ResultSize = offset;
03848 return S_OK;
03849 }
03850
03851
03852
03853
03854
03855 case RioMethodObjectManagerReallocBlocks:
03856 {
03857
03858
03859 unsigned int Block;
03860 ObjectHandle Handle;
03861 unsigned long long int ExcludeStorages;
03862
03863 offset = 0;
03864
03865 #ifdef RIO_DEBUG2
03866 struct in_addr clientip;
03867 clientip.s_addr = s_remoteAddress.sin_addr.s_addr;
03868 if( s_mgr->m_log.is_open() )
03869 s_mgr->m_log << " ip: " << inet_ntoa(clientip )
03870 << " port: " << htons( s_remoteAddress.sin_port )
03871 << " changing fisical blocks " << endl;
03872 #endif
03873
03874
03875
03876
03877
03878 if( !GetLong( Parameter, ParameterSize, &(Handle.Version),
03879 &offset ) )
03880 {
03881 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
03882 }
03883 if( !GetLong( Parameter, ParameterSize, &(Handle.Index), &offset ) )
03884 {
03885 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
03886 }
03887
03888
03889 if( !GetULong( Parameter, ParameterSize, &Block, &offset ) )
03890 {
03891 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
03892 }
03893
03894
03895
03896 ExcludeStorages = s_mgr->m_Router->GetInvalidStorages(
03897 s_ServerNat );
03898
03899
03900 HRESULT hresult = ReallocBlocks( Handle.Index, Block,
03901 ExcludeStorages );
03902
03903
03904 Size = MAX_LONG_STRING_SIZE;
03905 if( Size > *ResultSize )
03906 {
03907 return ERROR_CONNECTIONMANAGER + ERROR_RESULT_MESSAGE_OVERFLOW;
03908 }
03909 offset = 0;
03910
03911
03912 SetLong( *Result, hresult, &offset );
03913
03914
03915 *ResultSize = offset;
03916 return S_OK;
03917 }
03918
03919
03920 default:
03921 {
03922 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD;
03923 };
03924 }
03925
03926 }
03927
03928
03929 int RioSession::ExecuteRouter( unsigned int Method,
03930 char* Parameter,
03931 unsigned int ParameterSize,
03932 char** Result,
03933 unsigned int* ResultSize )
03934 {
03935 int offset = 0;
03936 unsigned int Size;
03937 switch( Method )
03938 {
03939
03940 case RioMethodRouterDataRequest:
03941 {
03942 #if defined(RIO_DEBUG2) || defined(RIO_DEBUG_EMUL)
03943 struct in_addr clientip;
03944 clientip.s_addr = s_remoteAddress.sin_addr.s_addr;
03945 #endif
03946 #ifdef RIO_DEBUG2
03947 if( s_mgr->m_log.is_open() )
03948 s_mgr->m_log << "SessionManager - ExecuteRouter "
03949 << " ip: " << inet_ntoa(clientip)
03950 << " port: " << htons( s_remoteAddress.sin_port )
03951 << " data request " << endl;
03952 #endif
03953
03954
03955
03956
03957
03958
03959
03960
03961
03962
03963
03964
03965 offset = 0;
03966 u32 reqid, ipaddr, objid, block, repbits, PL;
03967 u16 port, operation;
03968 HRESULT hresult;
03969 bool CanRead, CanWrite;
03970
03971 const int ERR = ERROR_CONNECTIONMANAGER +
03972 ERROR_INVALID_METHOD_PARAM;
03973
03974 if( !GetULong( Parameter, ParameterSize, &reqid, &offset ) )
03975 {
03976 return ERR;
03977 }
03978 if( !GetULong( Parameter, ParameterSize, &ipaddr, &offset ) )
03979 {
03980 return ERR;
03981 }
03982 if( !GetULong( Parameter, ParameterSize, &objid, &offset ) )
03983 {
03984 return ERR;
03985 }
03986 if( !GetULong( Parameter, ParameterSize, &block, &offset ) )
03987 {
03988 return ERR;
03989 }
03990 if( !GetULong( Parameter, ParameterSize, &repbits, &offset ) )
03991 {
03992 return ERR;
03993 }
03994 if( !GetUShort(Parameter, ParameterSize, &port, &offset ) )
03995 {
03996 return ERR;
03997 }
03998 if( !GetUShort( Parameter, ParameterSize, &operation, &offset ) )
03999 {
04000 return ERR;
04001 }
04002 if( !GetULong( Parameter, ParameterSize, &PL, &offset ) )
04003 {
04004 return ERR;
04005 }
04006
04007
04008 s_mgr->m_Router->GetStorageInfo( s_ServerNat, &CanRead, &CanWrite );
04009
04010
04011
04012
04013
04014
04015
04016
04017
04018
04019
04020
04021 if( ( operation == READ ) || ( ( operation == WRITE ) &&
04022 ( CanWrite ) ) )
04023 {
04024 if( !PL )
04025 {
04026 hresult = DataRequest( htonl( reqid ),
04027 s_remoteAddress.sin_addr.s_addr,
04028 objid, block, repbits,
04029 htons( port ), operation );
04030 }
04031 else
04032 {
04033
04034 hresult = DataRequest( htonl( reqid ),
04035 htonl( ipaddr ),
04036 objid, block, repbits,
04037 htons( port ), operation );
04038 }
04039 }
04040 else
04041 hresult = ERROR_SESSIONMANAGER +
04042 ERROR_SERVICE_TEMPORARY_UNAVAILABLE;
04043
04044
04045 if( FAILED( hresult ) )
04046 {
04047 #ifdef RIO_DEBUG2
04048 if( s_mgr->m_log.is_open() )
04049 s_mgr->m_log << "SessionManager - ExecuteRouter "
04050 << " Failed to call datarequest: "
04051 << GetErrorDescription( hresult ) << endl;
04052 #endif
04053 RioErr << " Failed DataRequest"
04054 << GetErrorDescription( hresult ) << endl;
04055 }
04056
04057
04058 Size = MAX_LONG_STRING_SIZE + 2 * MAX_SHORT_STRING_SIZE;
04059 if( Size > *ResultSize )
04060 {
04061 #ifdef RIO_DEBUG2
04062 if( s_mgr->m_log.is_open() )
04063 s_mgr->m_log << "SessionManager - ExecuteRouter "
04064 << " Error on size "
04065 << endl;
04066 #endif
04067 return ERROR_CONNECTIONMANAGER + ERROR_RESULT_MESSAGE_OVERFLOW;
04068 }
04069 offset = 0;
04070
04071
04072 SetLong( *Result, hresult, &offset );
04073
04074
04075 *ResultSize = offset;
04076
04077 return S_OK;
04078 }
04079
04080
04081 case RioMethodRouterSetNATMappings:
04082 {
04083 unsigned int NumberOfNodes, PosError;
04084 GetNumberOfStorageNodes( &NumberOfNodes );
04085
04086
04087 PosError = NumberOfNodes + 1;
04088
04089
04090 NumberOfNodes++;
04091
04092
04093 NumberOfNodes = 2 * NumberOfNodes;
04094
04095 bool ServerNatfilled = false;
04096 unsigned int id;
04097
04098 #ifdef RIO_DEBUG2
04099 RioErr << "NumberOfNodes = " << NumberOfNodes << endl;
04100 #endif
04101
04102 for( id = 0; id < NumberOfNodes; id++ )
04103 {
04104 NATData currNAT;
04105 int curr_addr, curr_port;
04106 if( !GetLong( Parameter, ParameterSize, &curr_addr, &offset ) )
04107 {
04108 if( id == PosError )
04109 break;
04110 else
04111 return ERROR_CONNECTIONMANAGER +
04112 ERROR_INVALID_METHOD_PARAM;
04113 }
04114 if( !GetLong( Parameter, ParameterSize, &curr_port, &offset ) )
04115 {
04116 if( id == PosError )
04117 break;
04118 else
04119 return ERROR_CONNECTIONMANAGER +
04120 ERROR_INVALID_METHOD_PARAM;
04121 }
04122 #ifdef RIO_DEBUG2
04123 in_addr ipr;
04124
04125 ipr.s_addr = curr_addr;
04126
04127 RioErr << "SessionManager::ExecuteRouter Recebendo o par de "
04128 << "enderecos numero " << id << ": IP = "
04129 << inet_ntoa( ipr ) << ", Porta = "
04130 << ntohs( curr_port ) << "." << endl;
04131 #endif
04132 currNAT.nat_addr = curr_addr;
04133 currNAT.nat_port = curr_port;
04134 if( !ServerNatfilled )
04135 {
04136
04137
04138 s_ServerNat.nat_addr = currNAT.nat_addr;
04139 s_ServerNat.nat_port = currNAT.nat_port;
04140 ServerNatfilled = true;
04141 }
04142 s_mgr->SetNATMapping( s_ServerNat, id, currNAT );
04143 }
04144
04145 #ifdef RIO_DEBUG2
04146
04147 s_mgr->m_Router->PrintNATMapping();
04148 #endif
04149
04150 offset = 0;
04151
04152 SetLong( *Result, S_OK, &offset );
04153
04154 return S_OK;
04155 }
04156
04157
04158
04159
04160
04161 case RioMethodRouterSearchLogsRequest:
04162 {
04163 #ifdef RIO_DEBUG2
04164 struct in_addr clientip;
04165 clientip.s_addr = s_remoteAddress.sin_addr.s_addr;
04166 if( s_mgr->m_log.is_open() )
04167 s_mgr->m_log << "SessionManager - ExecuteRouter "
04168 << " ip: " << inet_ntoa(clientip)
04169 << " port: " << htons( s_remoteAddress.sin_port )
04170 << " search logs request " << endl;
04171 #endif
04172
04173
04174 offset = 0;
04175 u32 reqid, serveripaddr, clientipaddr, searchtype;
04176 u16 serverport, clientport;
04177 time_t starttime, endtime;
04178 HRESULT hresult;
04179 unsigned int AuxInt;
04180
04181
04182 if( !GetULong( Parameter, ParameterSize, &searchtype, &offset ) )
04183 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
04184
04185 if( !GetULong( Parameter, ParameterSize, &AuxInt, &offset ) )
04186 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
04187 starttime = AuxInt;
04188
04189 if( !GetULong( Parameter, ParameterSize, &AuxInt, &offset ) )
04190 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
04191 endtime = AuxInt;
04192
04193 if( !GetULong( Parameter, ParameterSize, &serveripaddr, &offset ) )
04194 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
04195
04196 if( !GetUShort( Parameter, ParameterSize, &serverport, &offset ) )
04197 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
04198
04199 if( !GetULong( Parameter, ParameterSize, &clientipaddr, &offset ) )
04200 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
04201
04202 if( !GetUShort( Parameter, ParameterSize, &clientport, &offset ) )
04203 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
04204
04205 if( !GetULong( Parameter, ParameterSize, &reqid, &offset ) )
04206 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
04207
04208
04209
04210 if( endtime < starttime )
04211 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
04212
04213
04214 hresult = SearchLogsRequest( searchtype, starttime, endtime,
04215 serveripaddr, serverport, clientipaddr,
04216 clientport, reqid );
04217
04218 if( FAILED( hresult ) )
04219 {
04220 #ifdef RIO_DEBUG2
04221 if( s_mgr->m_log.is_open() )
04222 s_mgr->m_log << "SessionManager - ExecuteRouter "
04223 << " Failed to call SearchLogsRequest: "
04224 << GetErrorDescription( hresult ) << endl;
04225 #endif
04226 RioErr << " Failed SearchLogsRequest: "
04227 << GetErrorDescription( hresult ) << endl;
04228 }
04229
04230
04231 Size = MAX_LONG_STRING_SIZE;
04232 if( Size > *ResultSize )
04233 {
04234 #ifdef RIO_DEBUG2
04235 if( s_mgr->m_log.is_open() )
04236 s_mgr->m_log << "SessionManager - ExecuteRouter "
04237 << " Error on size "
04238 << endl;
04239 #endif
04240 return ERROR_CONNECTIONMANAGER + ERROR_RESULT_MESSAGE_OVERFLOW;
04241 }
04242 offset = 0;
04243
04244
04245 SetLong( *Result, hresult, &offset );
04246
04247
04248 *ResultSize = offset;
04249
04250 return S_OK;
04251 }
04252
04253
04254 case RioMethodRouterSearchResultDataRequest:
04255 {
04256 #ifdef RIO_DEBUG2
04257 struct in_addr clientip;
04258 clientip.s_addr = s_remoteAddress.sin_addr.s_addr;
04259 if( s_mgr->m_log.is_open() )
04260 s_mgr->m_log << "SessionManager - ExecuteRouter "
04261 << " ip: " << inet_ntoa(clientip)
04262 << " port: " << htons( s_remoteAddress.sin_port )
04263 << " search result data request " << endl;
04264 #endif
04265
04266
04267 offset = 0;
04268 u64 resultfileid;
04269 u32 reqid, serveripaddr, clientipaddr, block, highid, lowid;
04270 u16 serverport, clientport;
04271 HRESULT hresult;
04272
04273
04274 if( !GetULong( Parameter, ParameterSize, &serveripaddr, &offset ) )
04275 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
04276
04277 if( !GetUShort( Parameter, ParameterSize, &serverport, &offset ) )
04278 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
04279
04280 if( !GetULong( Parameter, ParameterSize, &clientipaddr, &offset ) )
04281 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
04282
04283 if( !GetUShort( Parameter, ParameterSize, &clientport, &offset ) )
04284 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
04285
04286 if( !GetULong( Parameter, ParameterSize, &lowid, &offset ) )
04287 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
04288
04289 if( !GetULong( Parameter, ParameterSize, &highid, &offset ) )
04290 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
04291
04292 if( !GetULong( Parameter, ParameterSize, &block, &offset ) )
04293 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
04294
04295 if( !GetULong( Parameter, ParameterSize, &reqid, &offset ) )
04296 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
04297
04298
04299 resultfileid = highid;
04300 resultfileid = ( resultfileid << 32 ) | lowid;
04301
04302
04303
04304 hresult = SearchResultDataRequest( serveripaddr, serverport,
04305 clientipaddr, clientport,
04306 resultfileid, block, reqid );
04307
04308 if( FAILED( hresult ) )
04309 {
04310 #ifdef RIO_DEBUG2
04311 if( s_mgr->m_log.is_open() )
04312 s_mgr->m_log << "SessionManager - ExecuteRouter "
04313 << " Failed to call SearchResultDataRequest: "
04314 << GetErrorDescription( hresult ) << endl;
04315 #endif
04316 RioErr << " Failed SearchResultDataRequest: "
04317 << GetErrorDescription( hresult ) << endl;
04318 }
04319
04320
04321 Size = MAX_LONG_STRING_SIZE;
04322 if( Size > *ResultSize )
04323 {
04324 #ifdef RIO_DEBUG2
04325 if( s_mgr->m_log.is_open() )
04326 s_mgr->m_log << "SessionManager - ExecuteRouter "
04327 << " Error on size "
04328 << endl;
04329 #endif
04330 return ERROR_CONNECTIONMANAGER + ERROR_RESULT_MESSAGE_OVERFLOW;
04331 }
04332 offset = 0;
04333
04334
04335 SetLong( *Result, hresult, &offset );
04336
04337
04338 *ResultSize = offset;
04339
04340 return S_OK;
04341 }
04342
04343
04344 case RioMethodRouterRemoveSearchResultFile:
04345 {
04346 #ifdef RIO_DEBUG2
04347 struct in_addr clientip;
04348 clientip.s_addr = s_remoteAddress.sin_addr.s_addr;
04349 if( s_mgr->m_log.is_open() )
04350 s_mgr->m_log << "SessionManager - ExecuteRouter "
04351 << " ip: " << inet_ntoa(clientip)
04352 << " port: " << htons( s_remoteAddress.sin_port )
04353 << " remove search result file " << endl;
04354 #endif
04355
04356
04357 offset = 0;
04358 u64 resultfileid;
04359 u32 ipaddr, highid, lowid;
04360 u16 port;
04361 HRESULT hresult;
04362
04363
04364 if( !GetULong( Parameter, ParameterSize, &ipaddr, &offset ) )
04365 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
04366
04367 if( !GetUShort( Parameter, ParameterSize, &port, &offset ) )
04368 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
04369
04370 if( !GetULong( Parameter, ParameterSize, &lowid, &offset ) )
04371 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
04372
04373 if( !GetULong( Parameter, ParameterSize, &highid, &offset ) )
04374 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
04375
04376
04377 resultfileid = highid;
04378 resultfileid = ( resultfileid << 32 ) | lowid;
04379
04380
04381 hresult = RemoveSearchResultFile( ipaddr, port, resultfileid );
04382
04383 if( FAILED( hresult ) )
04384 {
04385 #ifdef RIO_DEBUG2
04386 if( s_mgr->m_log.is_open() )
04387 s_mgr->m_log << "SessionManager - ExecuteRouter "
04388 << " Failed to call RemoveSearchResultFile: "
04389 << GetErrorDescription( hresult ) << endl;
04390 #endif
04391 RioErr << " Failed RemoveSearchResultFile: "
04392 << GetErrorDescription( hresult ) << endl;
04393 }
04394
04395
04396 Size = MAX_LONG_STRING_SIZE;
04397 if( Size > *ResultSize )
04398 {
04399 #ifdef RIO_DEBUG2
04400 if( s_mgr->m_log.is_open() )
04401 s_mgr->m_log << "SessionManager - ExecuteRouter "
04402 << " Error on size "
04403 << endl;
04404 #endif
04405 return ERROR_CONNECTIONMANAGER + ERROR_RESULT_MESSAGE_OVERFLOW;
04406 }
04407 offset = 0;
04408
04409
04410 SetLong( *Result, hresult, &offset );
04411
04412
04413 *ResultSize = offset;
04414
04415 return S_OK;
04416 }
04417
04418
04419 default:
04420 {
04421 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD;
04422 };
04423 }
04424 }
04425
04426
04427 int RioSession::ExecuteUserManager( unsigned int Method,
04428 char* Parameter,
04429 unsigned int ParameterSize,
04430 char** Result,
04431 unsigned int* ResultSize )
04432 {
04433 int offset = 0;
04434 unsigned int Size;
04435 switch( Method )
04436 {
04437
04438
04439 case RioMethodUserManagerCreateUser:
04440 {
04441 char* UserName;
04442 char* Password;
04443 HRESULT hResult;
04444
04445 offset = 0;
04446
04447 #ifdef RIO_DEBUG2
04448 struct in_addr clientip;
04449 clientip.s_addr = s_remoteAddress.sin_addr.s_addr;
04450 if( s_mgr->m_log.is_open() )
04451 s_mgr->m_log << " ip: " << inet_ntoa(clientip )
04452 << " port: " << htons( s_remoteAddress.sin_port )
04453 << " creating user " << endl;
04454 #endif
04455
04456
04457
04458
04459
04460 if( !GetString( Parameter, ParameterSize, &UserName, &offset ) )
04461 {
04462 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
04463 }
04464
04465
04466 if( !GetString( Parameter, ParameterSize, &Password, &offset ) )
04467 {
04468 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
04469 }
04470
04471
04472 hResult = CreateUser( UserName, Password );
04473
04474
04475 Size = MAX_LONG_STRING_SIZE;
04476 if( Size > *ResultSize )
04477 {
04478 return ERROR_CONNECTIONMANAGER + ERROR_RESULT_MESSAGE_OVERFLOW;
04479 }
04480 offset = 0;
04481
04482
04483 SetLong( *Result, hResult, &offset );
04484
04485
04486
04487
04488 *ResultSize = offset;
04489 return S_OK;
04490 }
04491
04492
04493
04494 case RioMethodUserManagerRemoveUser:
04495 {
04496 char* UserName;
04497 HRESULT hResult;
04498
04499 offset = 0;
04500
04501 #ifdef RIO_DEBUG2
04502 struct in_addr clientip;
04503 clientip.s_addr = s_remoteAddress.sin_addr.s_addr;
04504 if( s_mgr->m_log.is_open() )
04505 s_mgr->m_log << " ip: " << inet_ntoa(clientip )
04506 << " port: " << htons( s_remoteAddress.sin_port )
04507 << " remove user " << endl;
04508 #endif
04509
04510
04511
04512
04513
04514
04515 if( !GetString( Parameter, ParameterSize, &UserName, &offset ) )
04516 {
04517 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
04518 }
04519
04520
04521 hResult = RemoveUser( UserName );
04522
04523
04524 Size = MAX_LONG_STRING_SIZE;
04525 if( Size > *ResultSize )
04526 {
04527 return ERROR_CONNECTIONMANAGER + ERROR_RESULT_MESSAGE_OVERFLOW;
04528 }
04529 offset = 0;
04530
04531
04532 SetLong( *Result, hResult, &offset );
04533
04534
04535
04536
04537 *ResultSize = offset;
04538 return S_OK;
04539 }
04540
04541
04542
04543 case RioMethodUserManagerChangePassword:
04544 {
04545 char* UserName;
04546 char* Password;
04547 HRESULT hResult;
04548
04549 offset = 0;
04550
04551 #ifdef RIO_DEBUG2
04552 struct in_addr clientip;
04553 clientip.s_addr = s_remoteAddress.sin_addr.s_addr;
04554 if( s_mgr->m_log.is_open() )
04555 s_mgr->m_log << " ip: " << inet_ntoa(clientip )
04556 << " port: " << htons( s_remoteAddress.sin_port )
04557 << " change password " << endl;
04558 #endif
04559
04560
04561
04562
04563
04564
04565 if( !GetString( Parameter, ParameterSize, &UserName, &offset ) )
04566 {
04567 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
04568 }
04569
04570
04571 if( !GetString( Parameter, ParameterSize, &Password, &offset ) )
04572 {
04573 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD_PARAM;
04574 }
04575
04576
04577 hResult = ChangePassword( UserName, Password );
04578
04579
04580 Size = MAX_LONG_STRING_SIZE;
04581 if( Size > *ResultSize )
04582 {
04583 return ERROR_CONNECTIONMANAGER + ERROR_RESULT_MESSAGE_OVERFLOW;
04584 }
04585 offset = 0;
04586
04587
04588 SetLong( *Result, hResult, &offset );
04589
04590
04591
04592
04593 *ResultSize = offset;
04594 return S_OK;
04595 }
04596
04597
04598
04599 case RioMethodUserManagerUserList:
04600 {
04601 HRESULT hResult;
04602 vector< string > UserList;
04603
04604 #ifdef RIO_DEBUG2
04605 struct in_addr clientip;
04606 clientip.s_addr = s_remoteAddress.sin_addr.s_addr;
04607 if( s_mgr->m_log.is_open() )
04608 s_mgr->m_log << " ip: " << inet_ntoa(clientip )
04609 << " port: " << htons( s_remoteAddress.sin_port )
04610 << " user list " << endl;
04611 #endif
04612
04613
04614
04615 hResult = GetUserList( UserList );
04616
04617 if( FAILED( hResult ) )
04618 Size = MAX_LONG_STRING_SIZE;
04619 else
04620 {
04621 Size = MAX_LONG_STRING_SIZE + MAX_ULONG_STRING_SIZE;
04622 for( unsigned int i = 0; i < UserList.size(); i++ )
04623 Size = Size + strlen( UserList[ i ].c_str() ) + 1;
04624
04625 #ifdef RIO_DEBUG2
04626
04627 RioErr << "RioSession::ExecuteUserManager lista de usuarios a "
04628 << "ser enviada, com " << UserList.size()
04629 << " usuarios: ";
04630 for( unsigned int i = 0; i < UserList.size(); i++ )
04631 {
04632 RioErr << UserList[ i ];
04633 if( i != ( UserList.size() - 1 ) )
04634 RioErr << ",";
04635 }
04636 RioErr << endl;
04637 #endif
04638
04639 }
04640
04641
04642 if( Size > *ResultSize )
04643 {
04644 return ERROR_CONNECTIONMANAGER + ERROR_RESULT_MESSAGE_OVERFLOW;
04645 }
04646 offset = 0;
04647
04648
04649 SetLong( *Result, hResult, &offset );
04650
04651
04652 if( !FAILED( hResult ) )
04653 {
04654 SetULong( *Result, UserList.size(), &offset );
04655 for( unsigned int i = 0; i < UserList.size(); i++ )
04656 SetString( *Result, UserList[ i ].c_str(), &offset );
04657 }
04658
04659
04660 *ResultSize = offset;
04661
04662 return S_OK;
04663 }
04664
04665
04666 default:
04667 {
04668 return ERROR_CONNECTIONMANAGER + ERROR_INVALID_METHOD;
04669 };
04670 }
04671 }
04672
04673
04674 int RioSession::CreateUser( char *UserName, char *Password )
04675 {
04676
04677
04678
04679 char *SessionUserName;
04680
04681
04682 s_user->GetUser( &SessionUserName );
04683
04684
04685
04686 if( strcmp( SessionUserName, "root" ) != 0 )
04687 {
04688 return ERROR_RIOSESSION + ERROR_PERMISSION_DENIED;
04689 }
04690
04691
04692
04693 if( ( strcmp( UserName, "guest" ) == 0 ) ||
04694 ( strcmp( UserName, "root" ) == 0 ) ||
04695 ( strcmp( UserName, "var" ) == 0 ) ||
04696 ( strcmp( UserName, "etc" ) == 0 ) )
04697 {
04698 return ERROR_RIOSESSION + ERROR_INVALID_USER;
04699 }
04700
04701
04702
04703 if( strlen( Password ) > MAXPASSWORDSIZE )
04704 {
04705 return ERROR_RIOSESSION + ERROR_INVALID_PARAM;
04706 }
04707
04708 return s_mgr->m_UserManager->CreateUser( UserName, Password );
04709 }
04710
04711
04712 int RioSession::RemoveUser( char *UserName )
04713 {
04714
04715
04716
04717 char *SessionUserName;
04718
04719
04720 s_user->GetUser( &SessionUserName );
04721
04722
04723
04724 if( strcmp( SessionUserName, "root" ) != 0 )
04725 {
04726 return ERROR_RIOSESSION + ERROR_PERMISSION_DENIED;
04727 }
04728
04729
04730
04731 if( ( strcmp( UserName, "guest" ) == 0 ) ||
04732 ( strcmp( UserName, "root" ) == 0 ) ||
04733 ( strcmp( UserName, "var" ) == 0 ) ||
04734 ( strcmp( UserName, "etc" ) == 0 ) )
04735 {
04736 return ERROR_RIOSESSION + ERROR_INVALID_USER;
04737 }
04738
04739 return s_mgr->m_UserManager->RemoveUser( UserName );
04740 }
04741
04742
04743 int RioSession::ChangePassword( char *UserName, char *Password )
04744 {
04745
04746
04747
04748 char *SessionUserName;
04749
04750
04751 s_user->GetUser( &SessionUserName );
04752
04753
04754
04755 if( ( strcmp( SessionUserName, "root" ) != 0 ) &&
04756 ( strcmp( UserName, SessionUserName ) != 0 ) )
04757 {
04758 return ERROR_RIOSESSION + ERROR_PERMISSION_DENIED;
04759 }
04760
04761
04762
04763 if( strcmp( UserName, "guest" ) == 0 )
04764 {
04765 return ERROR_RIOSESSION + ERROR_INVALID_USER;
04766 }
04767
04768
04769
04770 if( strlen( Password ) > MAXPASSWORDSIZE )
04771 {
04772 return ERROR_RIOSESSION + ERROR_INVALID_PARAM;
04773 }
04774
04775 return s_mgr->m_UserManager->ChangePassword( UserName, Password );
04776 }
04777
04778 int RioSession::GetUserList( vector <string> &UserList )
04779 {
04780
04781
04782
04783 char *SessionUserName;
04784
04785
04786 s_user->GetUser( &SessionUserName );
04787
04788
04789
04790 if( strcmp( SessionUserName, "root" ) != 0 )
04791 {
04792 return ERROR_RIOSESSION + ERROR_PERMISSION_DENIED;
04793 }
04794
04795 return s_mgr->m_UserManager->GetUserList( UserList );
04796 }
04797
04798
04799 int RioSession::Open( char *Username, char *Password )
04800 {
04801 int rc;
04802
04803
04804
04805 if( strlen( Password ) > MAXPASSWORDSIZE )
04806 {
04807 return ERROR_RIOSESSION + ERROR_INVALID_PARAM;
04808 }
04809
04810
04811 if( s_user )
04812 {
04813 delete s_user;
04814 s_user = 0;
04815 }
04816 s_CurrentDir[0] = '\0';
04817
04818
04819 rc = s_mgr->m_UserManager->Logon( Username, Password, &s_user );
04820 if( rc )
04821 return rc;
04822
04823
04824 char *s;
04825 rc = s_user->GetUserHome( &s );
04826 if( rc )
04827 {
04828 delete s_user;
04829 s_user = 0;
04830 return rc;
04831 }
04832 strcpy( s_CurrentDir, s );
04833 return rc;
04834 }
04835
04836
04837
04838
04839 int RioSession::OpenStream( RioStreamTraffic *Traffic, int *StreamId )
04840 {
04841
04842 int rc;
04843
04844 RioStream **idp = ( RioStream ** ) newid( StreamId, idt_stream );
04845 if( idp == 0 )
04846 {
04847 return ERROR_SESSIONMANAGER + ERROR_MAX_OPENED_OBJECTS;
04848 }
04849
04850 rc = s_mgr->m_StreamManager->Open( Traffic, idp, s_remoteAddress );
04851 if( rc )
04852 return rc;
04853
04854 return S_OK;
04855 }
04856
04857
04858 int RioSession::CreateObject( char *ObjectName, short Type )
04859 {
04860 int rc;
04861 char Path[MaxPathSize + 1];
04862
04863
04864 rc = ObjectToPath( ObjectName, Path, sizeof( Path ));
04865 if( rc )
04866 return rc;
04867
04868 rc = s_user->CheckAccess( Path, 1 );
04869 if( rc == 0 )
04870 rc = s_mgr->m_ObjectManager->Create( Path, Type );
04871
04872 return rc;
04873 }
04874
04875
04876 int RioSession::DeleteObject( char *ObjectName )
04877 {
04878 int rc;
04879 char Path[MaxPathSize + 1];
04880
04881
04882 rc = ObjectToPath( ObjectName, Path, sizeof( Path ));
04883 if( rc )
04884 return rc;
04885
04886 #ifdef RIO_DEBUG2
04887 RioErr << "Caminho original " << ObjectName << ", caminho convertido "
04888 << Path << endl;
04889
04890 RioErr << "Tentando removendo objeto no caminho " << Path << endl;
04891 #endif
04892
04893 rc = s_user->CheckAccess( Path, 1 );
04894
04895 if( rc == 0 )
04896 {
04897
04898 char *UserName;
04899
04900 s_user->GetUser( &UserName );
04901
04902
04903
04904
04905
04906
04907 if( ( strcmp( Path, UserName ) == 0 ) ||
04908 ( strlen( Path ) == 0 ) )
04909 {
04910 #ifdef RIO_DEBUG2
04911 RioErr << "Permissao negada do remover o objeto no caminho "
04912 << Path << endl;
04913 #endif
04914
04915 return ERROR_RIOSESSION + ERROR_PERMISSION_DENIED;
04916 }
04917
04918 #ifdef RIO_DEBUG2
04919 RioErr << "Removendo objeto no caminho " << Path << endl;
04920 #endif
04921
04922 rc = s_mgr->m_ObjectManager->Delete( Path );
04923 }
04924 #ifdef RIO_DEBUG2
04925 else
04926 RioErr << "Permissao negada do remover o objeto no caminho " << Path
04927 << endl;
04928 #endif
04929
04930 return rc;
04931 }
04932
04933 int RioSession::RenameObject( char *CurrentName, char *NewName )
04934 {
04935 int rc;
04936 char CurPath[MaxPathSize + 1];
04937 char NewPath[MaxPathSize + 1];
04938
04939
04940 rc = ObjectToPath( CurrentName, CurPath, sizeof( CurPath ));
04941 if( rc )
04942 return rc;
04943 rc = ObjectToPath( NewName, NewPath, sizeof( NewPath ));
04944 if( rc )
04945 return rc;
04946
04947 rc = s_user->CheckAccess( CurPath, 1 );
04948 if( rc != 0 )
04949 return rc;
04950
04951 rc = s_user->CheckAccess( NewPath, 1 );
04952
04953 if( rc == 0 )
04954 {
04955
04956 char *UserName;
04957
04958 s_user->GetUser( &UserName );
04959
04960
04961
04962
04963
04964
04965 if( ( strcmp( CurPath, UserName ) == 0 ) ||
04966 ( strlen( CurPath ) == 0 ) )
04967 {
04968 #ifdef RIO_DEBUG2
04969 RioErr << "Permissao negada do renomear o objeto no caminho "
04970 << CurPath << endl;
04971 #endif
04972
04973 return ERROR_RIOSESSION + ERROR_PERMISSION_DENIED;
04974 }
04975
04976 #ifdef RIO_DEBUG2
04977 RioErr << "Renomeando objeto no caminho " << CurPath << " para "
04978 << NewPath << endl;
04979 #endif
04980
04981 rc = s_mgr->m_ObjectManager->Rename( CurPath, NewPath );
04982 }
04983
04984 return rc;
04985 }
04986
04987 int RioSession::GetBlockSize( unsigned int *BlockSize )
04988 {
04989 *BlockSize = s_mgr->m_BlockSize;
04990 return S_OK;
04991 }
04992
04993
04994 int RioSession::GetRemoteAddress( SOCKADDR_IN *Address )
04995 {
04996 *Address = s_remoteAddress;
04997 return S_OK;
04998 }
04999
05000
05001
05002
05003 int RioSession::RemoveIdEntryFromTable(int ObjectId, idtype type )
05004 {
05005 if( ( unsigned ) ObjectId > ( unsigned ) s_idmax )
05006 return -1;
05007 if( s_idtable[ObjectId].id_type != type )
05008 return -1;
05009
05010 s_idtable[ObjectId].id_type = idt_invalid;
05011 s_idtable[ObjectId].id_object = 0;
05012 return S_OK;
05013 }
05014
05015
05016
05017 int RioSession::GetNumberOfDisks( unsigned int *NumberOfDisks )
05018 {
05019 *NumberOfDisks = s_mgr->m_NumberOfDisks;
05020 return S_OK;
05021 }
05022
05023
05024 int RioSession::GetNumberOfStorageNodes( unsigned int *NumberOfStorageNodes )
05025 {
05026 *NumberOfStorageNodes = s_mgr->m_NumberOfStorageNodes;
05027 return S_OK;
05028 }
05029
05030
05031
05032 int RioSession::GetStorageNodeInfo( unsigned int StorageNodeIndex,
05033 RioStorageNodeInfo* StorageNodeInfo )
05034 {
05035 int rc = 0;
05036 rc = s_mgr->m_DiskMgr->GetStorageNodeInfo( StorageNodeIndex,
05037 StorageNodeInfo );
05038 return rc;
05039 }
05040
05041
05042
05043 int RioSession::GetNumberOfActiveAndMaxSessions(
05044 unsigned int *NumberOfActiveSessions,
05045 unsigned int *NumberOfMaxSessions )
05046 {
05047 *NumberOfActiveSessions = s_mgr->m_used;
05048 *NumberOfMaxSessions = s_mgr->m_MaxSessions;
05049 return S_OK;
05050 }
05051
05052 int RioSession::FirstObject( char* DirectoryName, int *dirid,
05053 int* IsDirectory, int BufferSize,
05054 char* ObjectName )
05055 {
05056 int rc;
05057 char Path[MaxPathSize + 1];
05058
05059
05060 rc = ObjectToPath( DirectoryName, Path, sizeof( Path ));
05061 if( rc )
05062 return rc;
05063
05064 RioDirectory **idp = (RioDirectory **) newid( dirid, idt_directory );
05065 if( idp == 0 )
05066 {
05067 return ERROR_SESSIONMANAGER + ERROR_MAX_OPENED_OBJECTS;
05068 }
05069
05070 rc = s_user->CheckAccess( Path );
05071
05072 if( rc == 0 )
05073 rc = s_mgr->m_ObjectManager->FirstObject( Path, idp,
05074 IsDirectory, BufferSize,
05075 ObjectName );
05076 return rc;
05077 }
05078
05079 int RioSession::NextObject( int DirectoryId, int *IsDirectory,
05080 int BufferSize, char *ObjectName )
05081 {
05082 RioDirectory *dp = (RioDirectory *) checkid( DirectoryId, idt_directory );
05083
05084
05085 *IsDirectory = false;
05086 ObjectName[ 0 ] = 0;
05087
05088 if( dp == 0 )
05089 {
05090 return ERROR_SESSIONMANAGER + ERROR_OBJECT_NOT_DIRECTORY;
05091 }
05092
05093 return dp->NextObject( IsDirectory, BufferSize, ObjectName );
05094 }
05095
05096 int RioSession::GetObjectInfo( char* ObjectName, ObjectInfo* ObjectInfo )
05097 {
05098 int rc;
05099 char Path[MaxPathSize + 1];
05100
05101
05102 rc = ObjectToPath( ObjectName, Path, sizeof( Path ) );
05103 if( rc )
05104 return rc;
05105
05106 return s_mgr->m_ObjectManager->GetObjectInfo( Path, ObjectInfo );
05107 }
05108
05109 int RioSession::ChangeDir( char * Dir )
05110 {
05111 int rc;
05112 char newdir[MaxPathSize + 1];
05113
05114
05115 rc = ObjectToPath( Dir, newdir, sizeof( newdir ));
05116 if( rc )
05117 return rc;
05118
05119 rc = s_user->CheckAccess( newdir );
05120 if( rc == 0 )
05121 {
05122 rc = s_mgr->m_ObjectManager->ExistDirectory( newdir );
05123 if( rc )
05124 return rc;
05125 }
05126 else
05127 return rc;
05128
05129 strcpy( s_CurrentDir, newdir );
05130 return S_OK;
05131 }
05132
05133 int RioSession::GetCurrentDir( int size, char *Dir )
05134 {
05135 if( (( signed ) strlen( s_CurrentDir ) + 1 ) >= size )
05136 {
05137 return ERROR_SESSIONMANAGER + ERROR_NAMEBUFFER_OVERFLOW;
05138 }
05139
05140 strcpy( Dir, "/" );
05141 strcpy( Dir + 1, s_CurrentDir );
05142 return S_OK;
05143 }
05144
05145 int RioSession::GetSize( int ObjectId, RioObjectSize *ObjectSize )
05146 {
05147 RioStreamObj *op = ( RioStreamObj * ) checkid( ObjectId, idt_streamobj );
05148 if( op == 0 )
05149 {
05150 RioErr << "Invalid Object Handle "<< ObjectId << endl;
05151 return ERROR_SESSIONMANAGER + ERROR_INVALID_OBJECT_HANDLE;
05152 }
05153 return op->GetSize( ObjectSize );
05154 }
05155
05156 int RioSession::SetSize( int ObjectId, RioObjectSize ObjectSize, char *md5sum,
05157 unsigned long long int ExcludeStorages )
05158 {
05159 int rc;
05160
05161 RioStreamObj *op = ( RioStreamObj * ) checkid( ObjectId, idt_streamobj );
05162 if( op == 0 )
05163 {
05164 return ERROR_SESSIONMANAGER + ERROR_INVALID_OBJECT_HANDLE;
05165 }
05166 rc = op->SetSize( ObjectSize, md5sum, ExcludeStorages );
05167 return rc;
05168 }
05169
05170 int RioSession::GetType( int ObjectId, short *Type )
05171 {
05172 RioStreamObj *op = ( RioStreamObj * ) checkid( ObjectId, idt_streamobj );
05173 if( op == 0 )
05174 {
05175 return ERROR_SESSIONMANAGER + ERROR_INVALID_OBJECT_HANDLE;
05176 }
05177
05178 return op->GetType( Type );
05179 }
05180
05181 int RioSession::GetnBlocks( int ObjectId, RioBlock *nBlocks )
05182 {
05183 RioStreamObj *op = ( RioStreamObj * ) checkid( ObjectId, idt_streamobj );
05184 if( op == 0 )
05185 {
05186 return ERROR_SESSIONMANAGER + ERROR_INVALID_OBJECT_HANDLE;
05187 }
05188
05189 return op->GetnBlocks( nBlocks );
05190 }
05191
05192
05193
05194
05195
05196 int RioSession::CloseObject( int ObjectId )
05197 {
05198 RioStreamObj *op = (RioStreamObj *) checkid( ObjectId, idt_streamobj);
05199
05200 #ifdef USE_GRID
05201
05202
05203
05204
05205 char ObjectName[ 2*MaxPathSize+1 ];
05206
05207
05208
05209 char *RioObjectName;
05210
05211 int status;
05212
05213 struct stat FileStat;
05214
05215 bool DeleteStreamObj;
05216 #else
05217 char ObjectName[ 2*MaxPathSize+1 ];
05218 char *RioObjectName;
05219
05220 bool DeleteStreamObj;
05221 #endif
05222
05223 if( op == 0 )
05224 {
05225
05226 RioDirectory *dp = (RioDirectory *) checkid( ObjectId, idt_directory );
05227 if( dp == 0 )
05228 {
05229 return ERROR_SESSIONMANAGER + ERROR_INVALID_OBJECT_HANDLE;
05230 }
05231 dp->Close();
05232 delete dp;
05233 s_idtable[ ObjectId ].id_type = idt_invalid;
05234 s_idtable[ ObjectId ].id_object = 0;
05235 return S_OK;
05236 }
05237
05238 #ifdef USE_GRID
05239
05240
05241
05242 op->GetObjectName( ObjectName );
05243
05244
05245 RioObjectName = &ObjectName[ strlen( s_mgr->m_FileRoot ) + 1 ];
05246 if( RioObjectName == NULL )
05247
05248
05249 return ERROR_SESSIONMANAGER + ERROR_UNEXPECTED;
05250
05251
05252
05253 status = stat( ObjectName, &FileStat );
05254
05255 if( status )
05256
05257
05258 return ERROR_SESSIONMANAGER + ERROR_UNEXPECTED;
05259
05260
05261
05262 status = s_mgr->m_ObjectManager->ChangeLastAccess( RioObjectName,
05263 FileStat.st_atime );
05264
05265 if( status )
05266
05267
05268
05269 return status;
05270
05271
05272
05273 if( s_mgr->m_log.is_open() )
05274 s_mgr->m_log << "RioSession::CloseObject Object " << ObjectName
05275 << ", FileName = /" << RioObjectName << " closed. "
05276 << "Last Access Time = " << FileStat.st_atime << endl;
05277
05278
05279
05280 s_mgr->m_ObjectManager->PrintFileList();
05281 #else
05282
05283
05284
05285 op->GetObjectName( ObjectName );
05286
05287
05288 RioObjectName = &ObjectName[ strlen( s_mgr->m_FileRoot ) + 1 ];
05289 #endif
05290
05291 op->Close( &DeleteStreamObj );
05292 s_idtable[ ObjectId ].id_type = idt_invalid;
05293 s_idtable[ ObjectId ].id_object = 0;
05294
05295
05296
05297
05298
05299 if( DeleteStreamObj )
05300 {
05301
05302
05303
05304 delete op;
05305 }
05306
05307 struct in_addr clientip;
05308 clientip.s_addr = s_remoteAddress.sin_addr.s_addr;
05309
05310 DisconnectEvent *it_event = new DisconnectEvent( inet_ntoa(clientip),
05311 htons( s_remoteAddress.sin_port ), RioObjectName );
05312 s_mgr->PostITEvent( (MonitorEvent *)it_event );
05313
05314
05315
05316
05317 SaveLogLine( "Close", &ObjectName[ strlen( s_mgr->m_FileRoot ) ] );
05318
05319 return S_OK;
05320 }
05321
05322
05323
05324
05325
05326 int RioSession::ObjectToPath( char* ObjectName, char* RioPath, int PathSize )
05327 {
05328
05329 if( ObjectName[0] == '/' )
05330 {
05331
05332
05333
05334
05335 return s_mgr->m_ObjectManager->StrToPath( ObjectName + 1,
05336 RioPath, PathSize );
05337 }
05338
05339
05340 int DirSize = strlen(s_CurrentDir);
05341 if( ( DirSize + 1 + strlen( ObjectName )) > MaxPathSize )
05342 {
05343 return ERROR_SESSIONMANAGER + ERROR_PATHNAME_TOOLARGE;
05344 }
05345
05346 char ObjectPath[MaxPathSize + 1];
05347 *ObjectPath = '\0';
05348
05349 if( DirSize != 0 )
05350 {
05351 strcpy( ObjectPath, s_CurrentDir );
05352
05353 if( strlen( ObjectName ) != 0 )
05354 strcat ( ObjectPath, "/" );
05355 }
05356 strcat( ObjectPath, ObjectName );
05357 return s_mgr->m_ObjectManager->StrToPath( ObjectPath, RioPath, PathSize );
05358 }
05359
05360
05361
05362
05363
05364
05365
05366
05367
05368
05369 int RioSession::GetVideoRate( int ObjectId, unsigned int *VideoRate )
05370 {
05371 RioStreamObj *op = ( RioStreamObj * ) checkid( ObjectId, idt_streamobj );
05372 if( op == 0 )
05373 {
05374 return ERROR_SESSIONMANAGER + ERROR_INVALID_OBJECT_HANDLE;
05375 }
05376
05377 return op->GetVideoRate( VideoRate );
05378 }
05379
05380
05381
05382
05383
05384 int RioSession::SetVideoRate( int ObjectId, unsigned int VideoRate )
05385 {
05386 RioStreamObj *op = ( RioStreamObj * ) checkid( ObjectId, idt_streamobj );
05387 if( op == 0 )
05388 {
05389 return ERROR_SESSIONMANAGER + ERROR_INVALID_OBJECT_HANDLE;
05390 }
05391
05392 return op->SetVideoRate( VideoRate );
05393 }
05394
05395
05396
05397
05398
05399
05400
05401 int RioSession::ReallocBlocks( int ObjectId, unsigned int Block,
05402 unsigned long long int ExcludeStorages )
05403 {
05404 RioStreamObj *op = ( RioStreamObj * ) checkid( ObjectId, idt_streamobj );
05405 if( op == 0 )
05406 {
05407 return ERROR_SESSIONMANAGER + ERROR_INVALID_OBJECT_HANDLE;
05408 }
05409
05410 return op->ReallocBlocks( Block, ExcludeStorages );
05411 }
05412
05413
05414
05415
05416
05417
05418 int RioSession::SaveLogLine( const char *StrInfo, const char *ObjectName )
05419 {
05420 int status;
05421 char LogLine[ MAXLOGLINESIZE ];
05422 sprintf( LogLine, "%u %s %s %s %u", s_mgr->m_used, StrInfo, ObjectName,
05423 inet_ntoa( s_remoteAddress.sin_addr ),
05424 ntohs( s_remoteAddress.sin_port ) );
05425 status = s_mgr->m_LogRotation->NewLogLine( time( NULL ), LogLine );
05426 #ifdef RIO_DEBUG2
05427 if( status != S_OK )
05428 RioErr << "RioSession::SaveLogLine erro ao salvar uma linha no "
05429 << "log com o comportamento dos clientes" << endl;
05430 #endif
05431 return status;
05432 }
05433
05434
05435 int RioSession::SearchLogsRequest( u32 searchtype, time_t starttime,
05436 time_t endtime, u32 serveripaddr,
05437 u16 serverport, u32 clientipaddr,
05438 u16 clientport, u32 reqid )
05439 {
05440
05441
05442
05443
05444 if( ( serveripaddr == s_mgr->m_ServerAddress[ 0 ].sin_addr.s_addr ) &&
05445 ( serverport == s_mgr->m_ServerAddress[ 0 ].sin_port ) )
05446 {
05447
05448
05449
05450
05451
05452 if( searchtype != SEARCHINCLIENTSLOGS )
05453 return ERROR_CONNECTIONMANAGER + ERROR_SEARCHLOGS_SEARCH_TYPE;
05454
05455 #ifdef RIO_DEBUG2
05456 in_addr ip;
05457 ip.s_addr = clientipaddr;
05458 RioErr << "RioSession::SearchLogsRequest Executando uma busca do tipo "
05459 << searchtype << " a partir do tempo " << starttime
05460 << " ate o tempo " << endtime << " nos logs do comportamento "
05461 << "dos clientes para o cliente com o IP " << inet_ntoa( ip )
05462 << " e porta " << ntohs( clientport ) << ", usando a id "
05463 << reqid << endl;
05464 #endif
05465
05466
05467
05468
05469
05470
05471 s_mgr->m_SearchLogs->SearchLogsRequestSendError( starttime, endtime,
05472 clientipaddr, clientport,
05473 reqid );
05474 return S_OK;
05475 }
05476 else
05477 {
05478
05479
05480
05481
05482
05483 if( searchtype != SEARCHINTRAFFICLOGS )
05484 return ERROR_CONNECTIONMANAGER + ERROR_SEARCHLOGS_SEARCH_TYPE;
05485
05486 #ifdef RIO_DEBUG2
05487 in_addr ip;
05488 ip.s_addr = clientipaddr;
05489 RioErr << "RioSession::SearchLogsRequest Executando uma busca do tipo "
05490 << searchtype << " a partir do tempo " << starttime
05491 << " ate o tempo " << endtime << " nos logs do comportamento "
05492 << "dos clientes para o cliente com o IP " << inet_ntoa( ip )
05493 << " e porta " << ntohs( clientport ) << ", usando a id "
05494 << reqid;
05495 ip.s_addr = serveripaddr;
05496 RioErr << ", para o servidor de armazenamento com o IP "
05497 << inet_ntoa( ip ) << " e a porta " << ntohs( serverport )
05498 << endl;
05499 #endif
05500
05501
05502 EventStorageRequest *event;
05503 event = ( EventStorageRequest* ) EventManager.
05504 New( EventTypeStorageRequest );
05505 if( event == NULL )
05506 return ERROR_CONNECTIONMANAGER + ERROR_MEMORY;
05507 event->StorageRequest.Header.Type = MSG_RSS_START_SEARCH_IN_LOGS_REQ;
05508 event->StorageRequest.Header.Size = SizeMsgRSSStartSearchInLogsReq;
05509 event->StorageRequest.Header.Token = RSS_TOKEN_ROUTER;
05510
05511
05512 MsgRSSStartSearchInLogsReq *Msg = & ( event->StorageRequest.
05513 StartSearchInLogs );
05514 Msg->SearchType = searchtype;
05515 Msg->StartTime = starttime;
05516 Msg->EndTime = endtime;
05517 Msg->IPaddr = clientipaddr;
05518 Msg->Port = clientport;
05519 Msg->ClientId = reqid;
05520
05521
05522 s_mgr->m_DiskMgr->SendStorageNodeByIP( event, serveripaddr );
05523
05524 return S_OK;
05525 }
05526
05527 }
05528
05529
05530
05531 int RioSession::SearchResultDataRequest( u32 serveripaddr, u16 serverport,
05532 u32 clientipaddr, u16 clientport,
05533 u64 resultfileid, u32 block,
05534 u32 reqid )
05535 {
05536
05537
05538
05539
05540 if( ( serveripaddr == s_mgr->m_ServerAddress[ 0 ].sin_addr.s_addr ) &&
05541 ( serverport == s_mgr->m_ServerAddress[ 0 ].sin_port ) )
05542 {
05543 #ifdef RIO_DEBUG2
05544 in_addr ip;
05545 ip.s_addr = clientipaddr;
05546 RioErr << "RioSession::SearchResultDataRequest Pedido do bloco "
05547 << block << " do arquivo com o identificador " << resultfileid
05548 << " a partir do cliente com o IP " << inet_ntoa( ip )
05549 << " e porta " << ntohs( clientport ) << ", usando a id "
05550 << reqid << endl;
05551 #endif
05552
05553
05554
05555
05556
05557
05558 s_mgr->m_SearchLogs->SearchResultDataRequestSendError( clientipaddr,
05559 clientport,
05560 resultfileid,
05561 block, reqid );
05562 return S_OK;
05563 }
05564 else
05565 {
05566 #ifdef RIO_DEBUG2
05567 in_addr ip;
05568 ip.s_addr = clientipaddr;
05569 RioErr << "RioSession::SearchResultDataRequest Pedido do bloco "
05570 << block << " do arquivo com o identificador " << resultfileid
05571 << " a partir do cliente com o IP " << inet_ntoa( ip )
05572 << " e porta " << ntohs( clientport ) << ", usando a id "
05573 << reqid;
05574 ip.s_addr = serveripaddr;
05575 RioErr << ", para o servidor de armazenamento com o IP "
05576 << inet_ntoa( ip ) << " e a porta " << ntohs( serverport )
05577 << endl;
05578 #endif
05579
05580
05581
05582 EventStorageRequest *event;
05583 event = ( EventStorageRequest* ) EventManager.
05584 New( EventTypeStorageRequest );
05585 if( event == NULL )
05586 return ERROR_CONNECTIONMANAGER + ERROR_MEMORY;
05587
05588 event->StorageRequest.Header.Type = MSG_RSS_BLOCK_SEARCH_FILE_REQ;
05589 event->StorageRequest.Header.Size = SizeMsgRSSBlockSearchFileReq;
05590 event->StorageRequest.Header.Token = RSS_TOKEN_ROUTER;
05591
05592
05593 MsgRSSBlockSearchFileReq *Msg = & ( event->StorageRequest.
05594 BlockSearchFile );
05595 Msg->IPaddr = clientipaddr;
05596 Msg->Port = clientport;
05597 Msg->FileId = resultfileid;
05598 Msg->Block = block;
05599 Msg->ClientId = reqid;
05600
05601
05602 s_mgr->m_DiskMgr->SendStorageNodeByIP( event, serveripaddr );
05603
05604 return S_OK;
05605 }
05606 }
05607
05608
05609
05610
05611 int RioSession::RemoveSearchResultFile( u32 serveripaddr, u16 serverport,
05612 u64 resultfileid )
05613 {
05614
05615
05616
05617
05618 if( ( serveripaddr == s_mgr->m_ServerAddress[ 0 ].sin_addr.s_addr ) &&
05619 ( serverport == s_mgr->m_ServerAddress[ 0 ].sin_port ) )
05620 {
05621 #ifdef RIO_DEBUG2
05622 RioErr << "RioSession::RemoveSearchResultFile Pedido de remocao do "
05623 << " do arquivo com o identificador " << resultfileid << endl;
05624 #endif
05625
05626
05627 return s_mgr->m_SearchLogs->RemoveSearchResultFile( resultfileid );
05628 }
05629 else
05630 {
05631
05632
05633 #ifdef RIO_DEBUG2
05634 in_addr ip;
05635 ip.s_addr = serveripaddr;
05636 RioErr << "RioSession::RemoveSearchResultFile Pedido de remocao do "
05637 << " do arquivo com o identificador " << resultfileid
05638 << ", para o servidor de armazenamento com o IP "
05639 << inet_ntoa( ip ) << " e a porta " << ntohs( serverport )
05640 << endl;
05641 #endif
05642
05643
05644
05645 EventStorageRequest *event;
05646 event = ( EventStorageRequest* ) EventManager.
05647 New( EventTypeStorageRequest );
05648 if( event == NULL )
05649 return ERROR_CONNECTIONMANAGER + ERROR_MEMORY;
05650
05651 event->StorageRequest.Header.Type = MSG_RSS_REMOVE_SEARCH_FILE_REQ;
05652 event->StorageRequest.Header.Size = SizeMsgRSSRemoveSearchFileReq;
05653 event->StorageRequest.Header.Token = RSS_TOKEN_ROUTER;
05654
05655
05656
05657 MsgRSSRemoveSearchFileReq *Msg = & ( event->StorageRequest.
05658 RemoveSearchFile );
05659
05660 Msg->FileId = resultfileid;
05661
05662
05663 s_mgr->m_DiskMgr->SendStorageNodeByIP( event, serveripaddr );
05664
05665 return S_OK;
05666 }
05667 }
05668