/******************************************************************* iRODSNtUtil.c Author: Bing Zhu San Diego Supercomputer Center Date of last modifictaion: 10-12-2005 Modified: Charles Cowart Date of last modification: 11/15/2006 *******************************************************************/ #include "iRODSNtutil.h" #include #include #include #include #include #include #include #include #include #define IRODS_NT_SERVICE_MODE 0 #define IRODS_NT_CONSOLE_MODE 1 char iRODSNtServerHomeDir[1024]; /* the home dir, "....../dice" in the installed service */ int nIrodsNtMode = IRODS_NT_SERVICE_MODE; char *iRODSNtServerLogFileName = NULL; /* pure file name */ char *iRODSNTServerLogDir = NULL; char *iRODSNtServerConfigDir = NULL; void iRODSNtAgentInit(int ac, char **av) { iRODSNtServerCheckExecMode(ac, av); iRODSNtSetServerHomeDir(av[0]); if(nIrodsNtMode != IRODS_NT_CONSOLE_MODE) { char *log_fname = getenv("irodsLogFile"); if(log_fname == NULL) return; iRODSNtServerLogFileName = strdup(log_fname); } if (startWinsock() != 0) { fprintf(stderr,"failed to call startWinsock().\n"); exit(0); } } void iRODSNtServerCheckExecMode(int targc, char **targv) { int i; for(i=0;i irodsServer.exe console\n"); exit(0); } p[0] = '\0'; p = strrchr(tmpstr,'\\'); if(p == NULL) { fprintf(stderr,"If you are running in sonsole mode. Please use the following syntax.\n"); fprintf(stderr,"> irodsServer.exe console\n"); exit(0); } p[0] = '\0'; strcpy(iRODSNtServerHomeDir, tmpstr); } int iRODSNtGetServiceName(char *service_name) { char irods_fname[2048]; FILE *f; char buff[1024]; int t; sprintf(irods_fname, "%s\\rodssnam.txt", iRODSNtServerHomeDir); f = iRODSNt_fopen(irods_fname, "r"); if(f == NULL) { /* failed to get service name. */ fprintf(stderr,"The iRODS could not open service name file, %s.\n", irods_fname); return -1; } if(fgets(buff, 1024, f) == NULL) { fprintf(stderr,"The iRODS failed to get info from service name file, %s.\n", irods_fname); fclose(f); return -2; } t = strlen(buff); if(buff[t-1] == '\n') buff[t-1] = '\0'; strcpy(service_name, buff); return 0; } void iRODSNtGetAgentExecutableWithPath(char *buf, char *agent_name) { if(nIrodsNtMode == IRODS_NT_CONSOLE_MODE) { strcpy(buf, agent_name); } else { sprintf(buf, "%s\\bin\\%s", iRODSNtServerHomeDir, agent_name); } } char *iRODSNtGetServerConfigPath() { char tmpstr[2048]; if(iRODSNtServerConfigDir != NULL) { return iRODSNtServerConfigDir; } if(nIrodsNtMode == IRODS_NT_CONSOLE_MODE) { strcpy(tmpstr, "..\\config"); } else { sprintf(tmpstr, "%s\\config", iRODSNtServerHomeDir); } iRODSNtServerConfigDir = _strdup(tmpstr); return iRODSNtServerConfigDir; } void iRODSNtAgentSetLogFilename(char *in_filename) { } /* This function should be called only in irodsServer. */ void iRODSNtGetLogFilename(char *log_filename) { if(iRODSNtServerLogFileName != NULL) strcpy(log_filename, iRODSNtServerLogFileName); } char *iRODSNtServerGetLogDir() { char buff[1024]; if(iRODSNTServerLogDir != NULL) return iRODSNTServerLogDir; sprintf(buff, "%s\\log", iRODSNtServerHomeDir); iRODSNTServerLogDir = strdup(buff); } void iRODSNtGetLogFilenameWithPath(char *logfilename_wp) { SYSTEMTIME tm; char tmpfn[1024]; if(nIrodsNtMode == IRODS_NT_CONSOLE_MODE) { logfilename_wp[0] = '\0'; return; } if(iRODSNtServerLogFileName != NULL) { sprintf(tmpfn, "%s\\log\\%s", iRODSNtServerHomeDir, iRODSNtServerLogFileName); strcpy(logfilename_wp, tmpfn); return ; } GetSystemTime(&tm); sprintf(tmpfn,"rodsLog_%d_%d_%d.txt", tm.wMonth, tm.wDay, tm.wYear); iRODSNtServerLogFileName = _strdup(tmpfn); sprintf(tmpfn, "%s\\log\\%s", iRODSNtServerHomeDir, iRODSNtServerLogFileName); strcpy(logfilename_wp, tmpfn); } /* The function is used to convert unix path delimiter,slash, to windows path delimiter, back slash. */ static void StrChangeChar(char* str,char from, char to) { int n,i; if(str == NULL) return; n = strlen(str); for(i=0;i 0)) { printf("%s", prompt); fflush(stdout); } while(1) { c = _getch(); if(c == 8) /* a backspace, we currently ignore it. i.e. treat it as doing nothing. User can alway re-do it. */ { if(p > buf) { --p; if(echo_input) { _putch(c); _putch(whitechar); _putch(c); } } } else if(c == 13) /* 13 is a return char */ { _putch(c); break; } else { /* _putch(star); */ p[0] = c; ++p; if(echo_input) { _putch(c); } } /* extra protection */ if((c == '\n') || (c == '\f') || (c == 13)) break; } p[0] = '\0'; printf("\n"); } long long atoll(const char *str) { return _atoi64(str); } void bzero(void *s, size_t n) { memset((char *)s, 0, n); } size_t irodsnt_strlen(const char *str) { if(str == NULL) return 0; return strlen(str); } void srandom(unsigned int seed) { srand(seed); } int strcasecmp(const char *s1, const char *s2) { return _stricmp(s1,s2); } void irodsStrChangeChar(char* str,char from, char to) { int n,i; if(str == NULL) return; n = strlen(str); for(i=0;i