/* * Copyright 1992-1999 Silicon Graphics, Inc. * All Rights Reserved. * * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.; * the contents of this file may not be disclosed to third parties, copied or * duplicated in any form, in whole or in part, without the prior written * permission of Silicon Graphics, Inc. * * RESTRICTED RIGHTS LEGEND: * Use, duplication or disclosure by the Government is subject to restrictions * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data * and Computer Software clause at DFARS 252.227-7013, and/or in similar or * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished - * rights reserved under the Copyright Laws of the United States. */ #include "availability.h" /* ----------------------------- rgpgInit ------------------------------------ */ int RGPGAPI rgpgInit(sscErrorHandle hError) { /* Try initialize "free list of mySession" mutex */ if(pthread_mutex_init(&seshFreeListmutex,0)) { sscError(hError,szServerNameErrorPrefix,"Can't initialize mutex"); return 0; /* error */ } mutex_inited++; #ifdef INCLUDE_TIME_DATE_STRINGS sprintf(szVersionStr,"%d.%d %s %s",MYVERSION_MAJOR,MYVERSION_MINOR,__DATE__,__TIME__); #else sprintf(szVersionStr,"%d.%d",MYVERSION_MAJOR,MYVERSION_MINOR); #endif return 1; /* success */ } /* ----------------------------- rgpgDone ------------------------------------ */ int RGPGAPI rgpgDone(sscErrorHandle hError) { mySession *s; if(mutex_inited) { pthread_mutex_destroy(&seshFreeListmutex); mutex_inited = 0; while((s = sesFreeList) != 0) { sesFreeList = s->next; free(s); } return 1; /* success */ } return 0; /* error - not inited */ } /* -------------------------- rgpgCreateSesion ------------------------------- */ rgpgSessionID RGPGAPI rgpgCreateSesion(sscErrorHandle hError) { mySession *s; pthread_mutex_lock(&seshFreeListmutex); if((s = sesFreeList) != 0) sesFreeList = s->next; pthread_mutex_unlock(&seshFreeListmutex); if(!s) s = (mySession*)malloc(sizeof(mySession)); if(!s) { sscError(hError,szServerNameErrorPrefix,"No memory to create session in rgpgCreateSesion()"); return 0; } memset(s,0,sizeof(mySession)); s->signature = sizeof(mySession); return (rgpgSessionID)s; } /* ------------------------- rgpgDeleteSesion -------------------------------- */ void RGPGAPI rgpgDeleteSesion(sscErrorHandle hError,rgpgSessionID _s) { mySession *s = (mySession *)_s; if(!s || s->signature != sizeof(mySession)) { sscError(hError,szServerNameErrorPrefix,"Incorrect session id in rgpgDeleteSesion()"); } else { pthread_mutex_lock(&seshFreeListmutex); s->next = sesFreeList; sesFreeList = s; s->signature = 0; pthread_mutex_unlock(&seshFreeListmutex); } } /* ------------------------ rgpgGetAttribute --------------------------------- */ char *RGPGAPI rgpgGetAttribute(sscErrorHandle hError,rgpgSessionID session, const char *attributeID, const char *extraAttrSpec,int *typeattr) { char *s; if(typeattr) *typeattr = RGATTRTYPE_STATIC; if(!strcasecmp(attributeID,szVersion)) s = (char*)szVersionStr; else if(!strcasecmp(attributeID,szTitle)) s = (char*)myLogo; else if(!strcasecmp(attributeID,szUnloadTime)) s = (char*)szUnloadTimeValue; else if(!strcasecmp(attributeID,szThreadSafe)) s = (char*)szThreadSafeValue; else if(!strcasecmp(attributeID,szUnloadable)) s = (char*)szUnloadableValue; else if(!strcasecmp(attributeID,szAcceptRawCmdString)) s = (char*)szAcceptRawCmdStringValue; else { sscError(hError,"%s No such attribute '%s' in rgpgGetAttribute()",szServerNameErrorPrefix,attributeID); return 0; } if(!s) sscError(hError,szServerNameErrorPrefix,"No memory in rgpgGetAttribute()"); return s; } /* --------------------- rgpgFreeAttributeString ------------------------------ */ void RGPGAPI rgpgFreeAttributeString(sscErrorHandle hError,rgpgSessionID session,const char *attributeID,const char *extraAttrSpec, char *attrString,int restype) { if(((restype == RGATTRTYPE_SPECIALALLOC) || (restype == RGATTRTYPE_MALLOCED)) && attrString) free(attrString); } /*----------------------------------------rgpgSetAttribute---------------------------------------------*/ void RGPGAPI rgpgSetAttribute(sscErrorHandle hError, rgpgSessionID session, const char *attributeID, const char *extraAttrSpec, const char *value) { char buff[128]; mySession *sess = session; if(!strcasecmp(attributeID,szVersion) || !strcasecmp(attributeID,szTitle) || !strcasecmp(attributeID,szThreadSafe) || !strcasecmp(attributeID,szUnloadable) || !strcasecmp(attributeID,szUnloadTime)) { sscError(hError,szServerNameErrorPrefix,"Attempt to set read only attribute in rgpgSetAttribute()"); return; } if(!strcasecmp(attributeID,"User-Agent") && value) { sess->textonly = (strcasecmp(value,"Lynx") == 0) ? 1 : 0; return; } if(!sess || sess->signature != sizeof(mySession)) { sscError(hError,szServerNameErrorPrefix,"Incorrect session id in rgpgGetAttribute()"); return; } } /*----------------------------------------rgpgGenerateReport---------------------------------------------*/ int RGPGAPI rgpgGenerateReport(sscErrorHandle hError, rgpgSessionID _session, int argc, char* argv[],char *rawCommandString, streamHandle result, char *accessmask) { ssdb_Client_Handle client; ssdb_Connection_Handle connection; ssdb_Request_Handle req_handle; ssdb_Error_Handle error_handle; int i,cmdpsize,SQL_TYPE; CMDPAIR cmdp[MAXNUMBERS_OF_KEYS]; mySession *session = _session; if ((error_handle = ssdbCreateErrorHandle()) == NULL) { sscError(hError,"SSDB API Error %d: \"%s\" - can't create error handle\n", ssdbGetLastErrorCode(0),ssdbGetLastErrorString(0)); return 0; } if ((client = ssdbNewClient(error_handle,szDefaultUserName,szDefaultPassword,0)) == NULL) { sscError(hError,"SSDB API Error %d: \"%s\" - can't create new client handle\n", ssdbGetLastErrorCode(error_handle),ssdbGetLastErrorString(error_handle)); ssdbDeleteErrorHandle(error_handle); return 0; } /* Establish a connection to a database */ if ((connection = ssdbOpenConnection(error_handle,client,szDefaultHostName,szDefaultDatabaseName,0)) == NULL) { sscError(hError,"SSDB API Error %d: \"%s\" - can't open connection\n", ssdbGetLastErrorCode(error_handle),ssdbGetLastErrorString(error_handle)); ssdbDeleteErrorHandle(error_handle); ssdbDeleteClient(error_handle,client); return 0; } /* Initialize The HTML Generator */ i = createMyHTMLGenerator(result); if (i != 0) { sscError(hError, "Sample server: Can't open the HTML generator"); ssdbDeleteErrorHandle(error_handle); ssdbDeleteClient(error_handle,client); ssdbCloseConnection (error_handle,connection); return 0; } if (argc < 2) { sscError(hError, "Invalid Request\n"); ssdbDeleteErrorHandle(error_handle); ssdbDeleteClient(error_handle,client); ssdbCloseConnection (error_handle,connection); return 0; } cmdpsize = sscInitPair(rawCommandString,cmdp,MAXNUMBERS_OF_KEYS); /* Check WEB browser type (Lynx is only tex based) */ for(i = 0;(i = sscFindPairByKey(cmdp,i,szUserAgent)) >= 0;i++) if(!strcasecmp(cmdp[i].value,"Lynx")) session->textonly = 1; /* Availmon Setup */ if (!strcasecmp(argv[1],"AVAILMON_CONFIG")) session->report_type = AVAILMON_CONFIG; else if (!strcasecmp(argv[1],"AVAILMON_CONFIG_CONFIRM")) session->report_type = AVAILMON_CONFIG_CONFIRM; else if (!strcasecmp(argv[1],"AVAILMON_MAIL")) session->report_type = AVAILMON_MAIL; else if (!strcasecmp(argv[1],"AVAILMON_MAIL_CONFIRM")) session->report_type = AVAILMON_MAIL_CONFIRM; else if (!strcasecmp(argv[1],"GLOBALPAGE")) session->report_type = GLOBALPAGE; else if (!strcasecmp(argv[1],"GLOBALCONFIRM")) session->report_type = GLOBALCONFIRM; else { sscError(hError, "Invalid Report Request %s",argv[1]); } switch (session->report_type) { case AVAILMON_CONFIG: availmon_config(hError,session,connection,error_handle); break; case AVAILMON_CONFIG_CONFIRM: availmon_config_confirm(hError,session,connection,error_handle,cmdp); break; case AVAILMON_MAIL: availmon_mail(hError,session,connection,error_handle,cmdp); break; case AVAILMON_MAIL_CONFIRM: availmon_mail_confirm(hError,session,connection,error_handle,cmdp); break; case GLOBALPAGE: global_setup(hError,session,connection,error_handle,cmdp); break; case GLOBALCONFIRM: globalconfirm(hError,session,connection,error_handle,cmdp); break; } /* Destroy The HTML Generator */ i = deleteMyHTMLGenerator(); if (i != 0) { sscError(hError, "Sample server: Can't destroy the HTML generator"); } if (ssdbIsConnectionValid(error_handle,connection)) ssdbCloseConnection (error_handle,connection); if (ssdbIsClientValid(error_handle,client)) ssdbDeleteClient(error_handle,client); if (error_handle) ssdbDeleteErrorHandle(error_handle); return 0; } #if 0