00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef CLIENT_H
00010 #define CLIENT_H
00011
00012 #include <stdio.h>
00013 #include <errno.h>
00014 #include <unistd.h>
00015 #include <malloc.h>
00016 #include <string.h>
00017 #include <sys/socket.h>
00018 #include <resolv.h>
00019 #include <netdb.h>
00020 #include <openssl/ssl.h>
00021 #include <openssl/err.h>
00022 #include<string.h>
00023 #include <pthread.h>
00024 #include <gmp.h>
00025
00026 #include "UserIf.h"
00027 #include "type.h"
00028 #ifndef FAIL
00029 #define FAIL -1
00030 #endif
00031
00032 #ifndef CONFIG
00033 #define CONFIG
00034 #define HOSTNAME "127.0.0.1"
00035 #define PORT_NUMBER 5000
00036 #define PORT_NUMBER2 5001
00037 #define CERT_FILE "client.crt"
00038 #define KEY_FILE "clientkey.pem"
00039 #endif // CONFIG
00040
00041 #define DATA_LEN 1000
00042 class Client
00043 {
00044
00045 public:
00046 Client(UserIf*);
00047 Client();
00048 ~Client();
00049 int initSSL();
00050 int setpassword(const char *p);
00051 int loadCertificates();
00052 int openConnection();
00053 int startSSL(unsigned char* , int* len);
00054 int stopSSL(unsigned char* , int* len);
00055 int registerToServer(unsigned char* , int* len);
00056 int unregisterOnServer(unsigned char* , int len);
00057 int initiateChatSession(int destClient);
00058 int terminateChatSession();
00059 int getActiveUserList( ClientInfo* &clientList, int* len );
00060 int receiveData(unsigned char* data , int len);
00061 int sendData(unsigned char* data, int len);
00062 int getAccountStatus(ClientInfo* client);
00063 void* listener(void*);
00064 void* worker(void*);
00065 int isconnected();
00066
00067 private:
00068 int initCTX(void);
00069 int showCerts();
00070 int verifyCert(X509*);
00071 int setHostAndPort();
00072 int setCertFile();
00073 int setKeyFile();
00074 int getCertificate(Cert*);
00075 int setCertificate(Cert*);
00076 int initLog();
00077
00078
00079 int serverid;
00080 int clientid;
00081 FILE* logfp;
00082 SSL_CTX *ctx;
00083 int server;
00084 int server2;
00085 SSL *ssl;
00086 SSL *ssl2;
00087 Cert* myCert;
00088 Cert* serverCert;
00089 Session* session;
00090 char hostname[16];
00091 int port;
00092 int port2;
00093 char CertFile[100];
00094 char KeyFile[100];
00095 char passwd[100];
00096 char isActive;
00097 UserIf* ui;
00098 int isBusy;
00099 pthread_t thrListen;
00100
00101 };
00102
00103 #define getid() getpid()
00104
00105 #endif // CLIENT_H
00106