00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "RioError.h"
00020 #include "ServerInterface.h"
00021 #include "RioModuleTypes.h"
00022 #include "common.h"
00023 #include "UserLogs.h"
00024
00025
00026 #include <http_config.h>
00027 #include <http_log.h>
00028 #include <util_filter.h>
00029 #include <http_protocol.h>
00030 #include <apr_strings.h>
00031 #include <http_request.h>
00032
00033
00034 #include <stdlib.h>
00035
00036 #ifdef RIO_DEBUG2
00037
00038 #include <sys/syscall.h>
00039 #endif
00040
00041
00042 TExecCmd CommandTable[] = {
00043 { "login", CMD_LOGIN_ID, 2, 2 },
00044 { "quit", CMD_QUIT_ID, 0, 0 },
00045 { "sessions", CMD_SESSIONS_ID, 0, 0 },
00046 { "ls", CMD_LS_ID, 1, 1 },
00047 { "rm", CMD_RM_ID, 1, 1 },
00048 { "mkdir", CMD_MKDIR_ID, 1, 1 },
00049 { "download", CMD_DOWNLOAD_ID, 1, 3 },
00050 { "mv", CMD_MV_ID, 2, 2 },
00051 { "upload", CMD_UPLOAD_ID, 2, 2 },
00052 { "adduser", CMD_ADDUSER_ID, 2, 2 },
00053 { "deluser", CMD_DELUSER_ID, 1, 1 },
00054 { "passwd", CMD_PASSWD_ID, 2, 2 },
00055 { "userlist", CMD_USERLIST_ID, 0, 0 },
00056 { NULL, CMD_INV_ID, 0, 0 } };
00057
00058
00059
00060 TLogCmd LogCommandTable[] = {
00061 { "login", 2 },
00062 { "adduser", 2 },
00063 { "passwd", 2 },
00064 { NULL, 0 } };
00065
00066
00067 CModuleRioExplorer::CModuleRioExplorer( server_rec *Server )
00068 {
00069
00070 m_Server = Server;
00071 }
00072
00073
00074 CModuleRioExplorer::~CModuleRioExplorer()
00075 {
00076
00077 }
00078
00079
00080 bool CModuleRioExplorer::showMessage( int type, string message, string title )
00081 {
00082 #ifdef RIO_DEBUG2
00083 switch( type )
00084 {
00085 case ERROR_MSG:
00086 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
00087 "[%s] %s", title.c_str(), message.c_str() );
00088 break;
00089
00090 case WARNING_MSG:
00091 ap_log_error( APLOG_MARK, APLOG_WARNING, 0, m_Server,
00092 "[%s] %s", title.c_str(), message.c_str() );
00093 break;
00094
00095 case INFO_MSG:
00096 ap_log_error( APLOG_MARK, APLOG_INFO, 0, m_Server,
00097 "[%s] %s", title.c_str(), message.c_str() );
00098 break;
00099
00100 default:
00101 ap_log_error( APLOG_MARK, APLOG_NOTICE, 0, m_Server,
00102 "[Invalid message type - %s] %s", title.c_str(),
00103 message.c_str() );
00104 break;
00105 }
00106 #endif
00107
00108 return true;
00109 }
00110
00111
00112 CServerInterface::CServerInterface( server_rec *Server )
00113 {
00114 int status;
00115
00116
00117 m_Server = Server;
00118
00119
00120 m_FragmentSize = 0;
00121 m_CircularBufferSize = 0;
00122 m_RioExplorer = NULL;
00123 m_Session = NULL;
00124 m_isSessionOpen = false;
00125 m_Stream = NULL;
00126 m_isStreamOpen = false;
00127 m_Object = NULL;
00128 m_isObjectOpen = false;
00129 m_CircularBuffer = NULL;
00130 m_RioBuffer = NULL;
00131 m_ApacheBuffer = NULL;
00132 m_ServerName = NULL;
00133 m_Started = false;
00134 m_ReadRioThread = 0;
00135 m_ThreadCanceled = false;
00136 m_RioBlock = 0;
00137 m_SendBlock = 0;
00138 m_TotalBlocks = 0;
00139 m_isReadingRioFile = false;
00140 m_BlockSize = 0;
00141 m_SessionId = 0;
00142 m_UserName = NULL;
00143 m_LastApacheBlockSize = 0;
00144 m_IsApacheEof = false;
00145 m_UploadRequest = NULL;
00146 m_isReadingApacheFile = false;
00147 m_ReadApacheThread = 0;
00148 m_DefaultSessionId = 0;
00149 m_ExecLogPort = 0;
00150
00151
00152 m_SystemStatus = 0;
00153 m_ApacheStatus = APR_SUCCESS;
00154 m_RioStatus = S_OK;
00155
00156
00157 status = pthread_mutex_init( &m_ReadWriteMutex, NULL );
00158 if( status < 0 )
00159 {
00160 m_SystemStatus = status;
00161
00162 #ifdef RIO_DEBUG2
00163 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
00164 "Error initializing m_ReadWriteMutex: %u (%s)",
00165 m_SystemStatus, strerror( m_SystemStatus ) );
00166 #endif
00167
00168 return;
00169 }
00170
00171 status = pthread_cond_init( &m_ReadWriteCond, NULL );
00172 if( status < 0 )
00173 {
00174 m_SystemStatus = status;
00175
00176 #ifdef RIO_DEBUG2
00177 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
00178 "Error initializing m_ReadWriteCond: %u (%s)",
00179 m_SystemStatus, strerror( m_SystemStatus ) );
00180 #endif
00181
00182 return;
00183 }
00184
00185 status = pthread_cond_init( &m_ReadRioStarted, NULL );
00186 if( status < 0 )
00187 {
00188 m_SystemStatus = status;
00189
00190 #ifdef RIO_DEBUG2
00191 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
00192 "Error initializing m_ReadRioStarted: %u (%s)",
00193 m_SystemStatus, strerror( m_SystemStatus ) );
00194 #endif
00195
00196 return;
00197 }
00198
00199 status = pthread_cond_init( &m_ReadApacheStarted, NULL );
00200 if( status < 0 )
00201 {
00202 m_SystemStatus = status;
00203
00204 #ifdef RIO_DEBUG2
00205 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
00206 "Error initializing m_ReadApacheStarted: %u (%s)",
00207 m_SystemStatus, strerror( m_SystemStatus ) );
00208 #endif
00209
00210 return;
00211 }
00212
00213 status = pthread_cond_init( &m_ThreadBlocked, NULL );
00214 if( status < 0 )
00215 {
00216 m_SystemStatus = status;
00217
00218 #ifdef RIO_DEBUG2
00219 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
00220 "Error initializing m_ThreadBlocked: %u (%s)",
00221 m_SystemStatus, strerror( m_SystemStatus ) );
00222 #endif
00223
00224 return;
00225 }
00226
00227 status = pthread_mutex_init( &m_Mutex, NULL );
00228 if( status < 0 )
00229 {
00230 m_SystemStatus = status;
00231
00232 #ifdef RIO_DEBUG2
00233 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
00234 "Error initializing m_Mutex: %u (%s)",
00235 m_SystemStatus, strerror( m_SystemStatus ) );
00236 #endif
00237
00238 return;
00239 }
00240 }
00241
00242
00243 CServerInterface::~CServerInterface()
00244 {
00245 int status;
00246
00247
00248 if( m_Started )
00249 Stop();
00250
00251 status = pthread_mutex_destroy( &m_ReadWriteMutex );
00252 if( status < 0 )
00253 {
00254 #ifdef RIO_DEBUG2
00255 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
00256 "Error destroying m_ReadWriteMutex: %u (%s)", status,
00257 strerror( status ) );
00258 #endif
00259 }
00260
00261 status = pthread_cond_destroy( &m_ReadWriteCond );
00262 if( status < 0 )
00263 {
00264 #ifdef RIO_DEBUG2
00265 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
00266 "Error destroying m_ReadWriteCond: %u (%s)", status,
00267 strerror( status ) );
00268 #endif
00269 }
00270
00271 status = pthread_cond_destroy( &m_ReadRioStarted );
00272 if( status < 0 )
00273 {
00274 #ifdef RIO_DEBUG2
00275 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
00276 "Error destroying m_ReadRioStarted: %u (%s)", status,
00277 strerror( status ) );
00278 #endif
00279 }
00280
00281 status = pthread_cond_destroy( &m_ReadApacheStarted );
00282 if( status < 0 )
00283 {
00284 #ifdef RIO_DEBUG2
00285 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
00286 "Error destroying m_ReadApacheStarted: %u (%s)", status,
00287 strerror( status ) );
00288 #endif
00289 }
00290
00291 status = pthread_cond_destroy( &m_ThreadBlocked );
00292 if( status < 0 )
00293 {
00294 #ifdef RIO_DEBUG2
00295 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
00296 "Error destroying m_ThreadBlocked: %u (%s)", status,
00297 strerror( status ) );
00298 #endif
00299 }
00300
00301 status = pthread_mutex_destroy( &m_Mutex );
00302 if( status < 0 )
00303 {
00304 #ifdef RIO_DEBUG2
00305 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
00306 "Error destroying m_Mutex: %u (%s)", status,
00307 strerror( status ) );
00308 #endif
00309 }
00310 }
00311
00312
00313
00314 bool CServerInterface::SendBlock( request_rec *Request, const char *Data,
00315 unsigned int DataSize )
00316 {
00317
00318 apr_bucket_brigade *DataBrigate;
00319
00320
00321 apr_bucket *FlushBucket;
00322
00323 apr_status_t ApacheStatus;
00324
00325
00326
00327
00328
00329
00330
00331 unsigned int NextFragment, TotalFragments, FragmentSize, SendDataSize;
00332
00333
00334 const char *PosNextFragment;
00335
00336
00337 FragmentSize = m_FragmentSize;
00338
00339 #ifdef RIO_DEBUG2
00340 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
00341 "Tentando escrever um bloco com %u bytes. Tamanho do "
00342 "fragmento e de %u bytes", DataSize, FragmentSize );
00343 #endif
00344
00345
00346 if( FragmentSize > DataSize )
00347 {
00348 #ifdef RIO_DEBUG2
00349 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
00350 "Warning: fragment size %u > datasize %u. "
00351 "Setting to data size", FragmentSize, DataSize );
00352 #endif
00353 FragmentSize = DataSize;
00354 }
00355 #ifdef RIO_DEBUG2
00356 if( ( DataSize % FragmentSize ) != 0 )
00357 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
00358 "Warning: data size %u is not multiple of fragment "
00359 "size %u. Last fragment will be smaller", DataSize,
00360 FragmentSize );
00361 #endif
00362
00363
00364 TotalFragments = ( DataSize + FragmentSize - 1 ) / FragmentSize;
00365 NextFragment = 0;
00366
00367 #ifdef RIO_DEBUG2
00368 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
00369 "Trying to send %u bytes: %u fragments of max size %u",
00370 DataSize, TotalFragments, FragmentSize );
00371 #endif
00372
00373 while( NextFragment < TotalFragments )
00374 {
00375
00376 if( NextFragment < ( TotalFragments - 1 ) )
00377 SendDataSize = FragmentSize;
00378 else
00379 SendDataSize = DataSize - ( ( TotalFragments - 1 ) *
00380 FragmentSize );
00381
00382 #ifdef RIO_DEBUG2
00383 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
00384 "Trying to send fragment %u/%u with %u bytes",
00385 NextFragment + 1, TotalFragments, SendDataSize );
00386 #endif
00387
00388
00389 DataBrigate = apr_brigade_create( Request->pool,
00390 Request->connection->bucket_alloc );
00391 if( DataBrigate == NULL )
00392 {
00393 #ifdef RIO_DEBUG2
00394 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
00395 "unable to create brigade" );
00396 #endif
00397
00398 m_ApacheStatus = HTTP_INTERNAL_SERVER_ERROR;
00399 return false;
00400 }
00401
00402
00403 PosNextFragment = &Data[ NextFragment * FragmentSize ];
00404 ApacheStatus = apr_brigade_write( DataBrigate, NULL, NULL,
00405 PosNextFragment, SendDataSize );
00406 if( ApacheStatus != APR_SUCCESS )
00407 {
00408 #ifdef RIO_DEBUG2
00409 ap_log_error( APLOG_MARK, APLOG_ERR, ApacheStatus, m_Server,
00410 "unable to write data in brigade" );
00411 #endif
00412
00413 m_ApacheStatus = ApacheStatus;
00414
00415
00416 ApacheStatus = apr_brigade_destroy( DataBrigate );
00417
00418 #ifdef RIO_DEBUG2
00419 if( ApacheStatus != APR_SUCCESS )
00420 {
00421 ap_log_error( APLOG_MARK, APLOG_ERR, ApacheStatus, m_Server,
00422 "warning: error when deleting brigate!" );
00423
00424 }
00425 #endif
00426
00427 return false;
00428 }
00429
00430
00431 FlushBucket = apr_bucket_flush_create(
00432 Request->connection->bucket_alloc );
00433 if( FlushBucket == NULL )
00434 {
00435 #ifdef RIO_DEBUG2
00436 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
00437 "unable to create flush bucket" );
00438 #endif
00439
00440 m_ApacheStatus = HTTP_INTERNAL_SERVER_ERROR;
00441
00442
00443 ApacheStatus = apr_brigade_destroy( DataBrigate );
00444
00445 #ifdef RIO_DEBUG2
00446 if( ApacheStatus != APR_SUCCESS )
00447 {
00448 ap_log_error( APLOG_MARK, APLOG_ERR, ApacheStatus, m_Server,
00449 "warning: error when deleting brigate!" );
00450
00451 }
00452 #endif
00453
00454 return false;
00455 }
00456
00457
00458 APR_BRIGADE_INSERT_TAIL( DataBrigate, FlushBucket );
00459
00460
00461 ApacheStatus = ap_pass_brigade( Request->output_filters, DataBrigate );
00462 if( ApacheStatus != APR_SUCCESS )
00463 {
00464 #ifdef RIO_DEBUG2
00465 ap_log_error( APLOG_MARK, APLOG_ERR, ApacheStatus, m_Server,
00466 "unable to pass brigade to filters" );
00467 #endif
00468
00469 m_ApacheStatus = ApacheStatus;
00470
00471
00472 ApacheStatus = apr_brigade_destroy( DataBrigate );
00473
00474 #ifdef RIO_DEBUG2
00475 if( ApacheStatus != APR_SUCCESS )
00476 {
00477 ap_log_error( APLOG_MARK, APLOG_ERR, ApacheStatus, m_Server,
00478 "warning: error when deleting brigate!" );
00479
00480 }
00481 #endif
00482
00483 return false;
00484 }
00485
00486 ApacheStatus = ap_fflush( Request->output_filters, DataBrigate );
00487 if( ApacheStatus != APR_SUCCESS )
00488 {
00489 #ifdef RIO_DEBUG2
00490 ap_log_error( APLOG_MARK, APLOG_ERR, ApacheStatus, m_Server,
00491 "unable to execute fflush" );
00492 #endif
00493
00494 m_ApacheStatus = ApacheStatus;
00495
00496
00497 ApacheStatus = apr_brigade_destroy( DataBrigate );
00498
00499 #ifdef RIO_DEBUG2
00500 if( ApacheStatus != APR_SUCCESS )
00501 {
00502 ap_log_error( APLOG_MARK, APLOG_ERR, ApacheStatus, m_Server,
00503 "warning: error when deleting brigate!" );
00504
00505 }
00506 #endif
00507
00508 return false;
00509 }
00510
00511 ApacheStatus = apr_brigade_destroy( DataBrigate );
00512 if( ApacheStatus != APR_SUCCESS )
00513 {
00514 #ifdef RIO_DEBUG2
00515 ap_log_error( APLOG_MARK, APLOG_ERR, ApacheStatus, m_Server,
00516 "unable to destroy brigade" );
00517 #endif
00518
00519 m_ApacheStatus = ApacheStatus;
00520 return false;
00521 }
00522
00523
00524 NextFragment++;
00525 }
00526
00527 return true;
00528 }
00529
00530
00531
00532 bool CServerInterface::ReceiveBlock( request_rec *Request, char *Data,
00533 unsigned int *DataSize, bool *IsEOF )
00534 {
00535
00536 apr_bucket_brigade *DataBrigate;
00537
00538 apr_bucket *DataBucket;
00539
00540 apr_status_t ApacheStatus;
00541
00542 apr_size_t BucketDataSize;
00543
00544 const char *BucketData;
00545
00546 unsigned int TotalDataSize;
00547
00548
00549 TotalDataSize = *DataSize;
00550
00551
00552 *Data = 0;
00553 *DataSize = 0;
00554 *IsEOF = false;
00555
00556 while( ( !( *IsEOF ) ) && ( ( *DataSize < TotalDataSize ) ) )
00557 {
00558
00559 DataBrigate = apr_brigade_create( Request->pool,
00560 Request->connection->bucket_alloc );
00561 if( DataBrigate == NULL )
00562 {
00563 #ifdef RIO_DEBUG2
00564 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
00565 "unable to create brigade" );
00566 #endif
00567
00568 m_ApacheStatus = HTTP_INTERNAL_SERVER_ERROR;
00569 return false;
00570 }
00571
00572
00573 ApacheStatus = ap_get_brigade( Request->input_filters, DataBrigate,
00574 AP_MODE_READBYTES, APR_BLOCK_READ,
00575 TotalDataSize - ( *DataSize ) );
00576 if( ApacheStatus != APR_SUCCESS )
00577 {
00578 #ifdef RIO_DEBUG2
00579 ap_log_error( APLOG_MARK, APLOG_ERR, ApacheStatus, m_Server,
00580 "unable to read up to %u bytes from filters",
00581 TotalDataSize - ( *DataSize ) );
00582 #endif
00583
00584 m_ApacheStatus = ApacheStatus;
00585
00586
00587 ApacheStatus = apr_brigade_destroy( DataBrigate );
00588 #ifdef RIO_DEBUG2
00589 if( ApacheStatus != APR_SUCCESS )
00590 {
00591 ap_log_error( APLOG_MARK, APLOG_ERR, ApacheStatus, m_Server,
00592 "warning: error when deleting brigate!" );
00593 }
00594 #endif
00595
00596 return false;
00597 }
00598
00599
00600 while( !APR_BRIGADE_EMPTY( DataBrigate ) )
00601 {
00602 DataBucket = APR_BRIGADE_FIRST( DataBrigate );
00603 if( APR_BUCKET_IS_EOS( DataBucket ) )
00604 {
00605 #ifdef RIO_DEBUG2
00606 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
00607 "Chegamos ao final dos dados lidos pela conexao "
00608 "do Apache. Foram lidos %u bytes de no maxino "
00609 "%u bytes", *DataSize, TotalDataSize );
00610 #endif
00611
00612
00613 *IsEOF = true;
00614
00615
00616
00617 break;
00618 }
00619
00620
00621
00622 ApacheStatus = apr_bucket_read( DataBucket, &BucketData,
00623 &BucketDataSize,
00624 APR_NONBLOCK_READ );
00625 if( ApacheStatus != APR_SUCCESS )
00626 {
00627 #ifdef RIO_DEBUG2
00628 ap_log_error( APLOG_MARK, APLOG_ERR, ApacheStatus, m_Server,
00629 "error when reading data from a bucket" );
00630 #endif
00631
00632 m_ApacheStatus = ApacheStatus;
00633
00634
00635 ApacheStatus = apr_brigade_destroy( DataBrigate );
00636
00637 #ifdef RIO_DEBUG2
00638 if( ApacheStatus != APR_SUCCESS )
00639 {
00640 ap_log_error( APLOG_MARK, APLOG_ERR, ApacheStatus,
00641 m_Server, "warning: error when deleting "
00642 "brigate!" );
00643 }
00644 #endif
00645
00646 return false;
00647 }
00648
00649
00650 if( BucketDataSize > 0 )
00651 {
00652
00653
00654
00655
00656 if( ( *DataSize + BucketDataSize ) > TotalDataSize )
00657 {
00658 #ifdef RIO_DEBUG2
00659 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
00660 "error when reading data from a bucket. "
00661 "Actual data size %u plus %u is greather "
00662 "then %u!", *DataSize, BucketDataSize,
00663 TotalDataSize );
00664 #endif
00665
00666 m_ApacheStatus = HTTP_INTERNAL_SERVER_ERROR;
00667
00668
00669 ApacheStatus = apr_brigade_destroy( DataBrigate );
00670 #ifdef RIO_DEBUG2
00671 if( ApacheStatus != APR_SUCCESS )
00672 {
00673 ap_log_error( APLOG_MARK, APLOG_ERR, ApacheStatus,
00674 m_Server, "warning: error when "
00675 "deleting brigate!" );
00676 }
00677 #endif
00678
00679 return false;
00680 }
00681
00682
00683
00684 memcpy( &Data[ *DataSize ], BucketData, BucketDataSize );
00685
00686
00687
00688 *DataSize = *DataSize + BucketDataSize;
00689 }
00690
00691
00692 apr_bucket_delete( DataBucket );
00693 }
00694
00695
00696 *IsEOF = ( *IsEOF ) || ( ( *DataSize == 0 ) );
00697
00698
00699 ApacheStatus = apr_brigade_destroy( DataBrigate );
00700 if( ApacheStatus != APR_SUCCESS )
00701 {
00702 #ifdef RIO_DEBUG2
00703 ap_log_error( APLOG_MARK, APLOG_ERR, ApacheStatus, m_Server,
00704 "unable to destroy brigade" );
00705 #endif
00706
00707 m_ApacheStatus = ApacheStatus;
00708 return false;
00709 }
00710 }
00711
00712 return true;
00713 }
00714
00715
00716 bool CServerInterface::TerminateCopyToClient( request_rec *Request )
00717 {
00718 apr_bucket_brigade *bb;
00719 apr_bucket *b;
00720 apr_status_t rv;
00721
00722
00723
00724 bb = apr_brigade_create( Request->pool,
00725 Request->connection->bucket_alloc );
00726 if( bb == NULL )
00727 {
00728 #ifdef RIO_DEBUG2
00729 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
00730 "unable to create brigade" );
00731 #endif
00732
00733 m_ApacheStatus = HTTP_INTERNAL_SERVER_ERROR;
00734 return false;
00735 }
00736
00737
00738 b = apr_bucket_eos_create( Request->connection->bucket_alloc );
00739 if( b == NULL )
00740 {
00741 #ifdef RIO_DEBUG2
00742 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
00743 "unable to create EOS bucket" );
00744 #endif
00745
00746 m_ApacheStatus = HTTP_INTERNAL_SERVER_ERROR;
00747 return false;
00748 }
00749
00750
00751 APR_BRIGADE_INSERT_TAIL( bb, b );
00752
00753
00754 rv = ap_pass_brigade( Request->output_filters, bb );
00755 if( rv != APR_SUCCESS )
00756 {
00757 #ifdef RIO_DEBUG2
00758 ap_log_error( APLOG_MARK, APLOG_ERR, rv, m_Server,
00759 "unable to pass brigade to filters" );
00760 #endif
00761
00762 m_ApacheStatus = rv;
00763 return false;
00764 }
00765
00766 rv = ap_fflush( Request->output_filters, bb );
00767 if( rv != APR_SUCCESS )
00768 {
00769 #ifdef RIO_DEBUG2
00770 ap_log_error( APLOG_MARK, APLOG_ERR, rv, m_Server,
00771 "unable to execute fflush" );
00772 #endif
00773
00774 m_ApacheStatus = rv;
00775 return false;
00776 }
00777 else
00778 return true;
00779 }
00780
00781
00782 bool CServerInterface::OpenRioSession( const char *ServerName,
00783 const char *UserName,
00784 const char *UserPassword )
00785 {
00786 RioResult hResult;
00787 char *EncryptedPassword;
00788
00789
00790 if( m_isSessionOpen )
00791 {
00792 m_RioStatus = ERROR_RIOSESSION + ERROR_SESSION_ALREADY_OPENED;
00793
00794 #ifdef RIO_DEBUG2
00795 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
00796 "Error opening RIO session (1): %u (%s)", m_RioStatus,
00797 GetErrorDescription( m_RioStatus ).c_str()
00798 );
00799 #endif
00800
00801 return false;
00802 }
00803
00804
00805 EncryptedPassword = encryptPassword( UserPassword );
00806 if( EncryptedPassword == NULL )
00807 {
00808 m_SystemStatus = ENOMEM;
00809
00810 #ifdef RIO_DEBUG2
00811 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
00812 "Error encrypting user password: %u (%s)", m_SystemStatus,
00813 strerror( m_SystemStatus ) );
00814 #endif
00815
00816 return false;
00817 }
00818
00819
00820 m_Session = new CRioSession;
00821 if( m_Session == NULL )
00822 {
00823 m_RioStatus = ERROR_RIOSESSION + ERROR_MEMORY;
00824
00825 #ifdef RIO_DEBUG2
00826 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
00827 "Error creating RIO session: %u (%s)", m_RioStatus,
00828 GetErrorDescription( m_RioStatus ).c_str() );
00829 #endif
00830
00831
00832 delete[] EncryptedPassword;
00833
00834 return false;
00835 }
00836
00837
00838
00839 hResult = m_Session->Connect( ServerName, UserName, EncryptedPassword, 1 );
00840 if( FAILED( hResult ) )
00841 {
00842 m_RioStatus = hResult;
00843
00844 #ifdef RIO_DEBUG2
00845 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
00846 "Error opening RIO session (2): %u (%s)", hResult,
00847 GetErrorDescription( hResult ).c_str() );
00848 #endif
00849
00850
00851 delete[] EncryptedPassword;
00852
00853
00854 delete m_Session;
00855 m_Session = NULL;
00856
00857 return false;
00858 }
00859
00860
00861 delete[] EncryptedPassword;
00862
00863 m_isSessionOpen = true;
00864
00865 return true;
00866 }
00867
00868
00869 bool CServerInterface::CloseRioSession()
00870 {
00871 RioResult hResult;
00872
00873
00874 if( ( m_Session == NULL ) || ( !m_isSessionOpen ) )
00875 {
00876 if( m_Session == NULL )
00877 m_RioStatus = ERROR_RIOSESSION + ERROR_NOT_INITIALIZED;
00878 else
00879 m_RioStatus = ERROR_RIOSESSION + ERROR_SESSION_NOT_OPENED;
00880
00881 #ifdef RIO_DEBUG2
00882 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
00883 "Error closing RIO session (1): %u (%s)", m_RioStatus,
00884 GetErrorDescription( m_RioStatus ).c_str() );
00885 #endif
00886
00887 return false;
00888 }
00889
00890
00891 hResult = m_Session->Disconnect();
00892 if( FAILED( hResult ) )
00893 {
00894 m_RioStatus = hResult;
00895
00896 #ifdef RIO_DEBUG2
00897 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
00898 "Error closing RIO session (2): %u (%s)", m_RioStatus,
00899 GetErrorDescription( m_RioStatus ).c_str() );
00900 #endif
00901
00902 return false;
00903 }
00904
00905
00906 delete m_Session;
00907 m_Session = NULL;
00908
00909 m_isSessionOpen = false;
00910
00911 return true;
00912 }
00913
00914
00915 bool CServerInterface::OpenRioStream( RioStreamDirection Direction )
00916
00917 {
00918
00919 RioStreamTraffic Traffic;
00920
00921 RioResult hResult;
00922
00923
00924 static const int MaxRequests = 20;
00925
00926
00927 if( m_isStreamOpen )
00928 {
00929 m_RioStatus = ERROR_RIOSTREAM + ERROR_STREAM_ALREADY_OPENED;
00930
00931 #ifdef RIO_DEBUG2
00932 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
00933 "Error opening RIO stream (1): %u (%s)",
00934 m_RioStatus, GetErrorDescription( m_RioStatus ).c_str()
00935 );
00936 #endif
00937
00938 return false;
00939 }
00940
00941
00942 if( ( m_Session == NULL ) || ( !m_isSessionOpen ) )
00943 {
00944 if( m_Session == NULL )
00945 m_RioStatus = ERROR_RIOSTREAM + ERROR_NOT_INITIALIZED;
00946 else
00947 m_RioStatus = ERROR_RIOSTREAM + ERROR_SESSION_NOT_OPENED;
00948
00949 #ifdef RIO_DEBUG2
00950 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
00951 "Erro opening RIO stream (2): %u (%s)", m_RioStatus,
00952 GetErrorDescription( m_RioStatus ).c_str() );
00953 #endif
00954
00955 return false;
00956 }
00957
00958
00959 m_Stream = new CRioStream();
00960 if( m_Stream == NULL )
00961 {
00962 m_RioStatus = ERROR_RIOSTREAM + ERROR_MEMORY;
00963
00964 #ifdef RIO_DEBUG2
00965 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
00966 "Error creating RIO stream: %u (%s)", m_RioStatus,
00967 GetErrorDescription( m_RioStatus ).c_str()
00968 );
00969 #endif
00970
00971 return false;
00972 }
00973
00974
00975 Traffic.Type = RIO_TRAFFIC_NRT;
00976 Traffic.TrafficNRT.Reserved = 0;
00977 Traffic.MaxRequests = MaxRequests;
00978 Traffic.Direction = Direction;
00979 Traffic.LogicalBlockSize = m_BlockSize;
00980
00981
00982 hResult = m_Stream->Open( &Traffic, m_Session );
00983 if( FAILED( hResult ) )
00984 {
00985 m_RioStatus = hResult;
00986
00987 #ifdef RIO_DEBUG2
00988 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
00989 "Error opening RIO stream (3): %u (%s)",
00990 m_RioStatus, GetErrorDescription( m_RioStatus ).c_str()
00991 );
00992 #endif
00993
00994 return false;
00995 }
00996
00997 m_isStreamOpen = true;
00998
00999 return true;
01000 }
01001
01002 bool CServerInterface::CloseRioStream()
01003 {
01004
01005 RioResult hResult;
01006
01007 bool Status;
01008
01009
01010 if( ( m_Stream == NULL ) || ( !m_isStreamOpen ) )
01011 {
01012 if( m_Stream == NULL )
01013 m_RioStatus = ERROR_RIOSTREAM + ERROR_NOT_INITIALIZED;
01014 else
01015 m_RioStatus = ERROR_RIOSTREAM + ERROR_STREAM_NOT_OPENED;
01016
01017 #ifdef RIO_DEBUG2
01018 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
01019 "Error closing RIO stream (1): %u (%s)",
01020 m_RioStatus, GetErrorDescription( m_RioStatus ).c_str()
01021 );
01022 #endif
01023
01024 return false;
01025 }
01026
01027
01028 hResult = m_Stream->Close();
01029 if( FAILED( hResult ) )
01030 {
01031 m_RioStatus = hResult;
01032
01033 #ifdef RIO_DEBUG2
01034 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
01035 "Error closing RIO stream (2): %u (%s)",
01036 m_RioStatus, GetErrorDescription( m_RioStatus ).c_str()
01037 );
01038 #endif
01039
01040 Status = false;
01041 }
01042 else
01043 Status = true;
01044
01045 m_isStreamOpen = false;
01046
01047
01048 delete m_Stream;
01049
01050 return Status;
01051 }
01052
01053
01054 bool CServerInterface::OpenRioObject( const char *FileName, RioAccess Access )
01055 {
01056
01057 RioResult hResult;
01058
01059
01060 if( m_isObjectOpen )
01061 {
01062 m_RioStatus = ERROR_RIOOBJECT + ERROR_OBJECT_ALREADY_OPENED;
01063
01064 #ifdef RIO_DEBUG2
01065 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
01066 "Error opening object (1): %u (%s)", m_RioStatus,
01067 GetErrorDescription( m_RioStatus ).c_str() );
01068 #endif
01069
01070 return false;
01071 }
01072
01073
01074 if( ( m_Session == NULL ) || ( !m_isSessionOpen ) )
01075 {
01076 if( m_Session == NULL )
01077 m_RioStatus = ERROR_RIOSTREAM + ERROR_NOT_INITIALIZED;
01078 else
01079 m_RioStatus = ERROR_RIOSTREAM + ERROR_SESSION_NOT_OPENED;
01080
01081 #ifdef RIO_DEBUG2
01082 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
01083 "Erro opening object (2): %u (%s)", m_RioStatus,
01084 GetErrorDescription( m_RioStatus ).c_str() );
01085 #endif
01086
01087 return false;
01088 }
01089
01090
01091 if( ( m_Stream == NULL ) || ( !m_isStreamOpen ) )
01092 {
01093 if( m_Stream == NULL )
01094 m_RioStatus = ERROR_RIOSTREAM + ERROR_NOT_INITIALIZED;
01095 else
01096 m_RioStatus = ERROR_RIOSTREAM + ERROR_STREAM_NOT_OPENED;
01097
01098 #ifdef RIO_DEBUG2
01099 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
01100 "Erro opening object (3): %u (%s)", m_RioStatus,
01101 GetErrorDescription( m_RioStatus ).c_str() );
01102 #endif
01103
01104 return false;
01105 }
01106
01107
01108 if( ( Access & RIO_WRITE_ACCESS ) )
01109 {
01110 hResult = m_Session->CreateObject( FileName, ObjectInfo::FILE_TYPE_DATA,
01111 NULL );
01112
01113 if( FAILED( hResult ) &&
01114 ( ( hResult & 0xff ) != ( unsigned ) ERROR_OBJECT_EXISTS ) )
01115 {
01116 m_RioStatus = hResult;
01117
01118 #ifdef RIO_DEBUG2
01119 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
01120 "Erro creating object: %u (%s)", m_RioStatus,
01121 GetErrorDescription( m_RioStatus ).c_str() );
01122 #endif
01123
01124 return false;
01125 }
01126 }
01127
01128
01129 m_Object = new CRioObject;
01130 if( m_Object == NULL )
01131 {
01132 m_RioStatus = ERROR_RIOOBJECT + ERROR_MEMORY;
01133
01134 #ifdef RIO_DEBUG2
01135 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
01136 "Error creating RIO object: %u (%s)", m_RioStatus,
01137 GetErrorDescription( m_RioStatus ).c_str()
01138 );
01139 #endif
01140
01141 return false;
01142 }
01143
01144
01145
01146 hResult = m_Object->Open( FileName, Access, m_Stream );
01147 if( FAILED( hResult ) )
01148 {
01149 m_RioStatus = hResult;
01150
01151 #ifdef RIO_DEBUG2
01152 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
01153 "Erro opening object (4): %u (%s)", m_RioStatus,
01154 GetErrorDescription( m_RioStatus ).c_str() );
01155 #endif
01156
01157 return false;
01158 }
01159 else
01160 {
01161 m_isObjectOpen = true;
01162
01163 return true;
01164 }
01165 }
01166
01167
01168 bool CServerInterface::CloseRioObject()
01169 {
01170
01171 RioResult hResult;
01172
01173
01174 if( ( m_Stream == NULL ) || ( !m_isStreamOpen ) )
01175 {
01176 if( m_Stream == NULL )
01177 m_RioStatus = ERROR_RIOSTREAM + ERROR_NOT_INITIALIZED;
01178 else
01179 m_RioStatus = ERROR_RIOSTREAM + ERROR_STREAM_NOT_OPENED;
01180
01181 #ifdef RIO_DEBUG2
01182 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
01183 "Error closing object (1): %u (%s)", m_RioStatus,
01184 GetErrorDescription( m_RioStatus ).c_str()
01185 );
01186 #endif
01187
01188 return false;
01189 }
01190
01191
01192 if( ( m_Object == NULL ) || ( !m_isObjectOpen ) )
01193 {
01194 if( m_Object == NULL )
01195 m_RioStatus = ERROR_RIOOBJECT + ERROR_NOT_INITIALIZED;
01196 else
01197 m_RioStatus = ERROR_RIOOBJECT + ERROR_OBJECT_NOT_OPENED;
01198
01199 #ifdef RIO_DEBUG2
01200 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
01201 "Error closing object (2): %u (%s)", m_RioStatus,
01202 GetErrorDescription( m_RioStatus ).c_str() );
01203 #endif
01204
01205 return false;
01206 }
01207
01208
01209 hResult = m_Object->Close();
01210 if( FAILED( hResult ) )
01211 {
01212 m_RioStatus = hResult;
01213
01214 #ifdef RIO_DEBUG2
01215 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
01216 "Error closing object (3): %u (%s)", m_RioStatus,
01217 GetErrorDescription( m_RioStatus ).c_str() );
01218 #endif
01219 }
01220
01221
01222 delete m_Object;
01223
01224 m_isObjectOpen = false;
01225
01226 return true;
01227 }
01228
01229
01230 bool CServerInterface::SendSignal()
01231 {
01232 int status;
01233
01234
01235 status = pthread_mutex_lock( &m_ReadWriteMutex );
01236 if( status != 0 )
01237 {
01238 m_SystemStatus = status;
01239
01240 #ifdef RIO_DEBUG2
01241 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
01242 "Error locking mutex m_ReadWriteMutex: %u (%s)",
01243 m_SystemStatus, strerror( m_SystemStatus ) );
01244 #endif
01245
01246 return false;
01247 }
01248
01249
01250
01251 status = pthread_cond_signal( &m_ReadWriteCond );
01252 if( status < 0 )
01253 {
01254 m_SystemStatus = status;
01255
01256 #ifdef RIO_DEBUG2
01257 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
01258 "Error sending signal: %u (%s)", m_SystemStatus,
01259 strerror( m_SystemStatus ) );
01260 #endif
01261
01262 return false;
01263 }
01264
01265
01266 status = pthread_mutex_unlock( &m_ReadWriteMutex );
01267 if( status != 0 )
01268 {
01269 m_SystemStatus = status;
01270
01271 #ifdef RIO_DEBUG2
01272 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
01273 "Error unlocking mutex m_ReadWriteMutex: %u (%s)",
01274 m_SystemStatus, strerror( m_SystemStatus ) );
01275 #endif
01276
01277 return false;
01278 }
01279
01280 return true;
01281 }
01282
01283
01284
01285 void CServerInterface::ReadCallBack( RioRequest *Request )
01286 {
01287 CServerInterface *Module = ( CServerInterface* ) Request->User;
01288
01289 #ifdef RIO_DEBUG2
01290 ap_log_error( APLOG_MARK, APLOG_ERR, 0, Module->GetServer(),
01291 "Block %u arrived. Sending signal!", Request->Block );
01292 #endif
01293
01294
01295 if( !Module->SendSignal() )
01296 ap_log_error( APLOG_MARK, APLOG_ERR, 0, Module->GetServer(),
01297 "Error when executing SendSignal" );
01298 }
01299
01300
01301 void CServerInterface::WriteCallBack( RioRequest *Request )
01302 {
01303 CServerInterface *Module = ( CServerInterface* ) Request->User;
01304
01305 #ifdef RIO_DEBUG2
01306 ap_log_error( APLOG_MARK, APLOG_ERR, 0, Module->GetServer(),
01307 "Block %u copied to server. Sending signal!",
01308 Request->Block );
01309 #endif
01310
01311
01312 if( !Module->SendSignal() )
01313 ap_log_error( APLOG_MARK, APLOG_ERR, 0, Module->GetServer(),
01314 "Error when executing SendSignal" );
01315 }
01316
01317
01318 bool CServerInterface::ReadRioObjectBlock( RioBlock Block )
01319 {
01320 RioResult hResult;
01321 RioRequest Request;
01322 int status;
01323
01324 bool CopyBlock;
01325
01326 #ifdef RIO_DEBUG2
01327 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
01328 "Trying reading block %u", Block );
01329 #endif
01330
01331
01332 unsigned int numberofretrys = 0;
01333
01334
01335 if( ( m_Object == NULL ) || ( !m_isObjectOpen ) )
01336 {
01337 if( m_Object == NULL )
01338 m_RioStatus = ERROR_RIOOBJECT + ERROR_NOT_INITIALIZED;
01339 else
01340 m_RioStatus = ERROR_RIOOBJECT + ERROR_OBJECT_NOT_OPENED;
01341
01342 #ifdef RIO_DEBUG2
01343 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
01344 "Object not opened: %u (%s)", m_RioStatus,
01345 GetErrorDescription( m_RioStatus ).c_str() );
01346 #endif
01347
01348 return false;
01349 }
01350
01351
01352 Request.Size = m_BlockSize;
01353 Request.Buffer = m_RioBuffer;
01354 Request.CallBackFunction = ReadCallBack;
01355 Request.User = (void *) this;
01356 Request.Block = Block;
01357 Request.Result = S_OK;
01358 Request.Status = RIO_REQUEST_FREE;
01359
01360 CopyBlock = true;
01361 while( CopyBlock )
01362 {
01363
01364
01365 status = pthread_mutex_lock( &m_ReadWriteMutex );
01366 if( status != 0 )
01367 {
01368 m_SystemStatus = status;
01369
01370 #ifdef RIO_DEBUG2
01371 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
01372 "Error reading block %u (1.1): %u (%s)",
01373 Block, m_SystemStatus, strerror( m_SystemStatus ) );
01374 #endif
01375
01376 return false;
01377 }
01378
01379
01380 hResult = m_Object->StreamRead( &Request );
01381
01382 if( FAILED( hResult ) )
01383 {
01384 m_RioStatus = hResult;
01385
01386 #ifdef RIO_DEBUG2
01387 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
01388 "Error reading block %u (1.2): %u (%s)",
01389 Block, m_RioStatus,
01390 GetErrorDescription( m_RioStatus ).c_str() );
01391 #endif
01392
01393 return false;
01394 }
01395
01396 status = pthread_cond_wait( &m_ReadWriteCond, &m_ReadWriteMutex );
01397 if( status != 0 )
01398 {
01399 m_SystemStatus = status;
01400
01401 #ifdef RIO_DEBUG2
01402 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
01403 "Error reading block %u (1.3): %u (%s)",
01404 Block, m_SystemStatus, strerror( m_SystemStatus ) );
01405 #endif
01406 status = pthread_mutex_unlock( &m_ReadWriteMutex );
01407 if( status != 0 )
01408 {
01409 m_SystemStatus = status;
01410
01411 #ifdef RIO_DEBUG2
01412 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
01413 "Error unlocking mutex: %u (%s)", status,
01414 strerror( status ) );
01415 #endif
01416 }
01417
01418 return false;
01419 }
01420
01421 status = pthread_mutex_unlock( &m_ReadWriteMutex );
01422 if( status != 0 )
01423 {
01424 m_SystemStatus = status;
01425
01426 #ifdef RIO_DEBUG2
01427 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
01428 "Error reading block %u (1.4): %u (%s)",
01429 Block, m_SystemStatus, strerror( m_SystemStatus ) );
01430 #endif
01431
01432 return false;
01433 }
01434
01435
01436 if( Request.Result == S_OK )
01437 {
01438 CopyBlock = false;
01439 }
01440 else if( ( Request.Result & 0xFF ) ==
01441 ERROR_SERVICE_TEMPORARY_UNAVAILABLE )
01442 {
01443
01444
01445
01446
01447
01448
01449 numberofretrys++;
01450
01451 if( numberofretrys >= MAXNUMBEROFBLOCKRETRYS )
01452 {
01453 m_RioStatus = ERROR_RIOOBJECT +
01454 ERROR_SERVICE_TEMPORARY_UNAVAILABLE;
01455
01456 #ifdef RIO_DEBUG2
01457 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
01458 "Error reading block %u (1.5): %u (%s)",
01459 Block, m_RioStatus,
01460 GetErrorDescription( m_RioStatus ).c_str() );
01461 #endif
01462
01463 return false;
01464 }
01465 }
01466 else
01467 {
01468 m_RioStatus = Request.Result;
01469
01470 #ifdef RIO_DEBUG2
01471 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
01472 "Error reading block %u (1.6): %u (%s)",
01473 Block, m_RioStatus,
01474 GetErrorDescription( m_RioStatus ).c_str() );
01475 #endif
01476
01477 return false;
01478 }
01479 }
01480
01481 return true;
01482 }
01483
01484
01485
01486 bool CServerInterface::WriteRioObjectBlock( RioBlock Block, char *Md5Sum,
01487 RioObjectSize UsedBlockSize,
01488 RioObjectSize *ActualFileSize )
01489 {
01490
01491 RioResult hResult;
01492 RioRequest Request;
01493 int status;
01494
01495 bool CopyBlock;
01496
01497 #ifdef RIO_DEBUG2
01498 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
01499 "Trying writing block %u", Block );
01500 #endif
01501
01502
01503 unsigned int numberofretrys = 0;
01504
01505
01506 if( ( m_Object == NULL ) || ( !m_isObjectOpen ) )
01507 {
01508 if( m_Object == NULL )
01509 m_RioStatus = ERROR_RIOOBJECT + ERROR_NOT_INITIALIZED;
01510 else
01511 m_RioStatus = ERROR_RIOOBJECT + ERROR_OBJECT_NOT_OPENED;
01512
01513 #ifdef RIO_DEBUG2
01514 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
01515 "Object not opened: %u (%s)", m_RioStatus,
01516 GetErrorDescription( m_RioStatus ).c_str() );
01517 #endif
01518
01519 return false;
01520 }
01521
01522
01523 Request.Size = m_BlockSize;
01524 Request.Buffer = m_RioBuffer;
01525 Request.CallBackFunction = WriteCallBack;
01526 Request.User = (void *) this;
01527 Request.Block = Block;
01528 Request.Result = S_OK;
01529 Request.Status = RIO_REQUEST_FREE;
01530
01531
01532
01533 hResult = m_Object->SetSize( *ActualFileSize + UsedBlockSize, Md5Sum );
01534 if( FAILED( hResult ) )
01535 {
01536 if( ( hResult & 0xff ) == (signed) ERROR_DISKFULL )
01537 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
01538 "Nao conseguiu alocar blocos para objeto: Disco(s) "
01539 "cheio(s)." );
01540 else
01541 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
01542 "Nao conseguiu alocar blocos para objeto: erro = %u "
01543 "(%8X - %s).", ( unsigned int ) ( hResult & 0xff ),
01544 hResult, GetErrorDescription( hResult ).c_str() );
01545 return false;
01546 }
01547
01548
01549 *ActualFileSize = *ActualFileSize + UsedBlockSize;
01550
01551
01552 CopyBlock = true;
01553 while( CopyBlock )
01554 {
01555
01556
01557 status = pthread_mutex_lock( &m_ReadWriteMutex );
01558 if( status != 0 )
01559 {
01560 m_SystemStatus = status;
01561
01562 #ifdef RIO_DEBUG2
01563 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
01564 "Error writing block %u (1.1): %u (%s)",
01565 Block, m_SystemStatus, strerror( m_SystemStatus ) );
01566 #endif
01567
01568 return false;
01569 }
01570
01571
01572 hResult = m_Object->StreamWrite( &Request );
01573
01574 if( FAILED( hResult ) )
01575 {
01576 m_RioStatus = hResult;
01577
01578 #ifdef RIO_DEBUG2
01579 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
01580 "Error writing block %u (1.2): %u (%s)",
01581 Block, m_RioStatus,
01582 GetErrorDescription( m_RioStatus ).c_str() );
01583 #endif
01584
01585 return false;
01586 }
01587
01588 status = pthread_cond_wait( &m_ReadWriteCond, &m_ReadWriteMutex );
01589 if( status != 0 )
01590 {
01591 m_SystemStatus = status;
01592
01593 #ifdef RIO_DEBUG2
01594 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
01595 "Error writing block %u (1.3): %u (%s)",
01596 Block, m_SystemStatus, strerror( m_SystemStatus ) );
01597 #endif
01598 status = pthread_mutex_unlock( &m_ReadWriteMutex );
01599 if( status != 0 )
01600 {
01601 m_SystemStatus = status;
01602
01603 #ifdef RIO_DEBUG2
01604 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
01605 "Error unlocking mutex: %u (%s)", status,
01606 strerror( status ) );
01607 #endif
01608 }
01609
01610 return false;
01611 }
01612
01613 status = pthread_mutex_unlock( &m_ReadWriteMutex );
01614 if( status != 0 )
01615 {
01616 m_SystemStatus = status;
01617
01618 #ifdef RIO_DEBUG2
01619 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
01620 "Error reading block %u (1.4): %u (%s)",
01621 Block, m_SystemStatus, strerror( m_SystemStatus ) );
01622 #endif
01623
01624 return false;
01625 }
01626
01627
01628 if( Request.Result == S_OK )
01629 {
01630
01631
01632 CopyBlock = false;
01633 }
01634 else if( ( ( Request.Result & 0xFF ) ==
01635 ERROR_SERVICE_TEMPORARY_UNAVAILABLE ) ||
01636 ( ( Request.Result & 0xFF ) == ERROR_INVALID_DISK ) )
01637 {
01638
01639
01640
01641
01642
01643
01644
01645
01646
01647 numberofretrys++;
01648 if( numberofretrys >= MAXNUMBEROFBLOCKRETRYS )
01649 {
01650 m_RioStatus = ERROR_RIOOBJECT +
01651 ERROR_SERVICE_TEMPORARY_UNAVAILABLE;
01652
01653 #ifdef RIO_DEBUG2
01654 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
01655 "Error writing block %u (1.5): %u (%s)",
01656 Block, m_RioStatus,
01657 GetErrorDescription( m_RioStatus ).c_str() );
01658 #endif
01659
01660 return false;
01661 }
01662
01663
01664 hResult = m_Object->ReallocBlocks( Block );
01665 if( FAILED( hResult ) )
01666 {
01667 m_RioStatus = hResult;
01668
01669 #ifdef RIO_DEBUG2
01670 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
01671 "Write failed to realocate fisical blocs of the "
01672 "logical block %u: %8X (%s)", Block, m_RioStatus,
01673 GetErrorDescription( m_RioStatus ).c_str() );
01674 #endif
01675
01676 return false;
01677 }
01678 #ifdef RIO_DEBUG2
01679 else
01680 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
01681 "CServerInterface::WriteRioObjectBlock blocos "
01682 "fisicos do bloco logico %u realocados com "
01683 "sucesso", Block );
01684 #endif
01685 }
01686 else
01687 {
01688 m_RioStatus = Request.Result;
01689
01690 #ifdef RIO_DEBUG2
01691 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
01692 "Error writing block %u (1.6): %u (%s)",
01693 Block, m_RioStatus,
01694 GetErrorDescription( m_RioStatus ).c_str() );
01695 #endif
01696
01697 return false;
01698 }
01699 }
01700
01701 return true;
01702 }
01703
01704
01705
01706
01707 void *CServerInterface::ReadRioThreadFunctionEp( void *Class )
01708 {
01709 CServerInterface *Module;
01710
01711
01712 Module = ( CServerInterface * ) Class;
01713
01714
01715 Module->ReadRioThreadFunction();
01716
01717
01718 return NULL;
01719
01720 }
01721
01722
01723 void CServerInterface::ReadRioThreadFunction()
01724 {
01725 RioBlock Block;
01726 bool NoError;
01727 int status;
01728
01729 #ifdef RIO_DEBUG2
01730 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
01731 "READRIOTHREADID %lu", syscall( SYS_gettid ) );
01732 #endif
01733
01734
01735
01736 while( 1 )
01737 {
01738
01739 if( m_ThreadCanceled )
01740 return;
01741
01742
01743 status = pthread_mutex_lock( &m_Mutex );
01744 if( status < 0 )
01745 {
01746 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
01747 "error locking mutex m_Mutex" );
01748 }
01749
01750
01751 status = pthread_cond_signal( &m_ThreadBlocked );
01752 if( status < 0 )
01753 {
01754 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
01755 "error signalling condition variable "
01756 "m_ThreadBlocked" );
01757 }
01758
01759
01760
01761
01762 if( !m_isReadingRioFile )
01763 {
01764 status = pthread_cond_wait( &m_ReadRioStarted, &m_Mutex );
01765
01766 if( status < 0 )
01767 {
01768 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
01769 "error waiting in condition variable "
01770 "m_ReadRioStarted" );
01771 }
01772
01773 }
01774
01775 while( ( m_isReadingRioFile ) && ( !m_ThreadCanceled ) )
01776 {
01777
01778 Block = m_RioBlock;
01779
01780
01781
01782 status = pthread_mutex_unlock( &m_Mutex );
01783 if( status < 0 )
01784 {
01785 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
01786 "error unlocking mutex m_Mutex" );
01787 }
01788
01789
01790 NoError = ReadRioObjectBlock( Block );
01791
01792 if( !NoError )
01793 {
01794 #ifdef RIO_DEBUG2
01795 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
01796 "error executing ReadRioObjectBlock" );
01797 #endif
01798 }
01799 else
01800 {
01801 #ifdef RIO_DEBUG2
01802 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
01803 "Trying to insert block %u in CircularBuffer!",
01804 Block );
01805 #endif
01806
01807
01808 NoError = m_CircularBuffer->SetElement( m_RioBuffer );
01809 if( !NoError )
01810 {
01811 m_SystemStatus = m_CircularBuffer->GetError();
01812
01813 #ifdef RIO_DEBUG2
01814 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
01815 "Error copying block %u to circular "
01816 "buffer: %u (%s)", Block, m_SystemStatus,
01817 strerror( m_SystemStatus ) );
01818 #endif
01819
01820 }
01821 }
01822
01823
01824
01825 status = pthread_mutex_lock( &m_Mutex );
01826 if( status < 0 )
01827 {
01828 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
01829 "error locking mutex m_Mutex" );
01830 }
01831
01832
01833
01834 m_RioBlock++;
01835
01836
01837 if( ( m_RioBlock >= m_TotalBlocks ) || ( !NoError ) )
01838 {
01839
01840
01841 m_isReadingRioFile = false;
01842
01843
01844
01845 if( !NoError )
01846 m_CircularBuffer->CancelGetElement();
01847
01848 }
01849 }
01850
01851 status = pthread_mutex_unlock( &m_Mutex );
01852 if( status < 0 )
01853 {
01854 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
01855 "error unlocking mutex m_Mutex" );
01856 }
01857 }
01858 }
01859
01860
01861
01862
01863 void *CServerInterface::ReadApacheThreadFunctionEp( void *Class )
01864 {
01865 CServerInterface *Module;
01866
01867
01868 Module = ( CServerInterface * ) Class;
01869
01870
01871 Module->ReadApacheThreadFunction();
01872
01873
01874 return NULL;
01875
01876 }
01877
01878
01879 void CServerInterface::ReadApacheThreadFunction()
01880 {
01881 bool NoError;
01882 bool IsApacheEof;
01883 int status;
01884 unsigned int DataSize;
01885 #ifdef RIO_DEBUG2
01886 RioBlock Block;
01887 #endif
01888
01889 #ifdef RIO_DEBUG2
01890 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
01891 "READAPACHETHREADID %lu", syscall( SYS_gettid ) );
01892 #endif
01893
01894
01895
01896 while( 1 )
01897 {
01898
01899 status = pthread_mutex_lock( &m_Mutex );
01900 if( status < 0 )
01901 {
01902 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
01903 "error locking mutex m_Mutex" );
01904 }
01905
01906
01907 if( m_ThreadCanceled )
01908 {
01909
01910
01911 status = pthread_mutex_unlock( &m_Mutex );
01912 if( status < 0 )
01913 {
01914 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
01915 "error unlocking mutex m_Mutex" );
01916 }
01917
01918 #ifdef RIO_DEBUG2
01919 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
01920 "Finalizando a thread ReadApacheThreadFunction!" );
01921 #endif
01922
01923 return;
01924 }
01925
01926
01927
01928 status = pthread_cond_signal( &m_ThreadBlocked );
01929 if( status < 0 )
01930 {
01931 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
01932 "error signalling condition variable "
01933 "m_ThreadBlocked" );
01934 }
01935
01936
01937
01938
01939 if( !m_isReadingApacheFile )
01940 {
01941 status = pthread_cond_wait( &m_ReadApacheStarted, &m_Mutex );
01942
01943 if( status < 0 )
01944 {
01945 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
01946 "error waiting in condition variable "
01947 "m_ReadApacheStarted" );
01948 }
01949
01950 }
01951
01952 #ifdef RIO_DEBUG2
01953
01954 Block = 0;
01955 #endif
01956
01957 while( ( m_isReadingApacheFile ) && ( !m_ThreadCanceled ) )
01958 {
01959
01960
01961 status = pthread_mutex_unlock( &m_Mutex );
01962 if( status < 0 )
01963 {
01964 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
01965 "error unlocking mutex m_Mutex" );
01966 }
01967
01968
01969 DataSize = m_BlockSize;
01970
01971
01972 NoError = ReceiveBlock( m_UploadRequest, m_ApacheBuffer,
01973 &DataSize, &IsApacheEof );
01974
01975
01976
01977
01978 if( ( !IsApacheEof ) && ( DataSize != m_BlockSize ) )
01979 {
01980 #ifdef RIO_DEBUG2
01981 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
01982 "Error receiving block %u! Size of received "
01983 "block is %u, but must be the maximum size "
01984 "%u because an EOF has not detected!",
01985 Block, DataSize, m_BlockSize );
01986 #endif
01987 NoError = false;
01988
01989 }
01990
01991
01992
01993 status = pthread_mutex_lock( &m_Mutex );
01994 if( status < 0 )
01995 {
01996 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
01997 "error locking mutex m_Mutex" );
01998 }
01999
02000
02001
02002 m_IsApacheEof = IsApacheEof;
02003
02004 if( !NoError )
02005 {
02006 #ifdef RIO_DEBUG2
02007 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
02008 "error executing ReadRioObjectBlock" );
02009 #endif
02010 }
02011 else if( ( !IsApacheEof ) || ( DataSize != 0 ) )
02012 {
02013 m_LastApacheBlockSize = DataSize;
02014
02015
02016
02017 status = pthread_mutex_unlock( &m_Mutex );
02018 if( status < 0 )
02019 {
02020 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
02021 "error unlocking mutex m_Mutex" );
02022 }
02023
02024 #ifdef RIO_DEBUG2
02025 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
02026 "Trying to insert apache block %u in "
02027 "CircularBuffer with %u bytes, eof = %s!",
02028 Block, DataSize,
02029 ( ( IsApacheEof ) ? "true": "false" ) );
02030 #endif
02031
02032
02033 NoError = m_CircularBuffer->SetElement( m_ApacheBuffer );
02034 if( !NoError )
02035 {
02036 m_SystemStatus = m_CircularBuffer->GetError();
02037
02038 #ifdef RIO_DEBUG2
02039 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
02040 "Error copying apache block to circular "
02041 "buffer: %u (%s)", m_SystemStatus,
02042 strerror( m_SystemStatus ) );
02043 #endif
02044
02045 }
02046
02047
02048
02049 status = pthread_mutex_lock( &m_Mutex );
02050 if( status < 0 )
02051 {
02052 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
02053 "error locking mutex m_Mutex" );
02054 }
02055
02056 }
02057
02058
02059
02060 if( ( m_IsApacheEof ) || ( !NoError ) )
02061 {
02062 #ifdef RIO_DEBUG2
02063 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
02064 "Fim da recepcao! Desbloqueando a outra thread "
02065 ", se isso for necessario!" );
02066 #endif
02067
02068
02069 m_isReadingApacheFile = false;
02070
02071
02072
02073
02074
02075 m_CircularBuffer->CancelGetElement();
02076 }
02077
02078 #ifdef RIO_DEBUG2
02079
02080
02081 Block++;
02082 #endif
02083 }
02084
02085
02086 status = pthread_mutex_unlock( &m_Mutex );
02087 if( status < 0 )
02088 {
02089 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
02090 "error unlocking mutex m_Mutex" );
02091 }
02092 }
02093 }
02094
02095
02096
02097
02098 bool CServerInterface::Connect( request_rec *Request, const char *UserName,
02099 const char *UserPassword )
02100 {
02101
02102 RioResult hResult;
02103
02104 int error;
02105
02106
02107
02108
02109
02110 if( !OpenRioSession( m_ServerName, UserName, UserPassword ) )
02111 {
02112 #ifdef RIO_DEBUG2
02113 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
02114 "Error creating RioSession: %u (%s)",
02115 m_RioStatus,
02116 GetErrorDescription( m_RioStatus ).c_str() );
02117 #endif
02118 return false;
02119 }
02120
02121
02122 hResult = m_Session->GetBlockSize( &m_BlockSize );
02123 if( FAILED( hResult ) )
02124 {
02125 m_RioStatus = hResult;
02126
02127 #ifdef RIO_DEBUG2
02128 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
02129 "Error getting block size: %u (%s)", m_RioStatus,
02130 GetErrorDescription( m_RioStatus ).c_str() );
02131 #endif
02132
02133 return false;
02134 }
02135
02136
02137
02138 try
02139 {
02140 m_RioBuffer = new char[ m_BlockSize ];
02141 }
02142 catch( bad_alloc &ba )
02143 {
02144 m_SystemStatus = ENOMEM;
02145
02146 #ifdef RIO_DEBUG2
02147 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
02148 "Erro allocating (bad_alloc, error=%s) m_RioBuffer: %u "
02149 "(%s)", ba.what(), m_SystemStatus,
02150 strerror( m_SystemStatus ) );
02151 #endif
02152
02153 if( !CloseRioSession() )
02154 {
02155 #ifdef RIO_DEBUG2
02156 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
02157 "Error closing RioSession: %u (%s)", m_RioStatus,
02158 GetErrorDescription( m_RioStatus ).c_str() );
02159 #endif
02160 }
02161
02162 return false;
02163 }
02164
02165
02166
02167 try
02168 {
02169 m_ApacheBuffer = new char[ m_BlockSize ];
02170 }
02171 catch( bad_alloc &ba )
02172 {
02173 m_SystemStatus = ENOMEM;
02174
02175 #ifdef RIO_DEBUG2
02176 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
02177 "Erro allocating (bad_alloc, error=%s) block buffer: "
02178 "%u (%s)", ba.what(), m_SystemStatus,
02179 strerror( m_SystemStatus ) );
02180 #endif
02181
02182
02183 delete[] m_RioBuffer;
02184 m_RioBuffer = NULL;
02185
02186 if( !CloseRioSession() )
02187 {
02188 #ifdef RIO_DEBUG2
02189 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
02190 "Error closing RioSession: %u (%s)", m_RioStatus,
02191 GetErrorDescription( m_RioStatus ).c_str() );
02192 #endif
02193 }
02194
02195 return false;
02196 }
02197
02198
02199
02200 try
02201 {
02202 m_CircularBuffer = new CircularBuffer( m_Server, m_CircularBufferSize,
02203 m_BlockSize );
02204 }
02205 catch( bad_alloc &ba )
02206 {
02207 m_SystemStatus = ENOMEM;
02208
02209 #ifdef RIO_DEBUG2
02210 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
02211 "Erro allocating circular buffer (bad_alloc, error=%s): "
02212 "%u (%s)", ba.what(), m_SystemStatus,
02213 strerror( m_SystemStatus ) );
02214 #endif
02215
02216 if( !CloseRioSession() )
02217 {
02218 #ifdef RIO_DEBUG2
02219 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
02220 "Error closing RioSession: %u (%s)", m_RioStatus,
02221 GetErrorDescription( m_RioStatus ).c_str() );
02222 #endif
02223 }
02224
02225
02226 delete[] m_RioBuffer;
02227 m_RioBuffer = NULL;
02228 delete[] m_ApacheBuffer;
02229 m_ApacheBuffer = NULL;
02230
02231
02232 delete m_CircularBuffer;
02233 m_CircularBuffer = NULL;
02234
02235 return false;
02236 }
02237
02238
02239 error = m_CircularBuffer->GetError();
02240 if( error != 0 )
02241 {
02242 m_SystemStatus = error;
02243
02244 #ifdef RIO_DEBUG2
02245 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
02246 "Erro allocating circular buffer: %u (%s)",
02247 m_SystemStatus, strerror( m_SystemStatus ) );
02248 #endif
02249
02250 if( !CloseRioSession() )
02251 {
02252 #ifdef RIO_DEBUG2
02253 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
02254 "Error closing RioSession: %u (%s)", m_RioStatus,
02255 GetErrorDescription( m_RioStatus ).c_str() );
02256 #endif
02257 }
02258
02259
02260 delete[] m_RioBuffer;
02261 m_RioBuffer = NULL;
02262 delete[] m_ApacheBuffer;
02263 m_ApacheBuffer = NULL;
02264
02265
02266 delete m_CircularBuffer;
02267 m_CircularBuffer = NULL;
02268
02269 return false;
02270 }
02271
02272
02273
02274
02275 if( m_DefaultSessionId == 0 )
02276 {
02277 m_SessionId = 0;
02278 while( m_SessionId == 0 )
02279 {
02280 m_SessionId = random();
02281 }
02282 }
02283 else
02284 m_SessionId = m_DefaultSessionId;
02285
02286
02287 m_RioExplorer->setSession( m_Session );
02288
02289 #ifdef RIO_DEBUG2
02290 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
02291 "Conectado com sucesso ao servidor %s, usando o usuario %s "
02292 "e a senha %s !", m_ServerName, UserName, UserPassword );
02293 #endif
02294
02295 return true;
02296 }
02297
02298
02299
02300 bool CServerInterface::Disconnect()
02301 {
02302 int Status;
02303
02304
02305
02306 m_RioExplorer->setSession( NULL );
02307
02308 Status = CloseRioSession();
02309 if( !Status )
02310 {
02311 #ifdef RIO_DEBUG2
02312 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
02313 "Error closing RioSession: %u (%s)",
02314 m_RioStatus,
02315 GetErrorDescription( m_RioStatus ).c_str() );
02316 #endif
02317 return false;
02318 }
02319
02320
02321 if( m_RioBuffer != NULL )
02322 delete[] m_RioBuffer;
02323 m_RioBuffer = NULL;
02324 if( m_ApacheBuffer != NULL )
02325 delete[] m_ApacheBuffer;
02326 m_ApacheBuffer = NULL;
02327
02328
02329 if( m_CircularBuffer != NULL )
02330 delete m_CircularBuffer;
02331 m_CircularBuffer = NULL;
02332
02333 return true;
02334 }
02335
02336
02337
02338 void CServerInterface::StartXML( request_rec *Request, unsigned int CommandId )
02339 {
02340
02341 const char *Command;
02342
02343
02344 if( CommandId < CMD_INV_ID )
02345 Command = CommandTable[ CommandId ].Command;
02346 else
02347 Command = NULL;
02348
02349 ap_set_content_type( Request, RIOMODULE_MIME_XML );
02350 if( Command != NULL )
02351 {
02352
02353
02354 char HeaderLine[ MaxPathSize ];
02355
02356
02357 sprintf( HeaderLine, "inline; filename=rioexec_%s.xml", Command );
02358
02359
02360 apr_table_set( Request->headers_out, RIOMODULE_HTTP_FILENAME,
02361 HeaderLine );
02362 ap_rprintf( Request, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
02363 ap_rprintf( Request, "<rioexec_%s>\n", Command );
02364 }
02365 else
02366 {
02367
02368 apr_table_set( Request->headers_out, RIOMODULE_HTTP_FILENAME,
02369 "inline; filename=rioexec.xml" );
02370 ap_rprintf( Request, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
02371 ap_rprintf( Request, "<rioexec>\n" );
02372 }
02373
02374 }
02375
02376 void CServerInterface::AddErrorToXML( request_rec *Request,
02377 apr_status_t ApacheStatus,
02378 int SystemStatus, RioResult RioStatus )
02379 {
02380
02381
02382 ap_rprintf( Request, "\t<sessionid id=\"0\">\n" );
02383
02384
02385 if( RioStatus != S_OK )
02386 ap_rprintf( Request, "\t\t<rioerror>%8X %s</rioerror>\n",
02387 RioStatus, GetErrorDescription( RioStatus ).c_str() );
02388
02389
02390 if( ApacheStatus != APR_SUCCESS )
02391 {
02392 char ApacheStrError[ MAXAPACHESTRERRORSIZE ];
02393
02394
02395 apr_strerror( ApacheStatus, ApacheStrError,
02396 MAXAPACHESTRERRORSIZE );
02397
02398
02399 ap_rprintf( Request, "\t\t<apacheerror>%u %s</apacheerror>\n",
02400 ApacheStatus, ApacheStrError );
02401 }
02402
02403
02404 if( SystemStatus != 0 )
02405 ap_rprintf( Request, "\t\t<systemerror>%u %s</systemerror>\n",
02406 SystemStatus, strerror( SystemStatus ) );
02407
02408
02409 ap_rprintf( Request, "\t</sessionid>\n" );
02410 }
02411
02412
02413 void CServerInterface::AddStatusToXML( request_rec *Request,
02414 unsigned int SessionId )
02415 {
02416 if( NoError() )
02417 {
02418
02419
02420 ap_rprintf( Request, "\t<sessionid id=\"%u\">\n", SessionId );
02421
02422 ap_rprintf( Request, "\t</sessionid>\n" );
02423 }
02424 else
02425 AddErrorToXML( Request, m_ApacheStatus, m_SystemStatus, m_RioStatus );
02426 }
02427
02428
02429
02430 void CServerInterface::EndXML( request_rec *Request, unsigned int CommandId )
02431 {
02432
02433 if( CommandId < CMD_INV_ID )
02434 ap_rprintf( Request, "</rioexec_%s>\n",
02435 CommandTable[ CommandId ].Command );
02436 else
02437 ap_rprintf( Request, "</rioexec>\n" );
02438 }
02439
02440
02441 void CServerInterface::GenerateXMLStatus( request_rec *Request,
02442 unsigned int CommandId,
02443 unsigned int SessionId )
02444 {
02445 #ifdef RIO_DEBUG2
02446 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
02447 "Tentando gerar o XML para os seguintes erros: Apache = %u, "
02448 "Sistema = %u e Rio = %08x", m_ApacheStatus, m_SystemStatus,
02449 m_RioStatus );
02450 #endif
02451
02452 StartXML( Request, CommandId );
02453 AddStatusToXML( Request, SessionId );
02454 EndXML( Request, CommandId );
02455 }
02456
02457
02458 void CServerInterface::GenerateExecLogLine( request_rec *Request,
02459 const char *UserName,
02460 unsigned int SessionId,
02461 apr_status_t ApacheStatus,
02462 int SystemStatus,
02463 RioResult RioStatus,
02464 const char *Command,
02465 unsigned int ExecPort )
02466 {
02467
02468
02469 CClientUserLogs *ClientExecLogs;
02470
02471
02472
02473 unsigned int StartParam;
02474
02475
02476
02477 unsigned int EndParam;
02478
02479
02480
02481 unsigned int PasswordParamPos;
02482
02483
02484
02485 unsigned int CommandPos;
02486
02487
02488 char TempChar;
02489
02490
02491 RioResult RioError;
02492
02493
02494 int status;
02495
02496
02497 const char *LocalUserName;
02498
02499
02500 char LogLine[ MAXLOGLINESIZE + 1 ];
02501
02502
02503
02504 if( UserName == NULL )
02505 LocalUserName = "none";
02506 else
02507 LocalUserName = UserName;
02508
02509
02510 if( ( ApacheStatus == APR_SUCCESS ) && ( SystemStatus == 0 ) &&
02511 ( RioStatus == S_OK ) )
02512 status = snprintf( LogLine, MAXLOGLINESIZE + 1, "%s %s %u OK %s",
02513 Request->connection->remote_ip, LocalUserName,
02514 SessionId, Command );
02515 else
02516 status = snprintf( LogLine, MAXLOGLINESIZE + 1, "%s %s %u Apache:%u,"
02517 "RIO:%08X,System:%u %s",
02518 Request->connection->remote_ip, LocalUserName,
02519 SessionId, ApacheStatus, RioStatus, SystemStatus,
02520 Command );
02521
02522
02523 if( status < 0 )
02524 {
02525 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
02526 "CServerInterface::GenerateExecLogLine Erro %u "
02527 "(%s) ao gerar a linha de log!", errno, strerror( errno )
02528 );
02529
02530 return;
02531
02532 }
02533
02534
02535
02536
02537
02538
02539 StartParam = strlen( LogLine ) - strlen( Command );
02540
02541
02542 while( ( LogLine[ StartParam ] == ' ' ) ||
02543 ( LogLine[ StartParam ] == '\t' ) )
02544 StartParam++;
02545
02546
02547 EndParam = StartParam;
02548 while( ( LogLine[ EndParam ] != ' ' ) &&
02549 ( LogLine[ EndParam ] != '\t' ) &&
02550 ( LogLine[ EndParam ] != 0 ) )
02551 EndParam++;
02552
02553
02554
02555
02556 if( LogLine[ EndParam ] != 0 )
02557 {
02558
02559
02560 TempChar = LogLine[ EndParam ];
02561
02562
02563
02564 LogLine[ EndParam ] = 0;
02565
02566
02567
02568 PasswordParamPos = 0;
02569
02570
02571 CommandPos = 0;
02572 while( ( LogCommandTable[ CommandPos ].Command != NULL ) &&
02573 ( PasswordParamPos == 0 ) )
02574 {
02575 if( strcmp( &LogLine[ StartParam ],
02576 LogCommandTable[ CommandPos ].Command ) == 0 )
02577 PasswordParamPos = LogCommandTable[ CommandPos ].PasswordParam;
02578 else
02579 CommandPos++;
02580 }
02581
02582
02583 LogLine[ EndParam ] = TempChar;
02584
02585
02586
02587 if( PasswordParamPos > 0 )
02588 {
02589
02590 StartParam = EndParam;
02591
02592
02593 while( PasswordParamPos > 0 )
02594 {
02595
02596 while( ( LogLine[ StartParam ] == ' ' ) ||
02597 ( LogLine[ StartParam ] == '\t' ) )
02598 StartParam++;
02599
02600
02601 if( PasswordParamPos > 1 )
02602 {
02603
02604 while( ( LogLine[ StartParam ] != ' ' ) &&
02605 ( LogLine[ StartParam ] != '\t' ) &&
02606 ( LogLine[ StartParam ] != 0 ) )
02607 StartParam++;
02608 }
02609
02610
02611 PasswordParamPos--;
02612 }
02613
02614
02615
02616
02617 while( ( LogLine[ StartParam ] != ' ' ) &&
02618 ( LogLine[ StartParam ] != '\t' ) &&
02619 ( LogLine[ StartParam ] != 0 ) )
02620 {
02621 LogLine[ StartParam ] = '*';
02622 StartParam++;
02623 }
02624 }
02625
02626 }
02627
02628
02629 try
02630 {
02631
02632 ClientExecLogs = new CClientUserLogs( Request );
02633
02634 RioError = ClientExecLogs->Initialize( ExecPort );
02635
02636 if( !FAILED( RioError ) )
02637 {
02638
02639 RioError = ClientExecLogs->NewLogLine( LogLine );
02640
02641 #if RIO_DEBUG2
02642 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
02643 "CServerInterface::GenerateExecLogLine Erro %8X "
02644 "(%s) ao tentar inserir a linha de log %s!",
02645 RioError, GetErrorDescription( RioError ).c_str(),
02646 LogLine );
02647 #endif
02648
02649 }
02650 #ifdef RIO_DEBUG2
02651 else
02652 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
02653 "CServerInterface::GenerateExecLogLine Erro %8X "
02654 "(%s) ao inicializar o objeto usado para enviar a "
02655 "linha de log %s!", RioError,
02656 GetErrorDescription( RioError ).c_str(), LogLine );
02657 #endif
02658
02659
02660
02661 delete ClientExecLogs;
02662 }
02663 catch( bad_alloc &ba )
02664 {
02665 #ifdef RIO_DEBUG2
02666 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
02667 "CServerInterface::GenerateExecLogLineErro de alocacao "
02668 "de memoria (bad_alloc, error = %s) ao criar o objeto "
02669 "para enviar a linha de log %s!", ba.what(), LogLine );
02670 #endif
02671 }
02672 }
02673
02674
02675
02676
02677 void CServerInterface::SaveExecLogLine( request_rec *Request,
02678 const char *Command )
02679 {
02680
02681
02682 GenerateExecLogLine( Request, m_UserName, m_SessionId, m_ApacheStatus,
02683 m_SystemStatus, m_RioStatus, Command, m_ExecLogPort );
02684 }
02685
02686
02687
02688 bool CServerInterface::ExecuteLoginCommand( request_rec *Request,
02689 char **Params )
02690 {
02691
02692 bool Status;
02693
02694 #ifdef RIO_DEBUG2
02695
02696 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
02697 "CServerInterface::ExecuteLoginCommand m_isSessionOpen [I] = "
02698 "%s", ( m_isSessionOpen ) ? "true": "false" );
02699 #endif
02700
02701
02702
02703 if( strcmp( Params[ 1 ], "guest" ) == 0 )
02704 {
02705 m_RioStatus = ERROR_SERVERINTERFACE + ERROR_INVALID_USER;
02706
02707 #ifdef RIO_DEBUG2
02708 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
02709 "User guest cannot execute commands!" );
02710 #endif
02711
02712 Status = false;
02713
02714 }
02715 else
02716 {
02717
02718 Status = true;
02719 }
02720
02721
02722
02723
02724 if( Status )
02725 {
02726 Status = Connect( Request, Params[ 1 ], Params[ 2 ] );
02727 #ifdef RIO_DEBUG2
02728 if( !Status )
02729 {
02730 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
02731 "Erro ao executar a funcao Connect!" );
02732 }
02733 #endif
02734 }
02735
02736
02737 GenerateXMLStatus( Request, CMD_LOGIN_ID, m_SessionId );
02738
02739 #ifdef RIO_DEBUG2
02740
02741 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
02742 "CServerInterface::ExecuteLoginCommand m_isSessionOpen [F] = "
02743 "%s", ( m_isSessionOpen ) ? "true": "false" );
02744 #endif
02745
02746 return Status;
02747 }
02748
02749
02750
02751 bool CServerInterface::ExecuteQuitCommand( request_rec *Request, char **Params )
02752 {
02753
02754 bool Status;
02755
02756
02757
02758 unsigned int SessionId;
02759
02760
02761 SessionId = m_SessionId;
02762
02763 #ifdef RIO_DEBUG2
02764
02765 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
02766 "CServerInterface::ExecuteQuitCommand m_isSessionOpen [I] "
02767 "= %s, SessionId (m_SessionId) = %u",
02768 ( m_isSessionOpen ) ? "true": "false", SessionId );
02769 #endif
02770
02771
02772
02773 Status = Disconnect();
02774 #ifdef RIO_DEBUG2
02775 if( !Status )
02776 {
02777 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
02778 "Erro ao executar a funcao Disconnect!" );
02779 }
02780 #endif
02781
02782
02783 GenerateXMLStatus( Request, CMD_QUIT_ID, SessionId );
02784
02785 #ifdef RIO_DEBUG2
02786
02787 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
02788 "CServerInterface::ExecuteQuitCommand m_isSessionOpen [F] "
02789 "= %s, m_SessionId = %u",
02790 ( m_isSessionOpen ) ? "true": "false", m_SessionId );
02791 #endif
02792
02793 return Status;
02794 }
02795
02796
02797
02798 bool CServerInterface::ExecuteSessionsCommand( request_rec *Request,
02799 char **Params )
02800 {
02801
02802 bool Status;
02803
02804 SessionsInfo Info;
02805
02806
02807 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
02808 "CServerInterface::ExecuteSessionsCommand m_isSessionOpen "
02809 "[I] = %s", ( m_isSessionOpen ) ? "true": "false" );
02810
02811
02812 Status = m_RioExplorer->sessions( &Info );
02813 if( !Status )
02814 {
02815
02816 m_RioExplorer->getError( &m_RioStatus, &m_SystemStatus );
02817
02818 #ifdef RIO_DEBUG2
02819 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
02820 "Erro ao executar a funcao Disconnect!" );
02821 #endif
02822 }
02823
02824
02825 StartXML( Request, CMD_SESSIONS_ID );
02826 AddStatusToXML( Request, m_SessionId );
02827
02828 if( Status )
02829 {
02830
02831 ap_rprintf( Request, "\t<maxsessions> %u </maxsessions>\n",
02832 Info.number_of_max_sessions );
02833
02834 ap_rprintf( Request, "\t<activesessions> %u </activesessions>\n",
02835 Info.number_of_active_sessions );
02836 }
02837 EndXML( Request, CMD_SESSIONS_ID );
02838
02839
02840 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
02841 "CServerInterface::ExecuteSessionsCommand m_isSessionOpen "
02842 "[F] = %s", ( m_isSessionOpen ) ? "true": "false" );
02843
02844 return Status;
02845 }
02846
02847
02848
02849 bool CServerInterface::ExecuteLsCommand( request_rec *Request, char **Params )
02850 {
02851
02852 ObjectInfo LsObjectInfo;
02853
02854
02855 bool Status;
02856
02857
02858 AccessTime ObjectAcessTime;
02859
02860 char ObjectMd5[ MD5SIZE ];
02861
02862
02863
02864 vector<ObjectInfo> LsObjets;
02865
02866
02867 StartXML( Request, CMD_LS_ID );
02868
02869
02870 Status = CheckDirectoryPermission( Params[ 1 ] );
02871 if( Status )
02872 {
02873
02874
02875
02876 Status = m_RioExplorer->getObjectInfo( Params[ 1 ], m_Session,
02877 &LsObjectInfo, true );
02878
02879
02880
02881
02882
02883
02884 if( Status )
02885 {
02886
02887 if( !LsObjectInfo.isDir() )
02888 {
02889
02890
02891
02892 Status = false;
02893
02894 m_RioStatus = ERROR_SERVERINTERFACE +
02895 ERROR_OBJECT_NOT_DIRECTORY;
02896
02897 #ifdef RIO_DEBUG2
02898 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
02899 "CServerInterface::ExecuteLsCommand O objeto %s "
02900 "nao e um diretorio! Erro retornado %8X (%s)!",
02901 Params[ 1 ], m_RioStatus,
02902 GetErrorDescription( m_RioStatus ).c_str() );
02903 #endif
02904 }
02905 else
02906 {
02907
02908 Status = m_RioExplorer->ls( &LsObjectInfo, &LsObjets, m_Session,
02909 true, false, NULL, 0 );
02910
02911 if( !Status )
02912 {
02913
02914 m_RioExplorer->getError( &m_RioStatus, &m_SystemStatus );
02915
02916 #ifdef RIO_DEBUG2
02917 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
02918 "CServerInterface::ExecuteLsCommand Erro ao "
02919 "executar o comando ls no diretorio %s!",
02920 Params[ 1 ] );
02921 #endif
02922 }
02923 }
02924 }
02925 else
02926 {
02927
02928 m_RioExplorer->getError( &m_RioStatus, &m_SystemStatus );
02929
02930 #ifdef RIO_DEBUG2
02931 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
02932 "CServerInterface::ExecuteLsCommand Erro ao obter "
02933 "as informacoes do objeto %s!", Params[ 1 ] );
02934 #endif
02935 }
02936 }
02937
02938
02939 AddStatusToXML( Request, m_SessionId );
02940
02941
02942
02943 if( Status )
02944 {
02945
02946
02947 ap_rprintf( Request, "\t<ls dirname=\"%s\">\n",
02948 LsObjectInfo.getFullPath().c_str() );
02949 ap_rprintf( Request, "\t\t<size>%lld</size>\n",
02950 LsObjectInfo.getSize() );
02951 ap_rprintf( Request, "\t\t<owner>%s</owner>\n",
02952 LsObjectInfo.getOwner().c_str() );
02953 ap_rprintf( Request, "\t\t<group>%s</group>\n",
02954 LsObjectInfo.getGroup().c_str() );
02955 ap_rprintf( Request, "\t\t<permission></permission>\n" );
02956
02957 ObjectAcessTime = LsObjectInfo.getTime();
02958 ap_rprintf( Request, "\t\t<datemodified>%04u-%02u-%02u %02u:%02u"
02959 "</datemodified>\n", ObjectAcessTime.Year,
02960 ObjectAcessTime.Month, ObjectAcessTime.Day,
02961 ObjectAcessTime.Hour, ObjectAcessTime.Minute );
02962
02963
02964 for( unsigned int i = 0; i < LsObjets.size(); i++ )
02965 {
02966
02967 ObjectAcessTime = LsObjets[ i ].getTime();
02968
02969
02970
02971 if( LsObjets[ i ].isDir() )
02972 {
02973
02974 ap_rprintf( Request, "\t\t<dir dirname=\"%s\">\n",
02975 LsObjets[ i ].getFullPath().c_str() );
02976 ap_rprintf( Request, "\t\t\t<size>%lld</size>\n",
02977 LsObjets[ i ].getSize() );
02978 ap_rprintf( Request, "\t\t\t<owner>%s</owner>\n",
02979 LsObjets[ i ].getOwner().c_str() );
02980 ap_rprintf( Request, "\t\t\t<group>%s</group>\n",
02981 LsObjets[ i ].getGroup().c_str() );
02982 ap_rprintf( Request, "\t\t\t<permission>%s</permission>\n",
02983 short2Permission(
02984 LsObjets[ i ].getPermission() ).c_str() );
02985
02986
02987 ObjectAcessTime = LsObjets[ i ].getTime();
02988 ap_rprintf( Request, "\t\t\t<datemodified>"
02989 "%04u-%02u-%02u %02u:%02u"
02990 "</datemodified>\n", ObjectAcessTime.Year,
02991 ObjectAcessTime.Month, ObjectAcessTime.Day,
02992 ObjectAcessTime.Hour,
02993 ObjectAcessTime.Minute );
02994 ap_rprintf( Request, "\t\t</dir>\n" );
02995 }
02996 else
02997 {
02998
02999 ap_rprintf( Request, "\t\t<file>\n" );
03000 ap_rprintf( Request, "\t\t\t<name>%s</name>\n",
03001 LsObjets[ i ].getFullPath().c_str() );
03002 ap_rprintf( Request, "\t\t\t<size>%lld</size>\n",
03003 LsObjets[ i ].getSize() );
03004 ap_rprintf( Request, "\t\t\t<owner>%s</owner>\n",
03005 LsObjets[ i ].getOwner().c_str() );
03006 ap_rprintf( Request, "\t\t\t<group>%s</group>\n",
03007 LsObjets[ i ].getGroup().c_str() );
03008 ap_rprintf( Request, "\t\t\t<permission>%s</permission>\n",
03009 short2Permission(
03010 LsObjets[ i ].getPermission() ).c_str() );
03011
03012
03013 ObjectAcessTime = LsObjets[ i ].getTime();
03014 ap_rprintf( Request, "\t\t\t<datemodified>"
03015 "%04u-%02u-%02u %02u:%02u"
03016 "</datemodified>\n", ObjectAcessTime.Year,
03017 ObjectAcessTime.Month, ObjectAcessTime.Day,
03018 ObjectAcessTime.Hour,
03019 ObjectAcessTime.Minute );
03020
03021 LsObjets[ i ].getMd5sum( &ObjectMd5[ 0 ] );
03022 ap_rprintf( Request, "\t\t\t<md5sum>%s</md5sum>\n", ObjectMd5 );
03023 ap_rprintf( Request, "\t\t</file>\n" );
03024 }
03025 }
03026 ap_rprintf( Request, "\t</ls>\n" );
03027 }
03028
03029 EndXML( Request, CMD_LS_ID );
03030
03031
03032 return Status;
03033 }
03034
03035
03036
03037
03038
03039
03040 bool CServerInterface::ConvertPath( request_rec *Request, char *OriginalPath,
03041 char *ConvertedPath,
03042 unsigned int ConvertedPathSize )
03043 {
03044
03045 bool Status;
03046
03047
03048
03049 unsigned int StartComp, EndComp;
03050
03051 unsigned int CompSize;
03052
03053
03054
03055
03056 Status = true;
03057 ConvertedPath[ 0 ] = '\0';
03058 StartComp = 0;
03059
03060
03061
03062 while( ( OriginalPath[ StartComp ] != '\0' ) && ( Status ) )
03063 {
03064 #ifdef RIO_DEBUG2
03065 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
03066 "Verificando a partir de %s, Novo caminho e igual a %s",
03067 &OriginalPath[ StartComp ], ConvertedPath );
03068 #endif
03069
03070
03071 while( OriginalPath[ StartComp ] == '/' )
03072 StartComp++;
03073
03074
03075
03076 if( OriginalPath[ StartComp ] != '\0' )
03077 {
03078 EndComp = StartComp;
03079
03080
03081 while( ( OriginalPath[ EndComp ] != '/' ) &&
03082 ( OriginalPath[ EndComp ] != '\0') )
03083 EndComp++;
03084
03085
03086
03087
03088
03089
03090
03091 CompSize = EndComp - StartComp;
03092
03093
03094 if( CompSize == 0 )
03095 {
03096
03097
03098
03099
03100 if( OriginalPath[ StartComp ] != '\0' )
03101 {
03102 #ifdef RIO_DEBUG2
03103 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
03104 "Erro de implementacao ao converter o "
03105 "caminho %s!", OriginalPath );
03106 #endif
03107
03108 ConvertedPath[ 0 ] = '\0';
03109 m_RioStatus = ERROR_SERVERINTERFACE + ERROR_UNEXPECTED;
03110 Status = false;
03111 }
03112 }
03113 else if( ( CompSize == 1 ) && ( OriginalPath[ StartComp ] == '.' ) )
03114 {
03115
03116
03117 }
03118 else if( ( CompSize == 2 ) &&
03119 ( OriginalPath[ StartComp ] == '.' ) &&
03120 ( OriginalPath[ StartComp + 1 ] == '.' ) )
03121 {
03122
03123
03124
03125 char *StartLastDir;
03126
03127
03128 StartLastDir = strrchr( ConvertedPath, '/' );
03129
03130
03131 if( StartLastDir == NULL )
03132 StartLastDir = ConvertedPath;
03133 else if( StartLastDir == ConvertedPath )
03134 {
03135
03136
03137
03138
03139 StartLastDir++;
03140 }
03141
03142
03143
03144
03145 if( strlen( StartLastDir ) > 0 )
03146 {
03147
03148
03149 *StartLastDir = '\0';
03150 }
03151 else
03152 {
03153
03154
03155 #ifdef RIO_DEBUG2
03156 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
03157 "Erro de sintaxe no caminho %s!",
03158 OriginalPath );
03159 #endif
03160
03161 ConvertedPath[ 0 ] = '\0';
03162 m_RioStatus = ERROR_SERVERINTERFACE +
03163 ERROR_PATHNAME_BADSYNTAX;
03164 Status = false;
03165 }
03166 }
03167 else
03168 {
03169
03170 unsigned int ConvertedCompSize;
03171
03172
03173 unsigned int ActualConvertedPathSize;
03174
03175
03176
03177
03178
03179
03180
03181
03182 ConvertedCompSize = CompSize;
03183
03184
03185 ActualConvertedPathSize = strlen( ConvertedPath );
03186
03187
03188
03189
03190
03191 if( ( ActualConvertedPathSize == 0 ) ||
03192 ( ConvertedPath[ ActualConvertedPathSize - 1 ] != '/' ) )
03193 ConvertedCompSize++;
03194
03195
03196
03197 if( ( ActualConvertedPathSize + ConvertedCompSize ) >
03198 ConvertedPathSize )
03199 {
03200
03201 #ifdef RIO_DEBUG2
03202 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
03203 "O caminho %s e muito grande!",
03204 OriginalPath );
03205 #endif
03206
03207 ConvertedPath[ 0 ] = '\0';
03208 m_RioStatus = ERROR_SERVERINTERFACE +
03209 ERROR_PATHNAME_TOOLARGE;
03210 Status = false;
03211 }
03212 else
03213 {
03214
03215 if( ( ActualConvertedPathSize == 0 ) ||
03216 ( ConvertedPath[ ActualConvertedPathSize - 1 ] != '/' )
03217 )
03218 strcat( ConvertedPath, "/" );
03219 strncat( ConvertedPath, &OriginalPath[ StartComp ],
03220 CompSize );
03221 }
03222 }
03223
03224
03225 StartComp = EndComp;
03226 }
03227 }
03228
03229 #ifdef RIO_DEBUG2
03230 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
03231 "Novo caminho final e igual a %s, Status = %u",
03232 ConvertedPath, ( unsigned int ) Status );
03233 #endif
03234
03235 return Status;
03236 }
03237
03238
03239
03240 bool CServerInterface::ExecuteRmCommand( request_rec *Request, char **Params )
03241 {
03242
03243 ObjectInfo LsObjectInfo;
03244
03245
03246 bool Status;
03247
03248
03249 char ConvertedPath[ MaxPathSize + 1 ];
03250
03251
03252 #ifdef RIO_DEBUG2
03253 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
03254 "Tentando converter %s", Params[ 1 ] );
03255 #endif
03256
03257 Status = ConvertPath( Request, Params[ 1 ], ConvertedPath, MaxPathSize );
03258 if( Status )
03259 {
03260 #ifdef RIO_DEBUG2
03261 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
03262 "Caminho %s convertido para %s", Params[ 1 ],
03263 ConvertedPath );
03264 #endif
03265
03266
03267
03268 Status = m_RioExplorer->getObjectInfo( ConvertedPath, m_Session,
03269 &LsObjectInfo, true );
03270
03271
03272
03273 if( Status )
03274 {
03275
03276 const char *ObjectFullPath;
03277
03278
03279
03280
03281 ObjectFullPath = LsObjectInfo.getFullPath().c_str();
03282
03283
03284 #ifdef RIO_DEBUG2
03285 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
03286 "Arquivo a ser removido %s, usuario %s!",
03287 ObjectFullPath, m_UserName );
03288 #endif
03289
03290
03291 if( strcmp( &ObjectFullPath[ 1 ], m_UserName ) == 0 )
03292 {
03293 #ifdef RIO_DEBUG2
03294 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
03295 "Diretorio do usuario %s detectado!",
03296 m_UserName );
03297 #endif
03298
03299 Status = false;
03300 m_RioStatus = ERROR_SERVERINTERFACE + ERROR_PERMISSION_DENIED;
03301 }
03302 else
03303 {
03304 #ifdef RIO_DEBUG2
03305 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
03306 "Tentando remover o objeto %s!",
03307 ObjectFullPath );
03308 #endif
03309
03310
03311 Status = m_RioExplorer->rm( &LsObjectInfo, m_Session, false,
03312 true );
03313 }
03314
03315 if( !Status )
03316 {
03317
03318 m_RioExplorer->getError( &m_RioStatus, &m_SystemStatus );
03319
03320 #ifdef RIO_DEBUG2
03321 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
03322 "CServerInterface::ExecuteRmCommand Erro ao "
03323 "executar o comando rm no objeto %s!",
03324 ConvertedPath );
03325 #endif
03326 }
03327 }
03328 else
03329 {
03330
03331 m_RioExplorer->getError( &m_RioStatus, &m_SystemStatus );
03332
03333 #ifdef RIO_DEBUG2
03334 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
03335 "CServerInterface::ExecuteRmCommand Erro ao obter "
03336 "as informacoes do objeto %s!", ConvertedPath );
03337 #endif
03338 }
03339 }
03340 #ifdef RIO_DEBUG2
03341 else
03342 {
03343 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
03344 "CServerInterface::ExecuteRmCommand Erro ao converter "
03345 "o caminho %s!", Params[ 1 ] );
03346 }
03347 #endif
03348
03349
03350 GenerateXMLStatus( Request, CMD_RM_ID, m_SessionId );
03351
03352
03353 return Status;
03354 }
03355
03356
03357
03358 bool CServerInterface::ExecuteMkdirCommand( request_rec *Request,
03359 char **Params )
03360 {
03361
03362
03363 bool Status;
03364
03365
03366 Status = m_RioExplorer->mkdir( Params[ 1 ], m_Session, true );
03367
03368 if( !Status )
03369 {
03370
03371 m_RioExplorer->getError( &m_RioStatus, &m_SystemStatus );
03372
03373 #ifdef RIO_DEBUG2
03374 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
03375 "CServerInterface::ExecuteMkdirCommand Erro ao "
03376 "executar o comando rm no diretorio %s!",
03377 Params[ 1 ] );
03378 #endif
03379 }
03380
03381
03382 GenerateXMLStatus( Request, CMD_MKDIR_ID, m_SessionId );
03383
03384
03385 return Status;
03386 }
03387
03388
03389 bool CServerInterface::FinalizeCopy( request_rec *Request )
03390 {
03391 int status;
03392 bool isReadingFile;
03393
03394
03395 status = pthread_mutex_lock( &m_Mutex );
03396 if( status < 0 )
03397 {
03398 m_SystemStatus = status;
03399
03400 #ifdef RIO_DEBUG2
03401 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
03402 "Error locking m_Mutex: %u (%s)",
03403 m_SystemStatus, strerror( m_SystemStatus ) );
03404 #endif
03405
03406 return false;
03407 }
03408
03409
03410
03411 if( !m_CircularBuffer->CleanBuffer() )
03412 {
03413 #ifdef RIO_DEBUG2
03414 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
03415 "Error when cleaning m_CircularBuffer" );
03416 #endif
03417 }
03418
03419
03420
03421 isReadingFile = m_isReadingRioFile;
03422
03423
03424 if( isReadingFile )
03425 {
03426
03427
03428
03429 m_isReadingRioFile = false;
03430 m_RioBlock = 0;
03431 m_SendBlock = 0;
03432 m_TotalBlocks = 0;
03433
03434
03435
03436 if( !TerminateCopyToClient( Request ) )
03437 {
03438 #ifdef RIO_DEBUG2
03439 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
03440 "Error when executing TerminateCopyToClient" );
03441 #endif
03442 }
03443
03444 status = pthread_cond_wait( &m_ThreadBlocked, &m_Mutex );
03445
03446 if( status < 0 )
03447 {
03448 m_SystemStatus = status;
03449
03450 #ifdef RIO_DEBUG2
03451 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
03452 "Error closing file: %u (%s)", m_SystemStatus,
03453 strerror( m_SystemStatus ) );
03454 #endif
03455
03456
03457 status = pthread_mutex_unlock( &m_Mutex );
03458 if( status < 0 )
03459 {
03460 m_SystemStatus = status;
03461
03462 #ifdef RIO_DEBUG2
03463 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
03464 "Error unlocking m_Mutex: %u (%s)",
03465 m_SystemStatus, strerror( m_SystemStatus ) );
03466 #endif
03467
03468 }
03469
03470 return false;
03471 }
03472 }
03473
03474
03475
03476 isReadingFile = m_isReadingApacheFile;
03477
03478
03479 if( isReadingFile )
03480 {
03481
03482
03483
03484 m_isReadingApacheFile = false;
03485 m_IsApacheEof = false;
03486 m_isReadingApacheFile = 0;
03487 m_UploadRequest = NULL;
03488
03489 status = pthread_cond_wait( &m_ThreadBlocked, &m_Mutex );
03490
03491 if( status < 0 )
03492 {
03493 m_SystemStatus = status;
03494
03495 #ifdef RIO_DEBUG2
03496 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
03497 "Error closing file: %u (%s)", m_SystemStatus,
03498 strerror( m_SystemStatus ) );
03499 #endif
03500
03501
03502 status = pthread_mutex_unlock( &m_Mutex );
03503 if( status < 0 )
03504 {
03505 m_SystemStatus = status;
03506
03507 #ifdef RIO_DEBUG2
03508 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
03509 "Error unlocking m_Mutex: %u (%s)",
03510 m_SystemStatus, strerror( m_SystemStatus ) );
03511 #endif
03512
03513 }
03514
03515 return false;
03516 }
03517 }
03518
03519
03520 status = pthread_mutex_unlock( &m_Mutex );
03521 if( status < 0 )
03522 {
03523 m_SystemStatus = status;
03524
03525 #ifdef RIO_DEBUG2
03526 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
03527 "Error unlocking m_Mutex: %u (%s)",
03528 m_SystemStatus, strerror( m_SystemStatus ) );
03529 #endif
03530
03531 return false;
03532 }
03533
03534 return true;
03535 }
03536
03537
03538 bool CServerInterface::Close( request_rec *Request )
03539 {
03540
03541 if( !FinalizeCopy( Request ) )
03542 {
03543 #ifdef RIO_DEBUG2
03544 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
03545 "Error when executing FinalizeCopy" );
03546 #endif
03547
03548 return false;
03549 }
03550
03551 if( !CloseRioObject() )
03552 {
03553 #ifdef RIO_DEBUG2
03554 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
03555 "Error closing RioObject: %u (%s)", m_RioStatus,
03556 GetErrorDescription( m_RioStatus ).c_str() );
03557 #endif
03558
03559 return false;
03560 }
03561
03562 if( !CloseRioStream() )
03563 {
03564 #ifdef RIO_DEBUG2
03565 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
03566 "Error closing RioStream: %u (%s)", m_RioStatus,
03567 GetErrorDescription( m_RioStatus ).c_str() );
03568 #endif
03569
03570 return false;
03571 }
03572
03573 return true;
03574 }
03575
03576
03577
03578 bool CServerInterface::SendFileHeader( request_rec *Request,
03579 const char *FileName,
03580 RioObjectSize FileSize )
03581 {
03582 const char *StartFinalExtension;
03583 const char *Header;
03584 unsigned int HeaderSize;
03585 RioObjectSize RealFileSize;
03586
03587
03588 RealFileSize = FileSize;
03589
03590
03591 StartFinalExtension = strrchr( FileName, '.' );
03592
03593
03594
03595 if( StartFinalExtension != NULL )
03596 {
03597
03598
03599 if( strcmp( StartFinalExtension + 1, "flv" ) == 0 )
03600 {
03601 Header = FLVX_HEADER;
03602 HeaderSize = FLVX_HEADER_LEN;
03603 RealFileSize = RealFileSize + HeaderSize;
03604 }
03605 else
03606 {
03607
03608
03609 Header = NULL;
03610 HeaderSize = 0;
03611 }
03612
03613 ap_set_content_length( Request, RealFileSize );
03614
03615 if( Header != NULL )
03616 return SendBlock( Request, Header, HeaderSize );
03617
03618 }
03619
03620 return true;
03621 }
03622
03623
03624 int CServerInterface::DownloadFile( request_rec *Request, const char *FileName,
03625 bool *SendXML, RioObjectSize StartPosition,
03626 bool SendHeader )
03627 {
03628 RioResult hResult;
03629 int status;
03630 RioObjectSize FileSize;
03631 RioObjectSize RealFileSize;
03632 bool isFirstBlock;
03633 RioObjectSize StartFirstBlock;
03634 bool HasNextBlock;
03635 RioBlock Block;
03636 const char *FileNamePos;
03637 char *Data;
03638 unsigned int DataSize;
03639 char HeaderLine[ MaxPathSize ];
03640
03641
03642
03643 *SendXML = true;
03644
03645
03646 request_rec *SubRequest;
03647
03648
03649 status = pthread_mutex_lock( &m_Mutex );
03650 if( status < 0 )
03651 {
03652 m_SystemStatus = status;
03653
03654 #ifdef RIO_DEBUG2
03655 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
03656 "Error locking m_Mutex: %u (%s)",
03657 m_SystemStatus, strerror( m_SystemStatus ) );
03658
03659 #endif
03660
03661 return HTTP_INTERNAL_SERVER_ERROR;
03662 }
03663
03664
03665 if( ( m_isReadingRioFile ) || ( m_SendBlock < m_TotalBlocks ) )
03666 {
03667 #ifdef RIO_DEBUG2
03668 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
03669 "A copy is already in progress" );
03670 #endif
03671
03672
03673 status = pthread_mutex_unlock( &m_Mutex );
03674 if( status < 0 )
03675 {
03676 m_SystemStatus = status;
03677
03678 #ifdef RIO_DEBUG2
03679 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
03680 "Error unlocking m_Mutex: %u (%s)",
03681 m_SystemStatus, strerror( m_SystemStatus ) );
03682 #endif
03683 }
03684
03685 return HTTP_INTERNAL_SERVER_ERROR;
03686 }
03687
03688
03689 status = pthread_mutex_unlock( &m_Mutex );
03690 if( status < 0 )
03691 {
03692 m_SystemStatus = status;
03693
03694 #ifdef RIO_DEBUG2
03695 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
03696 "Error unlocking m_Mutex: %u (%s)",
03697 m_SystemStatus, strerror( m_SystemStatus ) );
03698 #endif
03699
03700 return HTTP_INTERNAL_SERVER_ERROR;
03701 }
03702
03703
03704 if( !OpenRioStream( RioStreamDirectionRead ) )
03705 {
03706 #ifdef RIO_DEBUG2
03707 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
03708 "Error creating RIO Stream: %u (%s)", m_RioStatus,
03709 GetErrorDescription( m_RioStatus ).c_str() );
03710 #endif
03711
03712 return HTTP_SERVICE_UNAVAILABLE;
03713 }
03714
03715
03716 if( !OpenRioObject( FileName, RIO_READ_MASK ) )
03717 {
03718 #ifdef RIO_DEBUG2
03719 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
03720 "Error opening RioObject: %u (%s)", m_RioStatus,
03721 GetErrorDescription( m_RioStatus ).c_str() );
03722 #endif
03723
03724 if( !CloseRioStream() )
03725 {
03726 #ifdef RIO_DEBUG2
03727 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
03728 "Error closing RioStream: %u (%s)", m_RioStatus,
03729 GetErrorDescription( m_RioStatus ).c_str() );
03730 #endif
03731 }
03732
03733
03734
03735 if( ( m_RioStatus & 0xFF ) == ERROR_INVALID_OBJECTNAME )
03736 return HTTP_NOT_FOUND;
03737 else
03738 return HTTP_SERVICE_UNAVAILABLE;
03739 }
03740
03741
03742 hResult = m_Object->GetSize( &FileSize );
03743
03744 if( FAILED( hResult ) )
03745 {
03746 m_RioStatus = hResult;
03747
03748 #ifdef RIO_DEBUG2
03749 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
03750 "Error getting object size: %u (%s)", m_RioStatus,
03751 GetErrorDescription( m_RioStatus ).c_str() );
03752 #endif
03753
03754 return HTTP_SERVICE_UNAVAILABLE;
03755 }
03756
03757
03758
03759 if( ( ( StartPosition < -FileSize ) ) || ( StartPosition >= FileSize ) )
03760 {
03761 m_RioStatus = ERROR_SERVERINTERFACE + ERROR_INVALID_PARAM;
03762
03763 #ifdef RIO_DEBUG2
03764 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
03765 "Invalid start position %lld >= file size %lld: "
03766 "%u (%s)", StartPosition, FileSize, m_RioStatus,
03767 GetErrorDescription( m_RioStatus ).c_str() );
03768 #endif
03769
03770 return HTTP_BAD_REQUEST;
03771 }
03772
03773
03774
03775
03776
03777 if( StartPosition < 0 )
03778 StartPosition = FileSize + StartPosition;
03779
03780
03781 status = pthread_mutex_lock( &m_Mutex );
03782 if( status < 0 )
03783 {
03784 m_SystemStatus = status;
03785
03786 #ifdef RIO_DEBUG2
03787 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
03788 "Error locking m_Mutex: %u (%s)",
03789 m_SystemStatus, strerror( m_SystemStatus ) );
03790 #endif
03791
03792 if( !Close( Request ) )
03793 {
03794 #ifdef RIO_DEBUG2
03795 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
03796 "Error when executing Close" );
03797 #endif
03798 }
03799
03800 return HTTP_INTERNAL_SERVER_ERROR;
03801 }
03802
03803
03804 m_TotalBlocks = ( FileSize + m_BlockSize - 1 ) / m_BlockSize;
03805
03806
03807 m_RioBlock = StartPosition / m_BlockSize;
03808 m_SendBlock = m_RioBlock;
03809
03810
03811 StartFirstBlock = StartPosition % m_BlockSize;
03812
03813
03814
03815 isFirstBlock = true;
03816
03817
03818 m_isReadingRioFile = true;
03819
03820
03821 if( !m_CircularBuffer->ReinitializeBuffer() )
03822 {
03823 m_SystemStatus = m_CircularBuffer->GetError();
03824
03825 #ifdef RIO_DEBUG2
03826 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
03827 "Error reinitializing circular buffer: %u (%s)",
03828 m_SystemStatus, strerror( m_SystemStatus ) );
03829 #endif
03830
03831
03832 if( !Close( Request ) )
03833 {
03834 #ifdef RIO_DEBUG2
03835 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
03836 "Error when executing Close" );
03837 #endif
03838 }
03839
03840 return HTTP_INTERNAL_SERVER_ERROR;
03841 }
03842
03843
03844
03845 status = pthread_cond_signal( &m_ReadRioStarted );
03846 if( status < 0 )
03847 {
03848 m_SystemStatus = status;
03849
03850 #ifdef RIO_DEBUG2
03851 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
03852 "Error signalling m_ReadRioStarted: %u (%s)",
03853 m_SystemStatus, strerror( m_SystemStatus ) );
03854 #endif
03855
03856 return false;
03857 }
03858
03859
03860 HasNextBlock = ( m_SendBlock < m_TotalBlocks );
03861
03862
03863 status = pthread_mutex_unlock( &m_Mutex );
03864 if( status < 0 )
03865 {
03866 m_SystemStatus = status;
03867
03868 #ifdef RIO_DEBUG2
03869 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
03870 "Error unlocking m_Mutex: %u (%s)",
03871 m_SystemStatus, strerror( m_SystemStatus ) );
03872 #endif
03873
03874 if( !Close( Request ) )
03875 {
03876 #ifdef RIO_DEBUG2
03877 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
03878 "Error when executing Close" );
03879 #endif
03880 }
03881
03882 return HTTP_INTERNAL_SERVER_ERROR;
03883 }
03884
03885
03886
03887 FileNamePos = strrchr( FileName, '/' );
03888 if( FileNamePos == NULL )
03889 FileNamePos = FileName;
03890 else
03891 FileNamePos++;
03892
03893
03894
03895 sprintf( HeaderLine, "inline; filename=%s", FileNamePos );
03896
03897
03898 apr_table_set( Request->headers_out, RIOMODULE_HTTP_FILENAME,
03899 HeaderLine );
03900
03901
03902
03903 #ifdef RIO_DEBUG2
03904 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
03905 "Creating subrequest for file %s", FileNamePos );
03906 #endif
03907
03908
03909 SubRequest = ap_sub_req_lookup_uri( FileNamePos, Request, NULL );
03910 if( SubRequest == NULL )
03911 {
03912 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
03913 "Error creating subrequest. Using default type %s",
03914 RIOMODULE_MIME );
03915 ap_set_content_type( Request, RIOMODULE_MIME );
03916 }
03917 else
03918 {
03919 #ifdef RIO_DEBUG2
03920 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
03921 "Subrequest content-type: %s",
03922 SubRequest->content_type );
03923 #endif
03924
03925
03926
03927 if( SubRequest->content_type != NULL )
03928 ap_set_content_type( Request, SubRequest->content_type );
03929 else
03930 ap_set_content_type( Request, RIOMODULE_MIME );
03931
03932
03933 ap_destroy_sub_req( SubRequest );
03934 }
03935
03936
03937
03938 RealFileSize = FileSize - StartPosition;
03939
03940
03941
03942
03943
03944 if( ( StartPosition > 0 ) && ( SendHeader ) )
03945 {
03946 if( !SendFileHeader( Request, FileName, RealFileSize ) )
03947 {
03948 #ifdef RIO_DEBUG2
03949 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
03950 "Error when sending header for file %s ",
03951 FileName );
03952 #endif
03953
03954 if( !Close( Request ) )
03955 {
03956 #ifdef RIO_DEBUG2
03957 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
03958 "Error when executing Close" );
03959 #endif
03960 }
03961
03962 return HTTP_SERVICE_UNAVAILABLE;
03963 }
03964 }
03965 else
03966 {
03967
03968
03969
03970
03971 ap_set_content_length( Request, RealFileSize );
03972 }
03973
03974
03975
03976 *SendXML = false;
03977
03978
03979 while( HasNextBlock )
03980 {
03981
03982
03983 status = pthread_mutex_lock( &m_Mutex );
03984 if( status < 0 )
03985 {
03986 m_SystemStatus = status;
03987
03988 #ifdef RIO_DEBUG2
03989 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
03990 "Error locking m_Mutex: %u (%s)",
03991 m_SystemStatus, strerror( m_SystemStatus ) );
03992 #endif
03993
03994
03995 if( !Close( Request ) )
03996 {
03997 #ifdef RIO_DEBUG2
03998 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
03999 "Error when executing Close" );
04000 #endif
04001 }
04002
04003 return HTTP_INTERNAL_SERVER_ERROR;
04004 }
04005
04006 Block = m_SendBlock;
04007 m_SendBlock++;
04008
04009 #ifdef RIO_DEBUG2
04010 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
04011 "Trying to copy block %u", m_SendBlock - 1 );
04012 #endif
04013
04014 HasNextBlock = ( m_SendBlock < m_TotalBlocks );
04015
04016
04017 status = pthread_mutex_unlock( &m_Mutex );
04018 if( status < 0 )
04019 {
04020 m_SystemStatus = status;
04021
04022 #ifdef RIO_DEBUG2
04023 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
04024 "Error unlocking m_Mutex: %u (%s)",
04025 m_SystemStatus, strerror( m_SystemStatus ) );
04026 #endif
04027
04028
04029 if( !Close( Request ) )
04030 {
04031 #ifdef RIO_DEBUG2
04032 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
04033 "Error when executing Close" );
04034 #endif
04035 }
04036
04037 return HTTP_INTERNAL_SERVER_ERROR;
04038 }
04039
04040
04041
04042 if( !m_CircularBuffer->GetElement( m_ApacheBuffer ) )
04043 {
04044 m_SystemStatus = m_CircularBuffer->GetError();
04045
04046 #ifdef RIO_DEBUG2
04047 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
04048 "Error reading block %u from circular buffer: %u (%s)",
04049 Block, m_SystemStatus, strerror( m_SystemStatus ) );
04050 #endif
04051
04052
04053 if( !Close( Request ) )
04054 {
04055 #ifdef RIO_DEBUG2
04056 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
04057 "Error when executing Close" );
04058 #endif
04059 }
04060
04061 return HTTP_INTERNAL_SERVER_ERROR;
04062 }
04063
04064
04065
04066
04067 if( isFirstBlock )
04068 {
04069 Data = &m_ApacheBuffer[ StartFirstBlock ];
04070 if( HasNextBlock )
04071 {
04072
04073
04074 DataSize = m_BlockSize - StartFirstBlock;
04075 }
04076 else
04077 DataSize = FileSize - StartFirstBlock;
04078
04079
04080 isFirstBlock = false;
04081 }
04082 else
04083 {
04084
04085
04086
04087
04088 Data = m_ApacheBuffer;
04089 if( HasNextBlock )
04090 DataSize = m_BlockSize;
04091 else
04092 DataSize = FileSize - ( ( m_TotalBlocks - 1 ) * m_BlockSize );
04093 }
04094
04095
04096 if( !SendBlock( Request, Data, DataSize ) )
04097 {
04098 #ifdef RIO_DEBUG2
04099 ap_log_error( APLOG_MARK, APLOG_ERR, m_ApacheStatus, m_Server,
04100 "Error sending block %u to the client", Block );
04101 #endif
04102
04103
04104 if( !Close( Request ) )
04105 {
04106 #ifdef RIO_DEBUG2
04107 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
04108 "Error when executing Close" );
04109 #endif
04110
04111 }
04112
04113 return HTTP_SERVICE_UNAVAILABLE;
04114 }
04115 }
04116
04117
04118 if( !Close( Request ) )
04119 {
04120 #ifdef RIO_DEBUG2
04121 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
04122 "Error when executing Close" );
04123 #endif
04124
04125 return HTTP_INTERNAL_SERVER_ERROR;
04126 }
04127
04128 return OK;
04129 }
04130
04131
04132
04133 bool CServerInterface::CheckDirectoryPermission( char *FileName )
04134 {
04135
04136
04137
04138 char *Path;
04139
04140 char CurrentDir[ MaxPathSize ];
04141
04142 RioResult RioStatus;
04143
04144
04145
04146
04147 if( FileName[ 0 ] != '/' )
04148 {
04149
04150 RioStatus = m_Session->GetCurrentDir( CurrentDir, MaxPathSize );
04151 if( FAILED( RioStatus ) )
04152 {
04153 m_RioStatus = RioStatus;
04154
04155 #ifdef RIO_DEBUG2
04156 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
04157 "Erro ao obter o diretorio corrente!" );
04158 PrintErrors();
04159 #endif
04160
04161 return false;
04162 }
04163
04164 Path = CurrentDir;
04165 }
04166 else
04167 {
04168
04169 Path = FileName;
04170 }
04171
04172
04173
04174 if( strcmp( m_UserName, "root") != 0 )
04175 {
04176
04177 char *PosNextBar;
04178
04179
04180 bool isUserFile;
04181
04182 unsigned int PosFirstComponent;
04183
04184
04185 PosFirstComponent = 0;
04186 while( Path[ PosFirstComponent ] == '/' )
04187 PosFirstComponent++;
04188
04189
04190 PosNextBar = strchr( &Path[ PosFirstComponent ], '/' );
04191
04192
04193
04194 if( ( PosNextBar == NULL ) && ( FileName[ 0 ] != '/' ) )
04195 {
04196 #ifdef RIO_DEBUG2
04197 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
04198 "O usuario %s nao pode acessar o arquivo %s!",
04199 m_UserName, FileName );
04200 #endif
04201
04202
04203 m_RioStatus = ERROR_SERVERINTERFACE + ERROR_OBJECT_OPEN_FAILED;
04204
04205 return false;
04206 }
04207
04208
04209
04210 if( PosNextBar != NULL )
04211 *PosNextBar = 0;
04212
04213
04214 isUserFile = ( strcmp( &Path[ PosFirstComponent ], m_UserName ) == 0 );
04215
04216
04217
04218 if( PosNextBar != NULL )
04219 *PosNextBar = '/';
04220
04221
04222
04223 if( !isUserFile )
04224 {
04225 #ifdef RIO_DEBUG2
04226 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
04227 "O usuario %s nao pode acessar o arquivo %s!",
04228 m_UserName, FileName );
04229 #endif
04230
04231
04232 m_RioStatus = ERROR_SERVERINTERFACE + ERROR_OBJECT_OPEN_FAILED;
04233
04234 return false;
04235 }
04236 }
04237
04238 return true;
04239 }
04240
04241
04242
04243 int CServerInterface::ExecuteDownloadCommand( request_rec *Request,
04244 char **Params,
04245 unsigned int TotalParams )
04246 {
04247
04248 int httpResult;
04249
04250 bool SendHeader;
04251
04252 RioObjectSize StartPosition;
04253
04254 ObjectInfo DownloadObjectInfo;
04255
04256
04257 bool Status;
04258
04259
04260 bool SendXML;
04261
04262
04263 SendXML = true;
04264
04265
04266
04267 Status = true;
04268
04269
04270 httpResult = OK;
04271
04272
04273
04274 if( TotalParams < 2 )
04275 {
04276 StartPosition = 0;
04277 SendHeader = false;
04278 }
04279 else
04280 {
04281 StartPosition = atoi( Params[ 2 ] );
04282
04283
04284
04285
04286 if( TotalParams < 3 )
04287 {
04288 SendHeader = false;
04289 }
04290 else
04291 {
04292
04293 if( ( strcasecmp( Params[ 3 ], "on" ) != 0 ) &&
04294 ( strcasecmp( Params[ 3 ], "off" ) != 0 ) )
04295 {
04296 #ifdef RIO_DEBUG2
04297 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
04298 "O parametro %s nao e valido!",
04299 Params[ 3 ] );
04300 #endif
04301
04302 Status = false;
04303 }
04304 else
04305 SendHeader = ( strcasecmp( Params[ 3 ], "on" ) == 0 );
04306 }
04307 }
04308
04309
04310
04311 if( Status )
04312 {
04313 Status = CheckDirectoryPermission( Params[ 1 ] );
04314 if( Status )
04315 {
04316
04317 Status = m_RioExplorer->getObjectInfo( Params[ 1 ], m_Session,
04318 &DownloadObjectInfo, true );
04319
04320
04321
04322 if( Status )
04323 {
04324
04325 if( DownloadObjectInfo.isDir() )
04326 {
04327 m_RioStatus = ERROR_SERVERINTERFACE +
04328 ERROR_OBJECT_IS_DIRECTORY;
04329
04330 #ifdef RIO_DEBUG2
04331 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
04332 "O arquivo %s e um diretorio!",
04333 Params[ 1 ] );
04334 #endif
04335
04336 Status = false;
04337 }
04338 }
04339 else
04340 {
04341
04342 m_RioExplorer->getError( &m_RioStatus, &m_SystemStatus );
04343 }
04344 }
04345 }
04346
04347
04348 if( Status )
04349 {
04350
04351 #ifdef RIO_DEBUG2
04352 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
04353 "Tentando enviar o arquivo %s, a partir do byte %lld. Um "
04354 "cabecalho %s enviado se o arquivo precisar!",
04355 Params[ 1 ], StartPosition,
04356 ( ( SendHeader ) ? "sera" : "nao sera" ) );
04357 #endif
04358
04359
04360 httpResult = DownloadFile( Request, Params[ 1 ], &SendXML,
04361 StartPosition, SendHeader );
04362
04363 #ifdef RIO_DEBUG2
04364
04365 if( httpResult != OK )
04366 {
04367 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
04368 "Erro ao baixar o arquivo %s!", Params[ 1 ] );
04369 }
04370 #endif
04371 }
04372
04373
04374
04375
04376 if( SendXML )
04377 {
04378
04379 GenerateXMLStatus( Request, CMD_DOWNLOAD_ID, m_SessionId );
04380
04381 return OK;
04382 }
04383 else
04384 return httpResult;
04385 }
04386
04387
04388
04389 bool CServerInterface::ExecuteMvCommand( request_rec *Request, char **Params )
04390 {
04391
04392
04393 bool Status;
04394
04395
04396 Status = m_RioExplorer->mv( Params[ 1 ], Params[ 2 ], m_Session, false );
04397
04398 if( !Status )
04399 {
04400
04401 m_RioExplorer->getError( &m_RioStatus, &m_SystemStatus );
04402
04403 #ifdef RIO_DEBUG2
04404 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
04405 "CServerInterface::ExecuteMvCommand Erro ao "
04406 "executar o comando mv do arquivo %s para o %s!",
04407 Params[ 1 ], Params[ 2 ] );
04408 #endif
04409 }
04410
04411
04412 GenerateXMLStatus( Request, CMD_MV_ID, m_SessionId );
04413
04414
04415 return Status;
04416 }
04417
04418
04419
04420 bool CServerInterface::UploadFile( request_rec *Request, const char *FileName,
04421 char *FileMd5sum )
04422 {
04423 RioResult hResult;
04424 int status;
04425 RioObjectSize LastFileSize, FileSize;
04426 const char *FileSizeHeader;
04427 RioObjectSize DataSize;
04428 bool IsApacheEof;
04429 unsigned int TotalElements;
04430 unsigned int TotalBlocks;
04431 unsigned int LastApacheBlockSize;
04432 RioBlock Block;
04433
04434
04435 status = pthread_mutex_lock( &m_Mutex );
04436 if( status < 0 )
04437 {
04438 m_SystemStatus = status;
04439
04440 #ifdef RIO_DEBUG2
04441 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
04442 "Error locking m_Mutex: %u (%s)",
04443 m_SystemStatus, strerror( m_SystemStatus ) );
04444
04445 #endif
04446
04447 return false;
04448 }
04449
04450
04451 if( m_isReadingApacheFile )
04452 {
04453 #ifdef RIO_DEBUG2
04454 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
04455 "A copy is already in progress" );
04456 #endif
04457
04458
04459 m_RioStatus = ERROR_SERVERINTERFACE + ERROR_COPYING_OBJECT;
04460
04461
04462 status = pthread_mutex_unlock( &m_Mutex );
04463 if( status < 0 )
04464 {
04465 m_SystemStatus = status;
04466
04467 #ifdef RIO_DEBUG2
04468 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
04469 "Error unlocking m_Mutex: %u (%s)",
04470 m_SystemStatus, strerror( m_SystemStatus ) );
04471 #endif
04472 }
04473
04474 return false;
04475 }
04476
04477
04478 status = pthread_mutex_unlock( &m_Mutex );
04479 if( status < 0 )
04480 {
04481 m_SystemStatus = status;
04482
04483 #ifdef RIO_DEBUG2
04484 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
04485 "Error unlocking m_Mutex: %u (%s)",
04486 m_SystemStatus, strerror( m_SystemStatus ) );
04487 #endif
04488
04489 return false;
04490 }
04491
04492
04493 if( !OpenRioStream( RioStreamDirectionWrite ) )
04494 {
04495 #ifdef RIO_DEBUG2
04496 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
04497 "Error creating RIO Stream: %u (%s)", m_RioStatus,
04498 GetErrorDescription( m_RioStatus ).c_str() );
04499 #endif
04500
04501 return false;
04502 }
04503
04504
04505 if( !OpenRioObject( FileName, RIO_WRITE_MASK ) )
04506 {
04507 #ifdef RIO_DEBUG2
04508 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
04509 "Error opening RioObject: %u (%s)", m_RioStatus,
04510 GetErrorDescription( m_RioStatus ).c_str() );
04511 #endif
04512
04513 if( !CloseRioStream() )
04514 {
04515 #ifdef RIO_DEBUG2
04516 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
04517 "Error closing RioStream: %u (%s)", m_RioStatus,
04518 GetErrorDescription( m_RioStatus ).c_str() );
04519 #endif
04520 }
04521
04522 return false;
04523 }
04524
04525
04526 FileSizeHeader = apr_table_get( Request->headers_in, "Content-Length" );
04527 if( FileSizeHeader == NULL )
04528 {
04529 #ifdef RIO_DEBUG2
04530 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
04531 "Content-Length header not defined! " );
04532 #endif
04533
04534 if( !Close( Request ) )
04535 {
04536 #ifdef RIO_DEBUG2
04537 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
04538 "Error when executing Close" );
04539 #endif
04540 }
04541
04542 return false;
04543 }
04544 FileSize = atoll( FileSizeHeader );
04545
04546 #ifdef RIO_DEBUG2
04547 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
04548 "FileSize obteined from Content-Length header is %llu bytes!",
04549 FileSize );
04550 #endif
04551
04552
04553 hResult = m_Object->SetSize( 0, FileMd5sum );
04554
04555 if( FAILED( hResult ) )
04556 {
04557 m_RioStatus = hResult;
04558
04559 #ifdef RIO_DEBUG2
04560 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
04561 "Error setting object size to 0: %u (%s)", m_RioStatus,
04562 GetErrorDescription( m_RioStatus ).c_str() );
04563 #endif
04564
04565 if( !Close( Request ) )
04566 {
04567 #ifdef RIO_DEBUG2
04568 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
04569 "Error when executing Close" );
04570 #endif
04571 }
04572
04573 return false;
04574 }
04575
04576
04577 status = pthread_mutex_lock( &m_Mutex );
04578 if( status < 0 )
04579 {
04580 m_SystemStatus = status;
04581
04582 #ifdef RIO_DEBUG2
04583 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
04584 "Error locking m_Mutex: %u (%s)",
04585 m_SystemStatus, strerror( m_SystemStatus ) );
04586 #endif
04587
04588 if( !Close( Request ) )
04589 {
04590 #ifdef RIO_DEBUG2
04591 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
04592 "Error when executing Close" );
04593 #endif
04594 }
04595
04596 return false;
04597 }
04598
04599
04600 m_isReadingApacheFile = true;
04601
04602
04603 m_IsApacheEof = false;
04604 m_UploadRequest = Request;
04605 m_LastApacheBlockSize = 0;
04606 TotalBlocks = ( FileSize + m_BlockSize - 1 ) / m_BlockSize;
04607
04608
04609 if( !m_CircularBuffer->ReinitializeBuffer() )
04610 {
04611 m_SystemStatus = m_CircularBuffer->GetError();
04612
04613 #ifdef RIO_DEBUG2
04614 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
04615 "Error reinitializing circular buffer: %u (%s)",
04616 m_SystemStatus, strerror( m_SystemStatus ) );
04617 #endif
04618
04619
04620 if( !Close( Request ) )
04621 {
04622 #ifdef RIO_DEBUG2
04623 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
04624 "Error when executing Close" );
04625 #endif
04626 }
04627
04628 return false;
04629 }
04630
04631
04632
04633 status = pthread_cond_signal( &m_ReadApacheStarted );
04634 if( status < 0 )
04635 {
04636 m_SystemStatus = status;
04637
04638 #ifdef RIO_DEBUG2
04639 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
04640 "Error signalling m_ReadApacheStarted: %u (%s)",
04641 m_SystemStatus, strerror( m_SystemStatus ) );
04642 #endif
04643
04644 return false;
04645 }
04646
04647
04648 status = pthread_mutex_unlock( &m_Mutex );
04649 if( status < 0 )
04650 {
04651 m_SystemStatus = status;
04652
04653 #ifdef RIO_DEBUG2
04654 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
04655 "Error unlocking m_Mutex: %u (%s)",
04656 m_SystemStatus, strerror( m_SystemStatus ) );
04657 #endif
04658
04659 if( !Close( Request ) )
04660 {
04661 #ifdef RIO_DEBUG2
04662 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
04663 "Error when executing Close" );
04664 #endif
04665 }
04666
04667 return false;
04668 }
04669
04670
04671 Block = 0;
04672 LastFileSize = 0;
04673
04674 #ifdef RIO_DEBUG2
04675 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
04676 "Tentando receber o arquivo %s com %llu bytes e %u blocos!",
04677 FileName, FileSize, TotalBlocks );
04678 #endif
04679
04680
04681 while( Block < TotalBlocks )
04682 {
04683 #ifdef RIO_DEBUG2
04684 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
04685 "Tentando receber o bloco %u de %u do arquivo %s!",
04686 Block, TotalBlocks, FileName );
04687 #endif
04688
04689
04690
04691
04692 if( !m_CircularBuffer->TotalElements( &TotalElements ) )
04693 {
04694 m_SystemStatus = m_CircularBuffer->GetError();
04695
04696 #ifdef RIO_DEBUG2
04697 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
04698 "Error cheking for elementos in circular buffer: "
04699 "%u (%s)", m_SystemStatus,
04700 strerror( m_SystemStatus ) );
04701 #endif
04702
04703
04704 if( !Close( Request ) )
04705 {
04706 #ifdef RIO_DEBUG2
04707 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
04708 "Error when executing Close" );
04709 #endif
04710 }
04711
04712 return false;
04713 }
04714
04715
04716 if( !m_CircularBuffer->GetElement( m_RioBuffer ) )
04717 {
04718 m_SystemStatus = m_CircularBuffer->GetError();
04719
04720 #ifdef RIO_DEBUG2
04721 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
04722 "Error reading block %u from circular buffer: "
04723 "%u (%s)", Block, m_SystemStatus,
04724 strerror( m_SystemStatus ) );
04725 #endif
04726
04727
04728 if( !Close( Request ) )
04729 {
04730 #ifdef RIO_DEBUG2
04731 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
04732 "Error when executing Close" );
04733 #endif
04734 }
04735
04736 return false;
04737 }
04738
04739
04740
04741 status = pthread_mutex_lock( &m_Mutex );
04742 if( status < 0 )
04743 {
04744 m_SystemStatus = status;
04745
04746 #ifdef RIO_DEBUG2
04747 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
04748 "Error locking m_Mutex: %u (%s)",
04749 m_SystemStatus, strerror( m_SystemStatus ) );
04750 #endif
04751
04752
04753 if( !Close( Request ) )
04754 {
04755 #ifdef RIO_DEBUG2
04756 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
04757 "Error when executing Close" );
04758 #endif
04759 }
04760
04761 return false;
04762 }
04763
04764 #ifdef RIO_DEBUG2
04765 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
04766 "Trying to copy block %u", Block );
04767 #endif
04768
04769
04770
04771 IsApacheEof = m_IsApacheEof;
04772 LastApacheBlockSize = m_LastApacheBlockSize;
04773
04774
04775 status = pthread_mutex_unlock( &m_Mutex );
04776 if( status < 0 )
04777 {
04778 m_SystemStatus = status;
04779
04780 #ifdef RIO_DEBUG2
04781 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
04782 "Error unlocking m_Mutex: %u (%s)",
04783 m_SystemStatus, strerror( m_SystemStatus ) );
04784 #endif
04785
04786
04787 if( !Close( Request ) )
04788 {
04789 #ifdef RIO_DEBUG2
04790 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
04791 "Error when executing Close" );
04792 #endif
04793 }
04794
04795 return false;
04796 }
04797
04798
04799
04800
04801 if( Block < ( TotalBlocks - 1 ) )
04802 {
04803
04804
04805
04806 DataSize = m_BlockSize;
04807
04808
04809 if( ( TotalElements == 1 ) && ( IsApacheEof ) &&
04810 ( DataSize != LastApacheBlockSize) )
04811 {
04812 #ifdef RIO_DEBUG2
04813 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
04814 "Unexpected end of data found in saving block "
04815 "%u! Received %u bytes but expected %llu bytes!",
04816 Block, LastApacheBlockSize, DataSize );
04817 #endif
04818
04819
04820 if( !Close( Request ) )
04821 {
04822 #ifdef RIO_DEBUG2
04823 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
04824 "Error when executing Close" );
04825 #endif
04826 }
04827
04828
04829 m_RioStatus = ERROR_SERVERINTERFACE + ERROR_COPYING_OBJECT;
04830
04831 return false;
04832 }
04833 }
04834 else
04835 {
04836
04837
04838 DataSize = FileSize - ( ( TotalBlocks - 1 ) * m_BlockSize );
04839
04840
04841
04842
04843 if( LastApacheBlockSize < DataSize )
04844 {
04845 #ifdef RIO_DEBUG2
04846 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
04847 "Unexpected end of data found in saving block "
04848 "%u! Expected %llu bytes but received %u "
04849 "bytes!", Block, DataSize,
04850 LastApacheBlockSize );
04851 #endif
04852
04853
04854 if( !Close( Request ) )
04855 {
04856 #ifdef RIO_DEBUG2
04857 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
04858 "Error when executing Close" );
04859 #endif
04860 }
04861
04862
04863 m_RioStatus = ERROR_SERVERINTERFACE + ERROR_COPYING_OBJECT;
04864
04865 return false;
04866 }
04867 }
04868
04869 #ifdef RIO_DEBUG2
04870 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
04871 "Trying to save block %u with md5 %s and size %llu "
04872 "of %u bytes!", Block, FileMd5sum, DataSize,
04873 m_BlockSize );
04874 #endif
04875
04876
04877 if( !WriteRioObjectBlock( Block, FileMd5sum, DataSize,
04878 &LastFileSize) )
04879 {
04880 #ifdef RIO_DEBUG2
04881 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
04882 "Error when executing WriteRioObjectBlock!" );
04883 #endif
04884
04885
04886 if( !Close( Request ) )
04887 {
04888 #ifdef RIO_DEBUG2
04889 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
04890 "Error when executing Close" );
04891 #endif
04892 }
04893
04894 return false;
04895 }
04896
04897
04898 if( ( Block == ( TotalBlocks - 1 ) ) && ( ( TotalElements > 1 ) ||
04899 ( LastApacheBlockSize > DataSize ) ) )
04900 {
04901 #ifdef RIO_DEBUG2
04902 unsigned int TotalData;
04903
04904
04905 if( DataSize == m_BlockSize )
04906 TotalData = TotalElements * m_BlockSize;
04907 else
04908 TotalData = ( TotalElements - 1 ) * m_BlockSize +
04909 LastApacheBlockSize;
04910
04911
04912 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
04913 "There exists more data after block %u! Size %llu is "
04914 "incorrect?", Block, FileSize );
04915 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
04916 "Received %u bytes but expected only %llu bytes!",
04917 TotalData, DataSize );
04918 #endif
04919
04920
04921 if( !Close( Request ) )
04922 {
04923 #ifdef RIO_DEBUG2
04924 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
04925 "Error when executing Close" );
04926 #endif
04927 }
04928
04929
04930 m_RioStatus = ERROR_SERVERINTERFACE + ERROR_COPYING_OBJECT;
04931
04932 return false;
04933 }
04934
04935 Block++;
04936 }
04937
04938
04939 if( !Close( Request ) )
04940 {
04941 #ifdef RIO_DEBUG2
04942 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
04943 "Error when executing Close" );
04944 #endif
04945
04946 return false;
04947 }
04948
04949
04950
04951 if( LastFileSize != FileSize )
04952 {
04953
04954 #ifdef RIO_DEBUG2
04955 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
04956 "O arquivo %s foi recebido incorretamente! Recebidos "
04957 "%llu bytes quando esperavamos %llu bytes!", FileName,
04958 LastFileSize, FileSize );
04959 #endif
04960
04961 m_RioStatus = ERROR_SERVERINTERFACE + ERROR_COPYING_OBJECT;
04962
04963 return false;
04964 }
04965 else
04966 {
04967
04968 #ifdef RIO_DEBUG2
04969 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
04970 "O arquivo %s com tamanho %llu foi recebido "
04971 "corretamente!", FileName, FileSize );
04972 #endif
04973
04974 return true;
04975 }
04976 }
04977
04978
04979
04980 bool CServerInterface::ExecuteUploadCommand( request_rec *Request,
04981 char **Params )
04982 {
04983
04984 ObjectInfo UploadObjectInfo;
04985
04986
04987 bool Status;
04988
04989
04990 Status = CheckDirectoryPermission( Params[ 1 ] );
04991
04992
04993
04994 if( Status )
04995 {
04996
04997 Status = m_RioExplorer->getObjectInfo( Params[ 1 ], m_Session,
04998 &UploadObjectInfo, true );
04999
05000
05001
05002 if( Status )
05003 {
05004
05005 if( UploadObjectInfo.isDir() )
05006 {
05007 m_RioStatus = ERROR_SERVERINTERFACE + ERROR_OBJECT_IS_DIRECTORY;
05008
05009 #ifdef RIO_DEBUG2
05010 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
05011 "O arquivo %s e um diretorio!",
05012 Params[ 1 ] );
05013 #endif
05014
05015 Status = false;
05016 }
05017
05018 if( Status )
05019 {
05020
05021
05022 #ifdef RIO_DEBUG2
05023 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
05024 "Tentando remover o arquivo %s!", Params[ 1 ] );
05025 #endif
05026
05027 Status = m_RioExplorer->rm( &UploadObjectInfo, m_Session, false,
05028 false );
05029 if( !Status )
05030 {
05031
05032 m_RioExplorer->getError( &m_RioStatus, &m_SystemStatus );
05033
05034 #ifdef RIO_DEBUG2
05035 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
05036 "Erro ao remover o arquivo %s!",
05037 Params[ 1 ] );
05038 #endif
05039 }
05040 }
05041 }
05042 else
05043 {
05044
05045 m_RioExplorer->getError( &m_RioStatus, &m_SystemStatus );
05046
05047
05048
05049 if( ( m_RioStatus & ERROR_CODE_MASK ) != ERROR_OBJECT_OPEN_FAILED )
05050 {
05051 #ifdef RIO_DEBUG2
05052 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
05053 "Erro ao obter as informacoes do arquivo %s!",
05054 Params[ 1 ] );
05055 #endif
05056 }
05057 else
05058 {
05059
05060
05061 m_RioStatus = S_OK;
05062 m_SystemStatus = 0;
05063 Status = true;
05064 }
05065 }
05066 }
05067
05068
05069 if( Status )
05070 {
05071
05072 #ifdef RIO_DEBUG2
05073 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
05074 "Tentando receber o arquivo %s com md5 igual a %s!",
05075 Params[ 1 ], Params[ 2 ] );
05076 #endif
05077
05078 Status = UploadFile( Request, Params[ 1 ], Params[ 2 ] );
05079 }
05080 #ifdef RIO_DEBUG2
05081 else
05082 {
05083 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
05084 "Erro ao receber o arquivo %s!", Params[ 1 ] );
05085 }
05086 #endif
05087
05088
05089 GenerateXMLStatus( Request, CMD_UPLOAD_ID, m_SessionId );
05090
05091 return true;
05092 }
05093
05094
05095
05096 bool CServerInterface::ExecuteAdduserCommand( request_rec *Request,
05097 char **Params )
05098 {
05099
05100 bool Status;
05101
05102 char *EncryptedPassword;
05103
05104
05105 Status = true;
05106
05107
05108 EncryptedPassword = encryptPassword( Params[ 2 ] );
05109 if( EncryptedPassword == NULL )
05110 {
05111 m_SystemStatus = ENOMEM;
05112 Status = false;
05113
05114 #ifdef RIO_DEBUG2
05115 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
05116 "CServerInterface::ExecuteAdduserCommand Erro ao "
05117 "encriptar a senha do usuario: %u (%s)", m_SystemStatus,
05118 strerror( m_SystemStatus ) );
05119 #endif
05120 }
05121 else
05122 {
05123
05124 m_RioStatus = m_Session->CreateUser( Params[ 1 ], EncryptedPassword );
05125
05126 if( FAILED( m_RioStatus ) )
05127 {
05128 Status = false;
05129
05130 #ifdef RIO_DEBUG2
05131 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
05132 "CServerInterface::ExecuteAdduserCommand Erro ao "
05133 "executar o comando adduser para o usuario %s!",
05134 Params[ 1 ] );
05135 #endif
05136 }
05137
05138
05139 delete[] EncryptedPassword;
05140 }
05141
05142
05143 GenerateXMLStatus( Request, CMD_ADDUSER_ID, m_SessionId );
05144
05145
05146 return Status;
05147 }
05148
05149
05150
05151 bool CServerInterface::ExecuteDeluserCommand( request_rec *Request,
05152 char **Params )
05153 {
05154
05155 bool Status;
05156
05157 char *UserPath;
05158
05159 ObjectInfo UserPathObjectInfo;
05160
05161
05162 Status = true;
05163
05164
05165 try
05166 {
05167 UserPath = new char[ strlen( Params[ 1 ] ) + 2];
05168
05169
05170 strcpy( UserPath, "/" );
05171 strcat( UserPath, Params[ 1 ] );
05172
05173
05174 m_RioStatus = m_Session->RemoveUser( Params[ 1 ] );
05175
05176 if( FAILED( m_RioStatus ) )
05177 {
05178 Status = false;
05179
05180 #ifdef RIO_DEBUG2
05181 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
05182 "CServerInterface::ExecuteDeluserCommand Erro ao "
05183 "executar o comando deluser para o usuario %s!",
05184 Params[ 1 ] );
05185 #endif
05186 }
05187 else
05188 {
05189
05190
05191
05192
05193 Status = m_RioExplorer->getObjectInfo( UserPath, m_Session,
05194 &UserPathObjectInfo, true );
05195
05196
05197
05198 if( Status )
05199 {
05200
05201 Status = m_RioExplorer->rm( &UserPathObjectInfo, m_Session,
05202 false, true );
05203
05204 if( !Status )
05205 {
05206
05207 m_RioExplorer->getError( &m_RioStatus, &m_SystemStatus );
05208
05209 #ifdef RIO_DEBUG2
05210 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
05211 "CServerInterface::ExecuteDeluserCommand "
05212 "Erro ao executar o comando rm no objeto "
05213 "%s!", UserPath );
05214 #endif
05215 }
05216 }
05217 else
05218 {
05219
05220 m_RioExplorer->getError( &m_RioStatus, &m_SystemStatus );
05221
05222 #ifdef RIO_DEBUG2
05223 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
05224 "CServerInterface::ExecuteDeluserCommand Erro "
05225 "ao obter as informacoes do objeto %s!",
05226 UserPath );
05227 #endif
05228 }
05229 }
05230
05231
05232 delete[] UserPath;
05233 }
05234 catch( bad_alloc &ba )
05235 {
05236 #ifdef RIO_DEBUG2
05237 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
05238 "CServerInterface::ExecuteDeluserCommand Erro ao "
05239 "criar a string com o nome do diretorio para o usuario "
05240 "%s!", Params[ 1 ] );
05241 #endif
05242
05243 m_RioStatus = ERROR_SERVERINTERFACE + ERROR_MEMORY;
05244 }
05245
05246
05247 GenerateXMLStatus( Request, CMD_DELUSER_ID, m_SessionId );
05248
05249
05250 return Status;
05251 }
05252
05253
05254
05255 bool CServerInterface::ExecutePasswdCommand( request_rec *Request,
05256 char **Params )
05257 {
05258
05259 bool Status;
05260
05261
05262 char *EncryptedPassword;
05263
05264
05265 Status = true;
05266
05267
05268 EncryptedPassword = encryptPassword( Params[ 2 ] );
05269 if( EncryptedPassword == NULL )
05270 {
05271 m_SystemStatus = ENOMEM;
05272 Status = false;
05273
05274 #ifdef RIO_DEBUG2
05275 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
05276 "CServerInterface::ExecutePasswdCommand Erro ao "
05277 "encriptar a senha do usuario: %u (%s)", m_SystemStatus,
05278 strerror( m_SystemStatus ) );
05279 #endif
05280 }
05281 else
05282 {
05283
05284 m_RioStatus = m_Session->ChangePassword( Params[ 1 ],
05285 EncryptedPassword );
05286
05287 if( FAILED( m_RioStatus ) )
05288 {
05289 Status = false;
05290
05291 #ifdef RIO_DEBUG2
05292 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
05293 "CServerInterface::ExecutePasswdCommand Erro ao "
05294 "executar o comando adduser para o usuario %s!",
05295 Params[ 1 ] );
05296 #endif
05297 }
05298
05299
05300 delete[] EncryptedPassword;
05301 }
05302
05303
05304 GenerateXMLStatus( Request, CMD_PASSWD_ID, m_SessionId );
05305
05306
05307 return Status;
05308 }
05309
05310
05311
05312 bool CServerInterface::ExecuteUserListCommand( request_rec *Request,
05313 char **Params )
05314 {
05315
05316 bool Status;
05317
05318 vector< string > UserList;
05319
05320
05321 Status = true;
05322
05323
05324 m_RioStatus = m_Session->GetUserList( UserList );
05325
05326 if( FAILED( m_RioStatus ) )
05327 {
05328 Status = false;
05329
05330 #ifdef RIO_DEBUG2
05331 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
05332 "CServerInterface::ExecuteUserListCommand Erro ao "
05333 "executar o comando adduser para o usuario %s!",
05334 Params[ 1 ] );
05335 #endif
05336 }
05337
05338
05339 StartXML( Request, CMD_USERLIST_ID );
05340
05341
05342 AddStatusToXML( Request, m_SessionId );
05343
05344
05345 if( Status )
05346 {
05347
05348 for( unsigned int i = 0; i < UserList.size(); i++ )
05349 {
05350 ap_rprintf( Request, "\t<user>%s</user>\n",
05351 UserList[ i ].c_str() );
05352
05353 }
05354 }
05355
05356 EndXML( Request, CMD_USERLIST_ID );
05357
05358
05359 return Status;
05360 }
05361
05362
05363
05364 int CServerInterface::ExecuteCommands( request_rec *Request, char *Command,
05365 bool *RemoveObject,
05366 unsigned int *SessionId )
05367 {
05368
05369 char **Params;
05370
05371
05372
05373 unsigned int CommandPos;
05374
05375
05376 unsigned int CommandId;
05377
05378 bool Status;
05379
05380 unsigned int TotalParams;
05381
05382 unsigned int ParamPos;
05383
05384
05385 bool InvalidParams;
05386
05387
05388 bool SendXmlError;
05389
05390 int HttpResult;
05391
05392
05393
05394 m_RioStatus = S_OK;
05395 m_ApacheStatus = APR_SUCCESS;
05396 m_SystemStatus = 0;
05397
05398
05399 *RemoveObject = false;
05400
05401
05402 if( !m_Started )
05403 {
05404 m_RioStatus = ERROR_SERVERINTERFACE + ERROR_NOT_STARTED;
05405
05406 #ifdef RIO_DEBUG2
05407 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
05408 "The object has not started" );
05409 #endif
05410
05411
05412 GenerateXMLStatus( Request, CMD_INV_ID, 0 );
05413
05414
05415 SaveExecLogLine( Request, Command );
05416
05417 return OK;
05418
05419 }
05420
05421
05422 m_ApacheStatus = apr_tokenize_to_argv( Command, &Params, Request->pool );
05423 if( m_ApacheStatus != APR_SUCCESS )
05424 {
05425
05426
05427
05428
05429 GenerateXMLStatus( Request, CMD_INV_ID, 0 );
05430
05431
05432 SaveExecLogLine( Request, Command );
05433
05434
05435 return OK;
05436 }
05437
05438
05439 ParamPos = 1;
05440 TotalParams = 0;
05441
05442 #ifdef RIO_DEBUG2
05443 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
05444 "String (com o comando) passada a funcao: %s", Command );
05445
05446 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
05447 "Parametro 0 do comando (o comando): %s", Params[ 0 ] );
05448 #endif
05449
05450 while( Params[ ParamPos ] != NULL )
05451 {
05452 #ifdef RIO_DEBUG2
05453 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
05454 "Parametro %u do comando: %s", ParamPos,
05455 Params[ ParamPos ] );
05456 #endif
05457 TotalParams++;
05458 ParamPos++;
05459 }
05460
05461 #ifdef RIO_DEBUG2
05462 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
05463 "Total de parametros no comando %s: %u", Command,
05464 TotalParams );
05465 #endif
05466
05467
05468
05469 CommandPos = 0;
05470 CommandId = CMD_INV_ID;
05471 InvalidParams = false;
05472 SendXmlError = true;
05473 while( ( CommandTable[ CommandPos ].Command != NULL ) &&
05474 ( CommandId == CMD_INV_ID ) && ( !InvalidParams ) )
05475 {
05476
05477
05478 #ifdef RIO_DEBUG2
05479 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
05480 "Comparando com o comando da posicao %u: Command=%s, "
05481 "CommandId=%u,MininumParams=%u,MaximumParams=%u",
05482 CommandPos, CommandTable[ CommandPos ].Command,
05483 CommandTable[ CommandPos ].CommandId,
05484 CommandTable[ CommandPos ].MininumParams,
05485 CommandTable[ CommandPos ].MaximumParams );
05486 #endif
05487
05488 if( strcmp( Params[ 0 ], CommandTable[ CommandPos ].Command ) == 0 )
05489 {
05490
05491
05492
05493 #ifdef RIO_DEBUG2
05494 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
05495 "O comando da posicao %u e igual ao %s. Verificando "
05496 "se o numero de parametros %u esta correto",
05497 CommandPos, Command, TotalParams );
05498 #endif
05499
05500
05501 CommandId = CommandTable[ CommandPos ].CommandId;
05502
05503 if( ( TotalParams < CommandTable[ CommandPos ].MininumParams ) ||
05504 ( TotalParams > CommandTable[ CommandPos ].MaximumParams ) )
05505 {
05506
05507 #ifdef RIO_DEBUG2
05508 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
05509 "Numero de parametros %u do comando %u "
05510 "incorreto!", TotalParams, CommandId );
05511 #endif
05512
05513 m_RioStatus = ERROR_SERVERINTERFACE + ERROR_COMMAND_SYNTAX;
05514
05515
05516 GenerateXMLStatus( Request, CommandId, 0 );
05517
05518
05519 SaveExecLogLine( Request, Command );
05520
05521 return OK;
05522 }
05523 }
05524
05525
05526 CommandPos++;
05527 }
05528
05529
05530 if( ( strcmp( Request->method, "GET" ) != 0 ) &&
05531 ( strcmp( Request->method, "POST" ) != 0 ) &&
05532 ( strcmp( Request->method, "PUT" )))
05533 {
05534
05535
05536 m_ApacheStatus = APR_BADARG;
05537
05538
05539 GenerateXMLStatus( Request, CommandId, 0 );
05540
05541
05542 SaveExecLogLine( Request, Command );
05543
05544 return OK;
05545 }
05546
05547
05548
05549
05550 if( ( ( strcmp( Request->method, "GET" ) == 0 ) &&
05551 ( CommandId == CMD_UPLOAD_ID ) ) ||
05552 ( ( ( strcmp( Request->method, "POST" ) == 0 ) ||
05553 ( strcmp( Request->method, "PUT" ) == 0 ) ) &&
05554 ( CommandId != CMD_UPLOAD_ID ) ) )
05555 {
05556
05557
05558 m_ApacheStatus = APR_BADARG;
05559
05560
05561 GenerateXMLStatus( Request, CommandId, 0 );
05562
05563
05564 SaveExecLogLine( Request, Command );
05565
05566 return OK;
05567 }
05568
05569
05570
05571
05572 if( ( ( m_Session == NULL ) || ( !m_isSessionOpen ) ||
05573 ( m_SessionId == 0 ) ) && ( CommandId != CMD_LOGIN_ID ) )
05574 {
05575 #ifdef RIO_DEBUG2
05576 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
05577 "Sessao nao aberta: m_Session = %ld, m_isSessionOpen = "
05578 "%s e m_SessionId = %u!", ( long ) m_Session,
05579 ( ( m_isSessionOpen ) ? "true": "false" ), m_SessionId );
05580 #endif
05581
05582 m_RioStatus = ERROR_RIOSESSION + ERROR_SESSION_NOT_OPENED;
05583
05584
05585 GenerateXMLStatus( Request, CommandId, 0 );
05586
05587
05588 SaveExecLogLine( Request, Command );
05589
05590 return OK;
05591 }
05592
05593
05594
05595
05596 if( SessionId == NULL )
05597 {
05598
05599
05600
05601
05602
05603 if( ( CommandId != CMD_LOGIN_ID ) && ( CommandId != CMD_INV_ID ) )
05604 {
05605 #ifdef RIO_DEBUG2
05606 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
05607 "Error: sessionid not defined!" );
05608
05609 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
05610 "A opcao sessionid com o identificador da sessao "
05611 "nao foi definida!" );
05612 #endif
05613
05614 m_RioStatus = ERROR_RIOMODULE + ERROR_SESSIONID_NOT_DEFINED;
05615
05616
05617 GenerateXMLStatus( Request, CommandId, 0 );
05618
05619
05620 SaveExecLogLine( Request, Command );
05621
05622 return OK;
05623 }
05624 }
05625 else
05626 {
05627
05628
05629 if( CommandId == CMD_LOGIN_ID )
05630 {
05631 #ifdef RIO_DEBUG2
05632 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
05633 "Error: sessionid already defined!" );
05634
05635 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
05636 "A opcao sessionid com o identificador da sessao "
05637 "%u foi definida para o comando login!",
05638 *SessionId );
05639 #endif
05640
05641 m_RioStatus = ERROR_RIOMODULE + ERROR_SESSIONID_ALREADY_DEFINED;
05642
05643
05644 GenerateXMLStatus( Request, CommandId, 0 );
05645
05646
05647 SaveExecLogLine( Request, Command );
05648
05649 return OK;
05650
05651 }
05652
05653
05654
05655 if( ( *SessionId == 0 ) || ( m_SessionId != *SessionId ) )
05656 {
05657 #ifdef RIO_DEBUG2
05658 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
05659 "O valor da sessao %u e invalido! Deveria ser "
05660 "igual a %u!", *SessionId, m_SessionId );
05661 #endif
05662
05663 m_RioStatus = ERROR_RIOMODULE + ERROR_INVALID_SESSION;
05664
05665
05666 GenerateXMLStatus( Request, CommandId, 0 );
05667
05668
05669 SaveExecLogLine( Request, Command );
05670
05671 return OK;
05672 }
05673 }
05674
05675
05676
05677
05678 HttpResult = OK;
05679
05680
05681 switch( CommandId )
05682 {
05683
05684 case CMD_LOGIN_ID:
05685
05686
05687
05688
05689 try
05690 {
05691
05692 m_UserName = new char[ strlen( Params[ 1 ] ) + 1 ];
05693
05694
05695 strcpy( m_UserName, Params[ 1 ] );
05696
05697 #ifdef RIO_DEBUG2
05698 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
05699 "Tentando executar a funcao "
05700 "ExecuteLoginCommand!" );
05701 #endif
05702 Status = ExecuteLoginCommand( Request, Params );
05703 #ifdef RIO_DEBUG2
05704 if( !Status )
05705 {
05706 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
05707 "Erro ao executar a funcao "
05708 "ExecuteLoginCommand!" );
05709 }
05710 #endif
05711 }
05712 catch( bad_alloc &ba )
05713 {
05714 m_SystemStatus = ENOMEM;
05715
05716 #ifdef RIO_DEBUG2
05717 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
05718 "Erro allocating (bad_alloc, error=%s) m_User: "
05719 "%u (%s)", ba.what(), m_SystemStatus,
05720 strerror( m_SystemStatus ) );
05721 #endif
05722
05723 m_UserName = NULL;
05724
05725 Status = false;
05726 }
05727
05728 break;
05729
05730
05731 case CMD_QUIT_ID:
05732
05733 #ifdef RIO_DEBUG2
05734 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
05735 "Tentando executar a funcao ExecuteQuitCommand!" );
05736 #endif
05737 Status = ExecuteQuitCommand( Request, Params );
05738 #ifdef RIO_DEBUG2
05739 if( !Status )
05740 {
05741 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
05742 "Erro ao executar a funcao ExecuteQuitCommand!"
05743 );
05744 }
05745 #endif
05746
05747
05748
05749
05750 *RemoveObject = Status;
05751
05752 break;
05753
05754
05755 case CMD_SESSIONS_ID:
05756
05757 #ifdef RIO_DEBUG2
05758 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
05759 "Tentando executar a funcao ExecuteSessionsCommand!"
05760 );
05761 #endif
05762 Status = ExecuteSessionsCommand( Request, Params );
05763 #ifdef RIO_DEBUG2
05764 if( !Status )
05765 {
05766 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
05767 "Erro ao executar a funcao "
05768 "ExecuteSessionsCommand!" );
05769 }
05770 #endif
05771
05772 break;
05773
05774
05775 case CMD_LS_ID:
05776
05777 #ifdef RIO_DEBUG2
05778 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
05779 "Tentando executar a funcao ExecuteLsCommand!"
05780 );
05781 #endif
05782 Status = ExecuteLsCommand( Request, Params );
05783 #ifdef RIO_DEBUG2
05784 if( !Status )
05785 {
05786 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
05787 "Erro ao executar a funcao ExecuteLsCommand!" );
05788 }
05789 #endif
05790
05791 break;
05792
05793
05794
05795 case CMD_RM_ID:
05796
05797 #ifdef RIO_DEBUG2
05798 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
05799 "Tentando executar a funcao ExecuteRmCommand!" );
05800 #endif
05801 Status = ExecuteRmCommand( Request, Params );
05802 #ifdef RIO_DEBUG2
05803 if( !Status )
05804 {
05805 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
05806 "Erro ao executar a funcao ExecuteRmCommand!" );
05807 }
05808 #endif
05809
05810 break;
05811
05812
05813 case CMD_MKDIR_ID:
05814
05815 #ifdef RIO_DEBUG2
05816 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
05817 "Tentando executar a funcao ExecuteRmCommand!" );
05818 #endif
05819 Status = ExecuteMkdirCommand( Request, Params );
05820 #ifdef RIO_DEBUG2
05821 if( !Status )
05822 {
05823 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
05824 "Erro ao executar a funcao ExecuteMkdirCommand!" );
05825 }
05826 #endif
05827 break;
05828
05829
05830
05831 case CMD_DOWNLOAD_ID:
05832
05833 #ifdef RIO_DEBUG2
05834 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
05835 "Tentando executar a funcao ExecuteDownloadCommand!"
05836 );
05837 #endif
05838 HttpResult = ExecuteDownloadCommand( Request, Params, TotalParams );
05839 #ifdef RIO_DEBUG2
05840 if( HttpResult != OK )
05841 {
05842 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
05843 "Erro ao executar a funcao "
05844 "ExecuteDownloadCommand, com HttpResult igual "
05845 "a %u", HttpResult );
05846 Status = false;
05847 } else
05848 Status = true;
05849 PrintErrors();
05850 #endif
05851
05852 break;
05853
05854
05855
05856 case CMD_MV_ID:
05857
05858 #ifdef RIO_DEBUG2
05859 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
05860 "Tentando executar a funcao ExecuteMvCommand!"
05861 );
05862 #endif
05863 Status = ExecuteMvCommand( Request, Params );
05864 #ifdef RIO_DEBUG2
05865 if( !Status )
05866 {
05867 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
05868 "Erro ao executar a funcao ExecuteMvCommand!" );
05869 }
05870 #endif
05871
05872 break;
05873
05874
05875
05876 case CMD_UPLOAD_ID:
05877
05878 #ifdef RIO_DEBUG2
05879 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
05880 "Tentando executar a funcao ExecuteUploadCommand!"
05881 );
05882 #endif
05883 Status = ExecuteUploadCommand( Request, Params );
05884 #ifdef RIO_DEBUG2
05885 if( !Status )
05886 {
05887 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
05888 "Erro ao executar a funcao "
05889 "ExecuteUploadCommand!" );
05890 }
05891 PrintErrors();
05892 #endif
05893
05894 break;
05895
05896
05897
05898 case CMD_ADDUSER_ID:
05899
05900 #ifdef RIO_DEBUG2
05901 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
05902 "Tentando executar a funcao ExecuteAdduserCommand!"
05903 );
05904 #endif
05905 Status = ExecuteAdduserCommand( Request, Params );
05906 #ifdef RIO_DEBUG2
05907 if( !Status )
05908 {
05909 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
05910 "Erro ao executar a funcao "
05911 "ExecuteAdduserCommand!" );
05912 }
05913 PrintErrors();
05914 #endif
05915
05916 break;
05917
05918
05919
05920 case CMD_DELUSER_ID:
05921
05922 #ifdef RIO_DEBUG2
05923 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
05924 "Tentando executar a funcao ExecuteDeluserCommand!"
05925 );
05926 #endif
05927 Status = ExecuteDeluserCommand( Request, Params );
05928 #ifdef RIO_DEBUG2
05929 if( !Status )
05930 {
05931 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
05932 "Erro ao executar a funcao "
05933 "ExecuteDeluserCommand!" );
05934 }
05935 PrintErrors();
05936 #endif
05937
05938 break;
05939
05940
05941
05942 case CMD_PASSWD_ID:
05943
05944 #ifdef RIO_DEBUG2
05945 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
05946 "Tentando executar a funcao ExecutePasswdCommand!" );
05947 #endif
05948 Status = ExecutePasswdCommand( Request, Params );
05949 #ifdef RIO_DEBUG2
05950 if( !Status )
05951 {
05952 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
05953 "Erro ao executar a funcao ExecutePasswdCommand!"
05954 );
05955 }
05956 PrintErrors();
05957 #endif
05958
05959 break;
05960
05961
05962
05963 case CMD_USERLIST_ID:
05964
05965 #ifdef RIO_DEBUG2
05966 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
05967 "Tentando executar a funcao "
05968 "ExecuteUserListCommand!" );
05969 #endif
05970 Status = ExecuteUserListCommand( Request, Params );
05971 #ifdef RIO_DEBUG2
05972 if( !Status )
05973 {
05974 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
05975 "Erro ao executar a funcao "
05976 "ExecuteUserListCommand!" );
05977 }
05978 PrintErrors();
05979 #endif
05980
05981 break;
05982
05983
05984 default:
05985 Status = false;
05986 #ifdef RIO_DEBUG2
05987 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
05988 "Entrando na opcao default do case. CommandId = %u!",
05989 CommandId );
05990 #endif
05991
05992
05993
05994
05995 if( CommandId != CMD_INV_ID )
05996 {
05997 m_RioStatus = ERROR_SERVERINTERFACE + ERROR_UNEXPECTED;
05998 CommandId = CMD_INV_ID;
05999 }
06000 else
06001 m_RioStatus = ERROR_SERVERINTERFACE + ERROR_INVALID_COMMAND;
06002
06003 #ifdef RIO_DEBUG2
06004 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
06005 "Foi passado um identificador %u de comando "
06006 "invalido! O erro retornado do RIO sera %8x (%s)!",
06007 CommandId, m_RioStatus,
06008 GetErrorDescription( m_RioStatus ).c_str() );
06009 #endif
06010
06011
06012 GenerateXMLStatus( Request, CommandId, 0 );
06013
06014 break;
06015 }
06016
06017
06018 SaveExecLogLine( Request, Command );
06019
06020
06021
06022
06023 if( CommandId == CMD_QUIT_ID )
06024 {
06025 #ifdef RIO_DEBUG2
06026 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request, "Quit executado! "
06027 " Removendo o usuario e resetando a ID da sessao!" );
06028 #endif
06029
06030
06031 if( m_UserName != NULL )
06032 delete[] m_UserName;
06033 m_UserName = NULL;
06034
06035
06036 m_SessionId = 0;
06037 }
06038
06039
06040
06041 if( ( !Status ) && ( CommandId == CMD_LOGIN_ID ) )
06042 {
06043 if( m_UserName != NULL )
06044 delete[] m_UserName;
06045 }
06046
06047
06048 return HttpResult;
06049 }
06050
06051
06052 bool CServerInterface::Start( char *ServerName, unsigned int CircularBufferSize,
06053 unsigned int FragmentSize,
06054 unsigned int DefaultSessionId,
06055 unsigned int ExecLogPort)
06056 {
06057 int status;
06058
06059
06060 if( m_Started )
06061 {
06062 m_RioStatus = ERROR_SERVERINTERFACE + ERROR_STARTED;
06063
06064 #ifdef RIO_DEBUG2
06065 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
06066 "The module is already started" );
06067 #endif
06068
06069 return false;
06070
06071 }
06072
06073
06074 try
06075 {
06076 m_ServerName = new char[ strlen( ServerName ) + 1 ];
06077 }
06078 catch( bad_alloc &ba )
06079 {
06080 m_SystemStatus = ENOMEM;
06081
06082 #ifdef RIO_DEBUG2
06083 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
06084 "Insufficient memory (bad_alloc, error=%s) to create "
06085 "m_ServerName!", ba.what() );
06086 #endif
06087
06088 return false;
06089 }
06090 strcpy( m_ServerName, ServerName );
06091
06092
06093 try
06094 {
06095 m_RioExplorer = new CModuleRioExplorer( m_Server );
06096 }
06097 catch( bad_alloc &ba )
06098 {
06099
06100 delete[] m_ServerName;
06101 m_ServerName = NULL;
06102
06103
06104 m_SystemStatus = ENOMEM;
06105
06106 #ifdef RIO_DEBUG2
06107 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
06108 "Insufficient memory (bad_alloc, error=%s) to create "
06109 "m_RioExplorer!", ba.what() );
06110 #endif
06111
06112 return false;
06113 }
06114
06115
06116 m_ExecLogPort = ExecLogPort;
06117
06118
06119 m_ThreadCanceled = false;
06120
06121
06122
06123 status = pthread_create( &m_ReadRioThread, NULL, ReadRioThreadFunctionEp,
06124 ( void * ) this );
06125 if( status < 0 )
06126 {
06127
06128 delete[] m_ServerName;
06129 m_ServerName = NULL;
06130
06131
06132 delete m_RioExplorer;
06133
06134
06135 m_SystemStatus = status;
06136
06137 #ifdef RIO_DEBUG2
06138 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
06139 "Error creating copy thread: %u (%s)", m_SystemStatus,
06140 strerror( m_SystemStatus ) );
06141 #endif
06142
06143 return false;
06144
06145 }
06146
06147
06148
06149 status = pthread_create( &m_ReadApacheThread, NULL,
06150 ReadApacheThreadFunctionEp, ( void * ) this );
06151 if( status < 0 )
06152 {
06153 if( m_ReadRioThread != 0 )
06154 {
06155
06156
06157 m_ThreadCanceled = true;
06158
06159
06160
06161 status = pthread_cond_signal( &m_ReadRioStarted );
06162 if( status < 0 )
06163 {
06164 m_SystemStatus = status;
06165
06166 #ifdef RIO_DEBUG2
06167 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
06168 "Error signalling m_ReadRioStarted: %u (%s)",
06169 m_SystemStatus, strerror( m_SystemStatus ) );
06170 #endif
06171
06172 return false;
06173 }
06174
06175
06176 status = pthread_join( m_ReadRioThread, NULL );
06177
06178 if( status < 0 )
06179 {
06180 m_SystemStatus = status;
06181
06182 #ifdef RIO_DEBUG2
06183 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
06184 "Error when joining ReadRioThread: %u (%s)",
06185 m_SystemStatus, strerror( m_SystemStatus ) );
06186 #endif
06187
06188 return false;
06189 }
06190 }
06191
06192
06193 delete[] m_ServerName;
06194 m_ServerName = NULL;
06195
06196
06197 delete m_RioExplorer;
06198
06199
06200 m_SystemStatus = status;
06201
06202 #ifdef RIO_DEBUG2
06203 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
06204 "Error creating copy thread: %u (%s)", m_SystemStatus,
06205 strerror( m_SystemStatus ) );
06206 #endif
06207
06208 return false;
06209
06210 }
06211
06212
06213 m_DefaultSessionId = DefaultSessionId;
06214
06215
06216 m_FragmentSize = FragmentSize;
06217
06218
06219 m_CircularBufferSize = CircularBufferSize;
06220
06221
06222
06223 m_Started = true;
06224
06225 return true;
06226 }
06227
06228
06229 bool CServerInterface::Stop()
06230 {
06231 int status;
06232
06233
06234 if( !m_Started )
06235 {
06236 m_RioStatus = ERROR_SERVERINTERFACE + ERROR_NOT_STARTED;
06237
06238 #ifdef RIO_DEBUG2
06239 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
06240 "The object has not started" );
06241 #endif
06242
06243 return false;
06244
06245 }
06246
06247
06248 if( m_ReadRioThread != 0 )
06249 {
06250
06251
06252 m_ThreadCanceled = true;
06253
06254
06255 status = pthread_cond_signal( &m_ReadRioStarted );
06256 if( status < 0 )
06257 {
06258 m_SystemStatus = status;
06259
06260 #ifdef RIO_DEBUG2
06261 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
06262 "Error signalling m_ReadRioStarted: %u (%s)",
06263 m_SystemStatus, strerror( m_SystemStatus ) );
06264 #endif
06265
06266 return false;
06267 }
06268
06269
06270 status = pthread_join( m_ReadRioThread, NULL );
06271
06272 if( status < 0 )
06273 {
06274 m_SystemStatus = status;
06275
06276 #ifdef RIO_DEBUG2
06277 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
06278 "Error when joining ReadRioThread: %u (%s)",
06279 m_SystemStatus, strerror( m_SystemStatus ) );
06280 #endif
06281
06282 return false;
06283 }
06284 }
06285
06286
06287 if( m_ReadApacheThread != 0 )
06288 {
06289
06290
06291 m_ThreadCanceled = true;
06292
06293
06294 status = pthread_cond_signal( &m_ReadApacheStarted );
06295 if( status < 0 )
06296 {
06297 m_SystemStatus = status;
06298
06299 #ifdef RIO_DEBUG2
06300 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
06301 "Error signalling m_ReadApacheStarted: %u (%s)",
06302 m_SystemStatus, strerror( m_SystemStatus ) );
06303 #endif
06304
06305 return false;
06306 }
06307
06308
06309 status = pthread_join( m_ReadApacheThread, NULL );
06310
06311 if( status < 0 )
06312 {
06313 m_SystemStatus = status;
06314
06315 #ifdef RIO_DEBUG2
06316 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
06317 "Error when joining ReadApacheThread: %u (%s)",
06318 m_SystemStatus, strerror( m_SystemStatus ) );
06319 #endif
06320
06321 return false;
06322 }
06323 }
06324
06325
06326
06327 if( m_Session != NULL )
06328 {
06329 status = Disconnect();
06330 if( !status )
06331 {
06332 #ifdef RIO_DEBUG2
06333 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
06334 "Error when disconnecting from server" );
06335 #endif
06336
06337 return false;
06338 }
06339 }
06340
06341
06342 if( m_ServerName != NULL )
06343 delete m_ServerName;
06344
06345
06346 if( m_RioExplorer != NULL )
06347 delete m_RioExplorer;
06348 m_RioExplorer = NULL;
06349
06350 m_Started = false;
06351
06352 return true;
06353 }
06354
06355
06356
06357 void CServerInterface::GetErrors( apr_status_t *ApacheStatus, int *SystemStatus,
06358 RioResult *RioStatus )
06359 {
06360 if( ( ApacheStatus != NULL ) && ( m_ApacheStatus != APR_SUCCESS ) )
06361 *ApacheStatus = m_ApacheStatus;
06362 if( ( SystemStatus != NULL ) && ( m_SystemStatus != 0 ) )
06363 *SystemStatus = m_SystemStatus;
06364 if( ( RioStatus != NULL ) && ( m_RioStatus != S_OK ) )
06365 *RioStatus = m_RioStatus;
06366 }
06367
06368
06369
06370 bool CServerInterface::NoError()
06371 {
06372 return( ( m_ApacheStatus == APR_SUCCESS) && ( m_SystemStatus == 0 ) &&
06373 ( m_RioStatus == S_OK ) );
06374 }
06375
06376
06377 void CServerInterface::GenerateXMLError( request_rec *Request,
06378 apr_status_t ApacheStatus,
06379 int SystemStatus, RioResult RioStatus )
06380 {
06381 #ifdef RIO_DEBUG2
06382 ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, Request,
06383 "Tentando gerar o XML para os seguintes erros: Apache = %u, "
06384 "Sistema = %u e Rio = %08x", ApacheStatus, SystemStatus,
06385 RioStatus );
06386 #endif
06387
06388 StartXML( Request, CMD_INV_ID );
06389 AddErrorToXML( Request, ApacheStatus, SystemStatus, RioStatus );
06390 EndXML( Request, CMD_INV_ID );
06391 }
06392
06393
06394
06395 void CServerInterface::SaveExecLogLineError( request_rec *Request,
06396 apr_status_t ApacheStatus,
06397 int SystemStatus,
06398 RioResult RioStatus,
06399 const char *Command,
06400 unsigned int ExecPort )
06401 {
06402
06403
06404 GenerateExecLogLine( Request, NULL, 0, ApacheStatus, SystemStatus,
06405 RioStatus, Command, ExecPort );
06406 }
06407
06408
06409 void CServerInterface::PrintErrors()
06410 {
06411
06412 if( m_RioStatus != S_OK )
06413 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
06414 "RioError = %8X (%s)", m_RioStatus,
06415 GetErrorDescription( m_RioStatus ).c_str() );
06416
06417
06418 if( m_ApacheStatus != APR_SUCCESS )
06419 {
06420 char ApacheStrError[ MAXAPACHESTRERRORSIZE ];
06421
06422
06423 apr_strerror( m_ApacheStatus, ApacheStrError,
06424 MAXAPACHESTRERRORSIZE );
06425
06426 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
06427 "ApacheError = %u (%s)", m_ApacheStatus, ApacheStrError );
06428 }
06429
06430
06431 if( m_SystemStatus != 0 )
06432 ap_log_error( APLOG_MARK, APLOG_ERR, 0, m_Server,
06433 "SystemError = %u (%s)", m_SystemStatus,
06434 strerror( m_SystemStatus ) );
06435 }
06436
06437
06438
06439 server_rec *CServerInterface::GetServer()
06440 {
06441 return m_Server;
06442 }