int main() { struct ImageLibrary *ilib; if( ( ilib = (struct ImageLibrary *)LibraryOpen( "image.library", 0 ) ) != NULL ) { printf("<<<<<<<Library opened! version %ld\n", ilib->GetVersion() ); /* Image *img = NULL; if( ( img = ilib->ImageRead ( "test.ini" ) ) != NULL ) { printf("TEST.................\n"); char *t = ilib->ReadString( prop, "Database:test", "default" ); int val = ilib->ReadInt( prop, "Database:number", 223 ); if( t ) { printf("plib %s %d\n", t, val ); } ilib->Close( prop ); }*/ LibraryClose( (struct Library *)ilib ); } return 0; }
int main() { struct UserLibrary *ulib; if( ( ulib = (struct UserLibrary *)LibraryOpen( "user.library", 0 ) ) != NULL ) { int error = ulib->UserCreate( ulib, "jacek", "placek" ); printf("Library opened! version %f error %d\n", ulib->GetVersion(), error ); User *u = ulib->Authenticate( ulib, "jacek", "placek", NULL ); printf("After auth, error %d %p\n", u->u_Error, u->u_Name ); if( u ) { ulib->UserFree( u ); } LibraryClose( (struct Library *)ulib ); } printf("Checking library end\n"); return 0; }
int main() { struct ZLibrary *zlib; if( ( zlib = (struct ZLibrary *)LibraryOpen( "z.library", 0 ) ) != NULL ) { mkdir("directory", 0700); mkdir("output", 0700); FILE *d = fopen( "directory/test", "wb"); if( d != NULL ) { int i=0; for( i=0 ; i < 900 ; i++ ) fputc( 'a', d ); fclose( d ); } zlib->PackToZIP( zlib, "archive.zip", "directory", NULL ); zlib->UnpackZIP( zlib, "archive.zip", "output", NULL ); //User *u = ulib->Authenticate( ulib, "aajacek", "placek", NULL ); //printf("After auth, error %d %p\n", u->u_Error, u->u_Name ); //if( u ) //{ // ulib->UserFree( ulib, u ); //} LibraryClose( (struct Library *)zlib ); } printf("Checking library end\n"); return 0; }
int CommServiceThreadClient( FThread *ptr ) { CommService *service = (CommService *)ptr->t_Data; DEBUG("CommunicationServiceSend Start\n"); struct mq_attr attr; char buffer[ MAX_SIZE + 1 ]; /* // initialize the queue attributes attr.mq_flags = 0; attr.mq_maxmsg = MAX_MSG; attr.mq_msgsize = MAX_SIZE; attr.mq_curmsgs = 0; DEBUG("QUEUE Before Created SERVER\n"); // create the message queue mode_t mode = FLAGS; mode_t omask; omask = umask( 0 ); service->s_inMqfd = mq_open( QUEUE_NAME, (O_CREAT | O_RDONLY), mode, &attr ); umask( omask ); DEBUG("QUEUE Created SERVER\n"); */ pthread_mutex_lock( &InitMutex ); pthread_cond_signal( &InitCond ); pthread_mutex_unlock( &InitMutex ); // // atm we only read FC connections // struct PropertiesLibrary *plib = NULL; char *servers = NULL; Props *prop = NULL; if( ( plib = (struct PropertiesLibrary *)LibraryOpen( SLIB, "properties.library", 0 ) ) != NULL ) { char coresPath[ 1024 ]; sprintf( coresPath, "%s/cfg/cfg.ini", getenv( "FRIEND_HOME" ) ); prop = plib->Open( coresPath ); if( prop != NULL) { DEBUG("[Userlibrary] reading login\n"); servers = plib->ReadString( prop, "Cores:servers", "" ); DEBUG("[Userlibrary] servers %s\n", servers ); } //DEBUG("PROPERTIES LIBRARY OPENED, poitner to props %p! %s %s %s %s %d\n", prop, login, pass, host, dbname, port ); } if( servers != NULL ) { char *token; DEBUG("Server list found %s\n", servers ); // get the first token token = strtok( servers, SERVER_SPLIT_SIGN ); // walk through other tokens while( token != NULL ) { CommFCConnection *newcon; char *address = NULL; char *name = NULL; char *pos = strchr( token, SERVER_NAME_SPLIT_SING ); if( pos != NULL ) { *pos = 0; address = token; name = ++pos; }else{ address = token; name = token; } DEBUG("New connection found address : %s name : %s\n", address, name ); //TODO if( ( newcon = CommFCConnectionNew( address, name ) ) != NULL ) { DEBUG("Outgoing connection mem allocated\n"); newcon->cfcc_Socket = SocketOpen( FRIEND_COMMUNICATION_PORT, SOCKET_TYPE_CLIENT ); DEBUG("Outgoing connection created\n"); if( SocketConnect( newcon->cfcc_Socket, address ) == 0 ) { DEBUG("Connection setup with server : %s\n", token ); if( service->s_FCConnections == NULL ) { service->s_FCConnections = newcon; } else { // we already have connections, we must add them to the end of list CommFCConnection *lc = service->s_FCConnections; while( lc->node.mln_Succ != NULL ) { lc = (CommFCConnection *)lc->node.mln_Succ; } lc->node.mln_Succ = (MinNode *) newcon; } // // sockets connected, we create now special message where we sent ID of our host // DEBUG("Generate Data Form\n"); DataForm * df = DataFormNew( NULL ); DEBUG("DataForm Created\n"); FriendCoreManager *fcm = (FriendCoreManager *) service->s_FCM; DataFormAdd( &df, (BYTE *)fcm->fcm_ID, FRIEND_CORE_MANAGER_ID_SIZE ); //INFO("Message created name byte %c%c%c%c\n", fcm->fcm_ID[32], fcm->fcm_ID[33], fcm->fcm_ID[34], fcm->fcm_ID[35] ); SocketWrite( newcon->cfcc_Socket, (char *)df, df->df_Size ); DEBUG("Message sent\n"); DataFormDelete( df ); } else { close( newcon->cfcc_Socket->fd ); FFree( newcon->cfcc_Socket ); FFree( newcon ); ERROR("Cannot setup socket connection!\n"); } } DEBUG( " %s\n", token ); token = strtok( NULL, "," ); } DEBUG("All tokens passed\n"); } else { // servers == NULL } if( plib != NULL && prop != NULL ) { plib->Close( prop ); } if( plib != NULL ) { LibraryClose( (struct Library *)plib ); } DEBUG("CommunicationServiceClient start\n"); // // we should ask for information from connection // // messages get and pass to destination //int queueFd = mq_ msgqToFd( service->s_inMqfd ); struct timeval tv; fd_set writeToServ; fd_set readFromServ; ULONG idMax = 0; if( service->s_sendPipe[ 0 ] > idMax ) idMax = service->s_sendPipe[ 0 ]; if( service->s_sendPipe[ 1 ] > idMax ) idMax = service->s_sendPipe[ 1 ]; if( service->s_recvPipe[ 0 ] > idMax ) idMax = service->s_recvPipe[ 0 ]; if( service->s_recvPipe[ 1 ] > idMax ) idMax = service->s_recvPipe[ 1 ]; { CommFCConnection *lc = service->s_FCConnections; while( lc != NULL ) { if( lc->cfcc_Socket > idMax ) { idMax = lc->cfcc_Socket->fd; } lc = (CommFCConnection *)lc->node.mln_Succ; } } DEBUG("IDMAX SET TO %ld\n", idMax ); /* if( service->s_inMqfd != -1 ) {*/ while( service->s_Cam.cam_Quit != 1 ) { FD_ZERO( &writeToServ ); FD_ZERO( &readFromServ ); FD_SET( service->s_sendPipe[ 0 ] , &writeToServ ); //FD_SET( lc->cfcc_Socket , &readFromServ ); tv.tv_sec = 0; tv.tv_usec = 10000000; //ret = 0; int ret = select( idMax+1, &writeToServ, NULL, NULL, &tv ); // handle message if( ret > 0 ) { int rets = read( service->s_sendPipe[ 0 ], buffer, MAX_SIZE ); //ERROR("DATAREADED! %d\n", rets ); buffer[ rets ] = '\0'; //TODO // we should read from QUEUE, check destination server and send message // /* CommFCConnection *lc = service->s_FCConnections; while( lc != NULL ) { //TODO test message , should be removed SocketWrite( lc->cfcc_Socket, buffer, rets );//"hello", 5 ); DEBUG("CommunicationServiceClient Sending message hello\n"); int sockReadSize = 0; sockReadSize = SocketRead( lc->cfcc_Socket, buffer, MAX_SIZE, 0 ); int writeSize = write( service->s_recvPipe[ 1 ], buffer, sockReadSize ); DEBUG("Message received '%s'\n", buffer ); lc = (CommFCConnection *)lc->node.mln_Succ; }*/ }else{ } //usleep( 10000000 ); //DEBUG("CommunicationServiceClient Thread at work %d\n", ret ); ssize_t bytes_read; // receive the message //bytes_read = mq_receive( service->s_inMqfd, buffer, MAX_SIZE, NULL ); //CHECK(bytes_read >= 0); /* */ } /* }else{ ERROR("Cannot create QUEUE!\n"); }*/ DEBUG("CommunicationService close\n"); CommFCConnection *lc = service->s_FCConnections; CommFCConnection *rlc = service->s_FCConnections; while( lc != NULL ) { rlc = lc; lc = (CommFCConnection *) lc->node.mln_Succ; DEBUG("Closing output connection\n"); SocketClose( rlc->cfcc_Socket ); CommFCConnectionDelete( rlc ); } // closing queue //mq_close( service->s_inMqfd ); //mq_unlink( QUEUE_NAME ); return 0; }
FriendCoreManager *FriendCoreManagerNew() { FriendCoreManager *fcm = NULL; if( ( fcm = FCalloc( 1, sizeof( struct FriendCoreManager ) ) ) != NULL ) { int websocketPort = WEBSOCKET_PORT; fcm->fcm_ServiceManager = ServiceManagerNew( fcm ); // // Create FriendCoreManagerID // char temp[ 64 ]; SHA256_CTX ctx; //sha256_init( &ctx ); if( getMacAddress( temp ) == 0 ) { } //sha256_update( &ctx, temp, 32 ); //sha256_final( &ctx, fcm->fcm_ID ); struct hostent *he = gethostbyname( "localhost" ); strcpy( fcm->fcm_ID, temp ); strncat( fcm->fcm_ID, he->h_name, 31 ); int i; for( i=0 ; i<64; i++ ) { if( fcm->fcm_ID[i ] == 0 ) { fcm->fcm_ID[ i ] = '0'; } } fcm->fcm_ID[ 63 ] = 0; INFO("FriendCoreManager: name set to: %64s\n", fcm->fcm_ID ); // // create services // int port = FRIEND_CORE_PORT; int maxp = EPOLL_MAX_EVENTS; int bufsize = BUFFER_READ_SIZE; int maxpcom = EPOLL_MAX_EVENTS_COMM; int bufsizecom = BUFFER_READ_SIZE_COMM; BOOL SSLEnabled = FALSE; BOOL WSSSLEnabled = FALSE; { struct PropertiesLibrary *plib = NULL; Props *prop = NULL; if( ( plib = (struct PropertiesLibrary *)LibraryOpen( SLIB, "properties.library", 0 ) ) != NULL ) { char *ptr, path[ 1024 ]; path[ 0 ] = 0; ptr = getenv("FRIEND_HOME"); if( ptr != NULL ) { sprintf( path, "%scfg/cfg.ini", ptr ); } sprintf( RSA_SERVER_CERT, "%s/crt/certificate.pem", ptr ); sprintf( RSA_SERVER_KEY, "%s/crt/key.pem", ptr ); sprintf( RSA_SERVER_CA_CERT, "%s/crt/certificate.pem", ptr ); sprintf( RSA_SERVER_CA_PATH, "%s/crt/", ptr ); prop = plib->Open( path ); if( prop != NULL) { port= plib->ReadInt( prop, "Core:port", FRIEND_CORE_PORT ); maxp = plib->ReadInt( prop, "Core:epollevents", EPOLL_MAX_EVENTS ); bufsize = plib->ReadInt( prop, "Core:networkbuffer", BUFFER_READ_SIZE ); maxpcom = plib->ReadInt( prop, "Core:epolleventscom", EPOLL_MAX_EVENTS_COMM ); bufsizecom = plib->ReadInt( prop, "Core:networkbuffercom", BUFFER_READ_SIZE_COMM ); websocketPort = plib->ReadInt( prop, "Core:wsport", WEBSOCKET_PORT ); SSLEnabled = plib->ReadInt( prop, "Core:SSLEnable", 0 ); WSSSLEnabled = plib->ReadInt( prop, "Core:WSSSLEnable", 0 ); char *tptr = plib->ReadString( prop, "Core:Certpath", "cfg/crt/" ); if( tptr != NULL ) { if( tptr[ 0 ] == '/' ) { sprintf( RSA_SERVER_CERT, "%s%s", tptr, "certificate.pem" ); sprintf( RSA_SERVER_KEY, "%s%s", tptr, "key.pem" ); sprintf( RSA_SERVER_CA_CERT, "%s%s", tptr, "certificate.pem" ); sprintf( RSA_SERVER_CA_PATH, "%s%s", tptr, "/" ); } else { sprintf( RSA_SERVER_CERT, "%s%s%s", ptr, tptr, "certificate.pem" ); sprintf( RSA_SERVER_KEY, "%s%s%s", ptr, tptr, "key.pem" ); sprintf( RSA_SERVER_CA_CERT, "%s%s%s", ptr, tptr, "certificate.pem" ); sprintf( RSA_SERVER_CA_PATH, "%s%s%s", ptr, tptr, "/" ); } } else { } plib->Close( prop ); } LibraryClose( ( struct Library *)plib ); } fcm->fcm_FriendCores = FriendCoreNew( SSLEnabled, port, maxp, bufsize ); } if( fcm->fcm_FriendCores == NULL ) { free( fcm ); ERROR("Cannot create FriendCore!\n"); return NULL; } #ifdef ENABLE_WEBSOCKETS if( ( fcm->fcm_WebSocket = WebSocketNew( fcm, websocketPort, WSSSLEnabled ) ) != NULL ) { WebSocketStart( fcm->fcm_WebSocket ); } else { ERROR("Cannot launch websocket server\n"); } #endif fcm->fcm_CommServiceServer = CommServiceNew( SERVICE_TYPE_SERVER, fcm, maxpcom, bufsizecom ); fcm->fcm_CommServiceClient = CommServiceNew( SERVICE_TYPE_CLIENT, fcm, maxpcom, bufsizecom ); fcm->fcm_SSHServer = SSHServerNew(); //fcm->fcm_EventManager = EventManagerNew(); fcm->fcm_Shutdown = FALSE; } DEBUG("FriendCoreManager Created\n"); return fcm; }