base
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
#!/bin/sh
|
||||
./testclient localhost 13113 test.xml
|
||||
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<CloudStorage>
|
||||
<!-- Type : Open(개통), Move(RC 변경) -->
|
||||
<Job Type="Open">
|
||||
<UserID>totodisk05</UserID>
|
||||
<USER_SEQ>158</USER_SEQ>
|
||||
<Password>MD5 hasd password</Password>
|
||||
<ServiceID>softline2009</ServiceID>
|
||||
<SVC_SEQ>240</SVC_SEQ>
|
||||
<StgSize>322122547200</StgSize>
|
||||
<!-- Bytes : 1024 = 1KB -->
|
||||
<StartDate>2013-01-01</StartDate>
|
||||
<EndDate>2013-12-31</EndDate>
|
||||
<SvcAuthString>icsauth</SvcAuthString>
|
||||
<SvcPrivatekey>key</SvcPrivatekey>
|
||||
<Replica>3</Replica>
|
||||
<UriIgnoreCase>Y</UriIgnoreCase>
|
||||
<DelFileKeepTime>3</DelFileKeepTime>
|
||||
<TransferLogCollect_YN>3</TransferLogCollect_YN>
|
||||
<UsedSizeCalcDepth>1</UsedSizeCalcDepth>
|
||||
<Service_Domain>softline2009.ktsh.co.kr</Service_Domain>
|
||||
<!-- rc_syncd 지원하기 위한 정보 -->
|
||||
<!-- 일반적인 경우 : Master_YN : N, LinkServiceSeq : 없음, LinkRCTS : 없음 -->
|
||||
<!-- Master 경우: Master_YN : Y, LinkServiceSeq : Slave Servcie SEQ, LinkRCTS : Slave RCTS -->
|
||||
<!-- Slave 경우 : Master_YN : N, LinkServiceSeq : Master Servcie SEQ, LinkRCTS : Master RCTS -->
|
||||
<Master_YN></Master_YN>
|
||||
<LinkServiceSeq></LinkServiceSeq>
|
||||
<LinkRCTS ></LinkRCTS>
|
||||
<Etc>토토디스크</Etc>
|
||||
</Job>
|
||||
</CloudStorage>
|
||||
@@ -0,0 +1,96 @@
|
||||
#include <errno.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <fcntl.h>
|
||||
#include "FixedQueue.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
void *_entry_func(void *arg)
|
||||
{
|
||||
CFixedQueue *q = (CFixedQueue*)arg;
|
||||
for (int i = 0; i < 50; ++i)
|
||||
{
|
||||
|
||||
char p[1204] = {0};
|
||||
sprintf(p, "########## %i", i);
|
||||
int r = q->Push(p, strlen(p));
|
||||
cout << "Tread Push : " << p << "," << r << endl;
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *_entry_func2(void *arg)
|
||||
{
|
||||
CFixedQueue *q = (CFixedQueue*)arg;
|
||||
for (int i = 0; i < 30; ++i)
|
||||
{
|
||||
char p[1204] = {0};
|
||||
int r = q->Pop(p, sizeof(p));
|
||||
cout << "Tread Pop(1) : " << p << "," << r << endl;
|
||||
sleep(4);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *_entry_func3(void *arg)
|
||||
{
|
||||
CFixedQueue *q = (CFixedQueue*)arg;
|
||||
for (int i = 0; i < 20; ++i)
|
||||
{
|
||||
char p[1204] = {0};
|
||||
int r = q->Pop(p, sizeof(p));
|
||||
cout << "Tread Pop(2) : " << p << "," << r << endl;
|
||||
sleep(2);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main ( int argc, char * argv[] )
|
||||
{
|
||||
CFixedQueue q(2048, 50);
|
||||
|
||||
char * p = "12345";
|
||||
|
||||
q.Push(p, strlen(p));
|
||||
|
||||
char temp[1204] = {0};
|
||||
q.Pop(temp, sizeof(temp));
|
||||
|
||||
cout << "#### "<< temp << endl;
|
||||
|
||||
pthread_t workerthread = 0;
|
||||
|
||||
// start thread
|
||||
int ret = pthread_create(&workerthread, 0, _entry_func, (void*)&q);
|
||||
if (ret != 0)
|
||||
{
|
||||
cerr << "Client Thread create failed.[" << errno << "]";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
ret = pthread_create(&workerthread, 0, _entry_func2, (void*)&q);
|
||||
if (ret != 0)
|
||||
{
|
||||
cerr << "Client Thread create2 failed.[" << errno << "]";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
cout << "############### " << endl;
|
||||
|
||||
ret = pthread_create(&workerthread, 0, _entry_func3, (void*)&q);
|
||||
if (ret != 0)
|
||||
{
|
||||
cerr << "Client Thread create2 failed.[" << errno << "]";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
// ±×³É ½Ã±×³Î ´ë±â
|
||||
pause();
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
#!/bin/sh
|
||||
g++ testQueue.cpp -o testQueue -I./. -I../lib ../lib/libInterCommon.a -lpthread
|
||||
@@ -0,0 +1,143 @@
|
||||
#include <errno.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <fcntl.h>
|
||||
#include <arpa/inet.h>
|
||||
#include "BaseSocket.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
class CServerSocket : public CBaseSocket
|
||||
{
|
||||
public:
|
||||
|
||||
/// @brief 생성자.
|
||||
CServerSocket( const int & socket)
|
||||
: CBaseSocket(socket) { };
|
||||
|
||||
/// @brief 소멸자.
|
||||
~CServerSocket() { Close(); };
|
||||
|
||||
ssize_t ReadEx( void * vptr, size_t size )
|
||||
{ return Read(vptr, size); };
|
||||
|
||||
};
|
||||
|
||||
int main ( int argc, char * argv[] )
|
||||
{
|
||||
if(argc != 4)
|
||||
{
|
||||
cerr << argv[0] << " server port file" << endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
CServerSocket server(SOCKET_NOT_VALID);
|
||||
if(server.Connect(argv[1], atoi(argv[2])))
|
||||
{
|
||||
cout << "connected : " << argv[1] << "," << argv[2]<< "," << argv[3] << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "failed connection : " << errno << endl;
|
||||
}
|
||||
|
||||
int f = open( argv[3], O_RDONLY );
|
||||
|
||||
string sendval;
|
||||
if(f > 0 )
|
||||
{
|
||||
while(true)
|
||||
{
|
||||
char szBuffer[1024] = {0};
|
||||
int n = 0;
|
||||
if((n = read(f, szBuffer,sizeof(szBuffer))) <=0)
|
||||
break;
|
||||
|
||||
sendval.append(szBuffer,n);
|
||||
}
|
||||
|
||||
close( f );
|
||||
}
|
||||
else
|
||||
{
|
||||
cerr << "The file '"<< argv[3] << "' was not opened" <<endl;
|
||||
}
|
||||
|
||||
cout << "Send Data : " << sendval << ",Size : " << sendval.size () << endl;
|
||||
|
||||
// send header
|
||||
int sH = htonl(sendval.size());
|
||||
if(server.WriteN( &sH, 4 ) > 0)
|
||||
{
|
||||
cout << "Send success.[Header]"<< endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
cerr << "Send fail.[Header]" << errno << endl;
|
||||
}
|
||||
|
||||
// send body
|
||||
if(server.WriteN( sendval.c_str(), sendval.size () ) > 0)
|
||||
{
|
||||
cout << "Send success.[Body]"<< endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
cerr << "Send fail.[Body]" << errno << endl;
|
||||
}
|
||||
|
||||
// read header
|
||||
int nR = 0;
|
||||
ssize_t r = server.ReadEx( &nR, 4);
|
||||
|
||||
if(r < 0 )
|
||||
{
|
||||
cerr << "Socket Read Error.[Header]" << errno << endl;
|
||||
}
|
||||
else if ( r == 0)
|
||||
{
|
||||
cerr << "Server closed.[Header]" << errno << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
nR = ntohl(nR);
|
||||
|
||||
cout << "Resv success.[Header]," << nR << endl;
|
||||
}
|
||||
|
||||
// read body
|
||||
string readval;
|
||||
while(nR > 0)
|
||||
{
|
||||
char szBuffer[1024] = {0};
|
||||
ssize_t r = server.ReadEx( szBuffer, sizeof(szBuffer) );
|
||||
|
||||
if(r < 0 )
|
||||
{
|
||||
cerr << "Socket Read Error." << errno << endl;
|
||||
break;
|
||||
}
|
||||
else if ( r == 0)
|
||||
{
|
||||
cerr << "Server closed." << errno << endl;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
readval.append(szBuffer, r);
|
||||
}
|
||||
}
|
||||
|
||||
if(!readval.empty())
|
||||
{
|
||||
cout << "Read Data : " << readval << ", Size = " << readval.size() << endl;
|
||||
}
|
||||
|
||||
cout << "end" << endl;
|
||||
|
||||
// 그냥 시그널 대기
|
||||
pause();
|
||||
|
||||
server.Close();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
#!/bin/sh
|
||||
g++ testclient.cpp -o testclient -I./. -I../lib ../lib/libInterCommon.a `pkg-config libxml++-2.6 --cflags --libs`
|
||||
@@ -0,0 +1,196 @@
|
||||
#include <errno.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <fcntl.h>
|
||||
#include <arpa/inet.h>
|
||||
#include "openssl/ssl.h"
|
||||
#include "openssl/bio.h"
|
||||
#include "openssl/err.h"
|
||||
#include "BaseSocket.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
class CServerSocket : public CBaseSocket
|
||||
{
|
||||
public:
|
||||
|
||||
/// @brief 생성자.
|
||||
CServerSocket( const int & socket)
|
||||
: CBaseSocket(socket) { };
|
||||
|
||||
/// @brief 소멸자.
|
||||
~CServerSocket() { Close(); };
|
||||
|
||||
ssize_t ReadEx( void * vptr, size_t size )
|
||||
{ return Read(vptr, size); };
|
||||
|
||||
};
|
||||
|
||||
int main ( int argc, char * argv[] )
|
||||
{
|
||||
if(argc != 4)
|
||||
{
|
||||
cerr << argv[0] << " server port file" << endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
int f = open( argv[3], O_RDONLY );
|
||||
|
||||
string sendval;
|
||||
if(f > 0 )
|
||||
{
|
||||
while(true)
|
||||
{
|
||||
char szBuffer[1024] = {0};
|
||||
int n = 0;
|
||||
if((n = read(f, szBuffer,sizeof(szBuffer))) <=0)
|
||||
break;
|
||||
|
||||
sendval.append(szBuffer,n);
|
||||
}
|
||||
|
||||
close( f );
|
||||
}
|
||||
else
|
||||
{
|
||||
cerr << "The file '"<< argv[3] << "' was not opened" <<endl;
|
||||
}
|
||||
|
||||
cout << "Send Data : " << sendval << ",Size : " << sendval.size () << endl;
|
||||
|
||||
BIO * bio;
|
||||
SSL * ssl;
|
||||
SSL_CTX * ctx = NULL;
|
||||
SSL_METHOD *meth;
|
||||
|
||||
/* Set up the library */
|
||||
SSL_library_init();
|
||||
//ERR_load_BIO_strings();
|
||||
SSL_load_error_strings();
|
||||
|
||||
/* Setup the connection */
|
||||
meth = (SSL_METHOD*)SSLv3_method();
|
||||
|
||||
/* Set up the SSL context */
|
||||
ctx = SSL_CTX_new(meth);
|
||||
if(ctx == NULL )
|
||||
{
|
||||
cerr << "Error ctx" << endl;
|
||||
ERR_print_errors_fp(stderr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
bio = BIO_new_ssl_connect(ctx);
|
||||
|
||||
/* Set the SSL_MODE_AUTO_RETRY flag */
|
||||
|
||||
BIO_get_ssl(bio, & ssl);
|
||||
SSL_set_mode(ssl, SSL_MODE_AUTO_RETRY);
|
||||
|
||||
/* Create and setup the connection */
|
||||
ostringstream connstr;
|
||||
connstr << argv[1] << ":" << argv[2];
|
||||
BIO_set_conn_hostname(bio, connstr.str().c_str());
|
||||
|
||||
if(BIO_do_connect(bio) <= 0)
|
||||
{
|
||||
cerr << "Error attempting to connect" << endl;
|
||||
ERR_print_errors_fp(stderr);
|
||||
BIO_free_all(bio);
|
||||
SSL_CTX_free(ctx);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// send header
|
||||
int nH = htonl(sendval.size());
|
||||
if( BIO_write(bio, &nH, 4) <= 0 )
|
||||
{
|
||||
cerr << "Send fail.[Header]" << endl;
|
||||
//printf("Failed write\n");
|
||||
ERR_print_errors_fp(stderr);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "Send success.[Header]"<< endl;
|
||||
}
|
||||
|
||||
// send body
|
||||
if( BIO_write(bio, sendval.c_str(), sendval.size()) <= 0 )
|
||||
{
|
||||
cerr << "Send fail.[Body]" << endl;
|
||||
//printf("Failed write\n");
|
||||
ERR_print_errors_fp(stderr);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "Send success.[Body]"<< endl;
|
||||
|
||||
}
|
||||
|
||||
// read header
|
||||
int nR = 0;
|
||||
int r = BIO_read(bio, &nR, 4);
|
||||
if(r < 0 )
|
||||
{
|
||||
cerr << "Socket Read Error.[Header]" << errno << endl;
|
||||
ERR_print_errors_fp(stderr);
|
||||
return 1;
|
||||
}
|
||||
else if ( r == 0)
|
||||
{
|
||||
cerr << "Server closed.[Header]" << errno << endl;
|
||||
ERR_print_errors_fp(stderr);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
nR = ntohl(nR);
|
||||
|
||||
cout << "Resv success.[Header]," << nR << endl;
|
||||
}
|
||||
|
||||
// read body
|
||||
string readval;
|
||||
while(nR > 0)
|
||||
{
|
||||
char szBuffer[1025] = {0};
|
||||
r = BIO_read(bio, szBuffer, 1024);
|
||||
|
||||
if(r < 0 )
|
||||
{
|
||||
cerr << "Socket Read Error." << endl;
|
||||
ERR_print_errors_fp(stderr);
|
||||
break;
|
||||
}
|
||||
else if ( r == 0)
|
||||
{
|
||||
cerr << "Server closed." << endl;
|
||||
ERR_print_errors_fp(stderr);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
szBuffer[r] = 0;
|
||||
readval.append(szBuffer, r);
|
||||
}
|
||||
}
|
||||
|
||||
if(!readval.empty())
|
||||
{
|
||||
cout << "Read Data : " << readval << ", Size = " << readval.size() << endl;
|
||||
}
|
||||
|
||||
cout << "end" << endl;
|
||||
|
||||
// 그냥 시그널 대기
|
||||
pause();
|
||||
|
||||
/* Close the connection and free the context */
|
||||
BIO_free_all(bio);
|
||||
SSL_CTX_free(ctx);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
Executable
+2
@@ -0,0 +1,2 @@
|
||||
#!/bin/sh
|
||||
g++ testclientssl.cpp -o testclientssl -I./. -I../lib ../lib/libInterCommon.a `pkg-config libxml++-2.6 --cflags --libs` -lpthread -lssl
|
||||
@@ -0,0 +1,123 @@
|
||||
#include "openssl/ssl.h"
|
||||
#include "openssl/bio.h"
|
||||
#include "openssl/err.h"
|
||||
|
||||
#include "stdio.h"
|
||||
#include "string.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
BIO * bio;
|
||||
SSL * ssl;
|
||||
SSL_CTX * ctx = NULL;
|
||||
SSL_METHOD *meth;
|
||||
|
||||
int p;
|
||||
|
||||
//char * request = "GET / HTTP/1.1\x0D\x0AHost: www.verisign.com\x0D\x0A\x43onnection: Close\x0D\x0A\x0D\x0A";
|
||||
char * request = "<?xml version=\"1.0\" encoding=\"utf-8\"?><CloudStorage><Job Type=\"Change\" List=\"ServiceStatus\"><VolumeID>softline2009@totodisk05</VolumeID><StatusCode>SVC_STATUS_ING</StatusCode></Job></CloudStorage>";
|
||||
char r[1024];
|
||||
|
||||
/* Set up the library */
|
||||
SSL_library_init();
|
||||
//ERR_load_BIO_strings();
|
||||
SSL_load_error_strings();
|
||||
|
||||
meth=SSLv3_method();
|
||||
|
||||
/* Set up the SSL context */
|
||||
ctx = SSL_CTX_new(meth);
|
||||
if(ctx == NULL )
|
||||
{
|
||||
fprintf(stderr, "Error ctx\n");
|
||||
ERR_print_errors_fp(stderr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// 2014.07.10 rc_mngd 는 인증서 필요 없이도 SSL 사용한 데이터 통신 가능함
|
||||
/* Load the trust store */
|
||||
//if(! SSL_CTX_load_verify_locations(ctx, "/user/service/etc/rc_mmngd_CA.pem", "/user/service/etc/"))
|
||||
//{
|
||||
// fprintf(stderr, "Error loading trust store\n");
|
||||
// ERR_print_errors_fp(stderr);
|
||||
// SSL_CTX_free(ctx);
|
||||
// return 0;
|
||||
//}
|
||||
|
||||
/* Setup the connection */
|
||||
|
||||
bio = BIO_new_ssl_connect(ctx);
|
||||
|
||||
/* Set the SSL_MODE_AUTO_RETRY flag */
|
||||
|
||||
BIO_get_ssl(bio, & ssl);
|
||||
SSL_set_mode(ssl, SSL_MODE_AUTO_RETRY);
|
||||
|
||||
/* Create and setup the connection */
|
||||
|
||||
//BIO_set_conn_hostname(bio, "www.verisign.com:https");
|
||||
BIO_set_conn_hostname(bio, "localhost:13112");
|
||||
|
||||
if(BIO_do_connect(bio) <= 0)
|
||||
{
|
||||
fprintf(stderr, "Error attempting to connect\n");
|
||||
ERR_print_errors_fp(stderr);
|
||||
BIO_free_all(bio);
|
||||
SSL_CTX_free(ctx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 2014.07.10 rc_mngd 는 인증서 필요 없이도 SSL 사용한 데이터 통신 가능함
|
||||
/* Check the certificate */
|
||||
//if(SSL_get_verify_result(ssl) != X509_V_OK)
|
||||
//{
|
||||
// fprintf(stderr, "Certificate verification error: %i\n", SSL_get_verify_result(ssl));
|
||||
// BIO_free_all(bio);
|
||||
// SSL_CTX_free(ctx);
|
||||
// return 0;
|
||||
//}
|
||||
|
||||
/* Send the request */
|
||||
int nH = htonl(strlen(request));
|
||||
if( BIO_write(bio, &nH, 4) <= 0 )
|
||||
{
|
||||
printf("Failed write\n");
|
||||
ERR_print_errors_fp(stderr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if( BIO_write(bio, request, strlen(request)) <= 0 )
|
||||
{
|
||||
printf("Failed write\n");
|
||||
ERR_print_errors_fp(stderr);
|
||||
return 0;
|
||||
}
|
||||
/* Read in the response */
|
||||
|
||||
for(;;)
|
||||
{
|
||||
p = BIO_read(bio, r, 1023);
|
||||
if(p == 0)
|
||||
{
|
||||
printf("read end\n");
|
||||
ERR_print_errors_fp(stderr);
|
||||
break;
|
||||
}
|
||||
else if(p < 0)
|
||||
{
|
||||
printf("Failed read \n");
|
||||
ERR_print_errors_fp(stderr);
|
||||
break;
|
||||
}
|
||||
else {}
|
||||
|
||||
r[p] = 0;
|
||||
printf("%s", r);
|
||||
}
|
||||
/* Close the connection and free the context */
|
||||
BIO_free_all(bio);
|
||||
SSL_CTX_free(ctx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
#!/bin/sh
|
||||
gcc testssl.c -o testssl -g -I./. -I../lib ../lib/libInterCommon.a `pkg-config libxml++-2.6 --cflags --libs` -lpthread -lssl
|
||||
Reference in New Issue
Block a user