95 lines
2.6 KiB
C
95 lines
2.6 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
|
|
#include "VSConfig.h"
|
|
|
|
#include "ZMQLayout.h"
|
|
|
|
#include "AWSMCall.h"
|
|
|
|
#define CallXXX(XXX, XXXLEN) \
|
|
if( psZMQBuf->iBufLen >= (XXXLEN) && !strncmp(psZMQBuf->pcBuf, (#XXX), (XXXLEN))) \
|
|
{ \
|
|
psReply = Call##XXX (psZMQBuf->pcBuf + (XXXLEN), psZMQBuf->iBufLen - (XXXLEN)); \
|
|
}
|
|
|
|
static char pcAddress[512] = "tcp://localhost:60006";
|
|
|
|
int main()
|
|
{
|
|
int rv = AWSMCallInit();
|
|
if(rv) { printf("rv = %x", rv); return 0; }
|
|
|
|
static char pcIP[128] = "localhost";
|
|
static char pcPort[32] = "60006";
|
|
|
|
VSConfig_s psConfig[] =
|
|
VSConfigStart
|
|
VSConfigString("IP", pcIP, 128, "IP")
|
|
VSConfigString("Port", pcPort, 32, "Port")
|
|
VSConfigEnd
|
|
|
|
if(!VSConfig(psConfig, "../config/AWSMRPC.conf") || !VSConfig(psConfig, "/etc/awconfig/AWSMRPC.conf"))
|
|
snprintf(pcAddress, 512, "tcp://%s:%s", pcIP, pcPort);
|
|
|
|
printf("%s\n", pcAddress);
|
|
pZMQ_s psZMQ = ZMQServerInit(pcAddress);
|
|
if(!psZMQ) { printf("ZMQServerInit fail\n"); return 0; }
|
|
|
|
int iCnt = 0;
|
|
|
|
pZMQBuf_s psZMQBuf = NULL;
|
|
pAWSMProtobuf_s psReply = NULL;
|
|
while(1)
|
|
{
|
|
psZMQBuf = ZMQRecv(psZMQ, -1);
|
|
if(!psZMQBuf) { printf("ZMQRecv fail\n"); break; }
|
|
|
|
CallXXX(HashInit, 8)
|
|
else CallXXX(HashUpdate, 10)
|
|
else CallXXX(HashFinal, 9)
|
|
else CallXXX(Hash, 4)
|
|
else CallXXX(Rand, 4)
|
|
else CallXXX(SignatureByIntPrikey, 20)
|
|
else CallXXX(SignatureByExtPrikey, 20)
|
|
else CallXXX(VerifySignature, 15)
|
|
else CallXXX(SM2EncryptByExtPubKey, 21)
|
|
else CallXXX(SM2DecryptByExtPrikey, 21)
|
|
else CallXXX(SM2DecryptByIntPrikey, 21)
|
|
else CallXXX(SM2DecryptByIntCryptPrikey, 26)
|
|
else CallXXX(SM1Encrypt, 10)
|
|
else CallXXX(SM1Decrypt, 10)
|
|
else CallXXX(SM4Encrypt, 10)
|
|
else CallXXX(SM4Decrypt, 10)
|
|
else CallXXX(GenerateECCKeyPair, 18)
|
|
else CallXXX(ExportPubkey, 12)
|
|
else CallXXX(ImportKeyPair, 13)
|
|
else CallXXX(ImportCertificate, 17)
|
|
else CallXXX(ExportCertificate, 17)
|
|
else CallXXX(ImportFile, 10)
|
|
else CallXXX(ExportFile, 10)
|
|
else CallXXX(GetHwcode, 9)
|
|
else CallXXX(GetDevInfo, 10)
|
|
|
|
if(psReply)
|
|
{
|
|
ZMQSend(psZMQ, psReply->pcBuf, psReply->iBufLen);
|
|
AWSMProtobufDestroy(psReply); psReply = NULL;
|
|
}
|
|
else
|
|
{
|
|
ZMQSend(psZMQ, "{ \"code\":501, \"msg\"=\"Unknow method\" }", 38);
|
|
}
|
|
if(psZMQBuf) ZMQBufDestroy(psZMQBuf); psZMQBuf = NULL;
|
|
|
|
}
|
|
|
|
ZMQDestroy(psZMQ);
|
|
|
|
AWSMCallDestroy();
|
|
|
|
return 0;
|
|
}
|