int logSuccess(const struct AmmServer_Instance * instance,const struct HTTPTransaction * transaction,unsigned int logCode,const char * filename) { return AccessLogAppend( transaction->ipStr, 0, // Auto Date It NOW! transaction->incomingHeader.GETrequest //transaction->incomingHeader.resource ,logCode ,transaction->outgoingBodySize // <- This might be wrong ,filename ,transaction->incomingHeader.userAgent ); }
struct AmmServer_Instance * AmmServer_Start( const char * name , const char * ip, unsigned int port, const char * conf_file, const char * web_root_path, const char * templates_root_path ) { fprintf(stderr,"Binding AmmarServer v%s to %s:%u\n",FULLVERSION_STRING,ip,port); fprintf(stderr,"\n\nDISCLAIMER : \n"); fprintf(stderr,"Please note that this server version is not thoroughly\n"); fprintf(stderr," pen-tested so it is not meant for production deployment..\n"); fprintf(stderr,"Bug reports and feedback are very welcome.. \n"); fprintf(stderr,"via https://github.com/AmmarkoV/AmmarServer/issues\n\n"); //log/ could be a global directory snprintf(AccessLog,MAX_FILE_PATH,"log/%s_access.log",name); snprintf(ErrorLog,MAX_FILE_PATH,"log/%s_error.log",name); fprintf(stderr,"Access logged @ %s , Errors logged @ %s \n ",AccessLog,ErrorLog); //Allocate and Clear instance.. struct AmmServer_Instance * instance = (struct AmmServer_Instance *) malloc(sizeof(struct AmmServer_Instance)); if (!instance) { fprintf(stderr,"AmmServer_Start failed to allocate a new instance \n"); } else { memset(instance,0,sizeof(struct AmmServer_Instance)); } fprintf(stderr,"Initial AmmServer_Start instance pointing @ %p \n",instance);//Clear instance..! instance->threads_pool = (pthread_t *) malloc( sizeof(pthread_t) * MAX_CLIENT_THREADS); if (!instance->threads_pool) { fprintf(stderr,"AmmServer_Start failed to allocate %u records for a thread pool\n",MAX_CLIENT_THREADS); } else { memset(instance->threads_pool,0,sizeof(pthread_t)*MAX_CLIENT_THREADS); } strncpy(instance->instanceName , name , MAX_INSTANCE_NAME_STRING); // TODO: check for MAX_INSTANCE_NAME_STRING fprintf(stderr,"Initial AmmServer_Start ( name %s ) thread pool pointing @ %p \n",instance->instanceName,instance->threads_pool);//Clear instance..! instance->prespawned_pool = (void *) malloc( sizeof(struct PreSpawnedThread) * MAX_CLIENT_PRESPAWNED_THREADS); if (!instance->prespawned_pool) { fprintf(stderr,"AmmServer_Start failed to allocate %u records for a prespawned thread pool\n",MAX_CLIENT_PRESPAWNED_THREADS); }else { if (MAX_CLIENT_PRESPAWNED_THREADS>0) { memset(instance->prespawned_pool,0,sizeof(pthread_t)*MAX_CLIENT_PRESPAWNED_THREADS); } } //LoadConfigurationFile happens before dropping root id so we are more sure that we will manage to read the configuration file.. LoadConfigurationFile(instance,conf_file); //LoadConfigurationFile may set a binding port but if the parent call set a nonzero a port setting here it overrides configuration file.... if (port!=0) { instance->settings.BINDING_PORT = port; } //This line explains configuration conflicts in a user understandable manner :p EmmitPossibleConfigurationWarnings(instance); cache_Initialize( instance, /*These are the file cache settings , file caching is the mechanism that holds dynamic content and speeds up file serving by not accessing the whole disk drive subsystem ..*/ MAX_SEPERATE_CACHE_ITEMS , /*Seperate items*/ MAX_CACHE_SIZE_IN_MB , /*MB Limit for the WHOLE Cache*/ MAX_CACHE_SIZE_FOR_EACH_FILE_IN_MB /*MB Max Size of Individual File*/ ); if (StartHTTPServer(instance,ip,instance->settings.BINDING_PORT,web_root_path,templates_root_path)) { //All is well , we return a valid instance AccessLogAppend("127.0.0.1",0,"startup",1,0,"startup","ammarserver"); return instance; } else { AmmServer_Stop(instance); return 0; } return 0; }