void main(int argc, char *argv[]) { char buf[256]; char *bufptr = (char *)buf; int iarg; /* ** Put the program name and its parameters in the buffer. */ STcopy("ntrcpst", bufptr); for (iarg = 1; iarg<argc; iarg++) { STcat(bufptr, " "); STcat(bufptr, argv[iarg]); } /* ** Execute the command. */ if( PCexec_suid(&buf) != OK ) PCexit(FAIL); PCexit(OK); }
void Time2Chars (double dSecond, char* buffer) { char* p; char buff1[16]; char buff2[16]; int m = 0; int h = 0; while (dSecond >= 60.0) { dSecond -= 60.0; m++; } while (m >= 60) { m -= 60; h++; } dSecond = dSecond*100; STprintf(buff1, "%04d", (int)dSecond); STlcopy (buff1, buff2, 2); p = buff1; p += 2; STprintf (buffer, "%02d%:%02d:%s", h, m, buff2); STcat(buffer, "."); STcat(buffer, p); }
int odxa_errhandler(void) { char buf[257]=""; char message[513]=" ::[ , 00000000]: "; long error_no = 0; char error_text[257]; SYSTIME time_now; i4 len; // EXEC SQL INQUIRE_SQL(:error_no = ERRORNO,:error_text = ERRORTEXT); IILQisInqSqlio((short *)0,1,30,4,&error_no,2); IILQisInqSqlio((short *)0,1,32,256,error_text,63); CVlx((u_i4)error_no, buf); STprintf(message, ERx(" ::[%-16s, %s]: "), szFuncName, buf); TMnow( &time_now ); TMstr( &time_now, buf ); STcat(message, buf); STcat(message, " MS DTC Ingres XA Interface: "); if (STequal(szFuncName,"xa_open")) /* dump out xa_open's xa_info string */ { len = (i4)STlength(message); STcat(message, errlog_xa_info); WriteDTCerrToEventLog(S_OK, message); message[len] = '\0'; /* chop back to the message header */ } STcat(message, error_text); WriteDTCerrToEventLog(S_OK, message); return 0; }
static char * ns_value( API_PARSE *parse, i4 buflen, char *buffer ) { char *parms[ API_FIELD_MAX ]; char *value; i4 len, fld, fld_cnt; STATUS status; /* ** Get each (possibly optional) parameter ** and determine the size of the final ** combined value. */ fld_cnt = max( 0, parse->parms->parm_max - API_FIELD_PARM ); for( fld = len = 0; fld < fld_cnt; fld++ ) { parms[ fld ] = ns_resolve_param( parse, fld + API_FIELD_PARM, (parse->opcode != API_KW_ADD) ); len += STlength( parms[ fld ] ); } len += fld_cnt; /* Allow room for EOS and separating ',' */ if ( ! len ) len++; /* ** Use passed in buffer if large enough. ** Otherwise, allocate temp buffer. */ value = (len <= buflen) ? buffer : (char *)MEreqmem( 0, len, FALSE, &status ); if ( ! value ) { IIAPI_TRACE( IIAPI_TR_FATAL ) ( "ns_value: can't allocate value buffer\n" ); return( NULL ); } /* ** Build the comma separated list of parameters. */ if ( fld_cnt ) STcopy( parms[ 0 ], value ); else *value = EOS; for( fld = 1; fld < fld_cnt; fld++ ) { STcat( value, "," ); STcat( value, parms[ fld ] ); } return( value ); }
/* ** Name: GetMSroot ** ** Description: ** Display the home HTML directory for MS IIS ** ** Inputs: ** conf pointer to the MS config structure. ** regkey generated registry key. ** ** Outputs: ** docpath contains the HTML root path ** ** Returns: ** none ** ** History: ** 09-Oct-98 (fanra01) ** Created. ** 20-Nov-1998 (fanra01) ** Add docpath. ** 24-Mar-1999 (fanra01) ** Store error return from RegQueryValueEx and retry on not found ** or not exist errors. */ STATUS GetMSroot (PW3CONF conf, char* regkey, char** docpath) { STATUS status = FAIL; i4 i =0; DWORD dwstat = 0; char val[10]; HKEY key; char regval[256]; DWORD valtype; DWORD valsize = sizeof(regval); if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, regkey, 0, KEY_QUERY_VALUE, &key) == ERROR_SUCCESS) { /* ** Need this loop as microsoft annoyingly adds a comma to the key name ** when any HTTP paths have been updated. */ for (i = 0; i < 2; i++) { STcopy (httpsrv[enumwebsrv].val, val); if (i == 1) STcat (val, ","); if ((dwstat = RegQueryValueEx (key, val, NULL, &valtype, regval, &valsize)) == ERROR_SUCCESS) { char* p; if ((p = STindex (regval, ",", 0)) != NULL) *p = EOS; *docpath = STalloc (regval); status = OK; } else { switch (dwstat) { case ERROR_FILE_NOT_FOUND: case ERROR_CLASS_DOES_NOT_EXIST: case ERROR_ENVVAR_NOT_FOUND: /* ** Can't find? Try again with a comma */ break; default: SIprintf ("Error : %d Retrieving value %s. Info %d\n", dwstat, val, GetLastError()); i = 2; /* terminate loop */ break; } } } } else { DISPERROR(errflg)("Error : No Microsoft servers found\n"); } return (status); }
static void formatXID( IIAPI_XA_DIS_TRAN_ID *xid, char *str ) { u_i4 count, val; u_i1 *data; CVlx( xid->xa_tranID.xt_formatID, str ); str += STlength( str ); *(str++) = ':'; CVla( xid->xa_tranID.xt_gtridLength, str ); str += STlength( str ); *(str++) = ':'; CVla( xid->xa_tranID.xt_bqualLength, str ); str += STlength( str ); data = (u_i1 *)xid->xa_tranID.xt_data; count = (xid->xa_tranID.xt_gtridLength + xid->xa_tranID.xt_bqualLength + sizeof( i4 ) - 1) / sizeof( i4 ); while( count-- ) { val = (*data << 24) | (*(data+1) << 16) | (*(data+2) << 8) | *(data+3); data+= 4; *(str++) = ':'; CVlx( val, str ); str += STlength( str ); } STcat( str, ERx( ":XA" ) ); str += STlength( str ); *(str++) = ':'; CVna( xid->xa_branchSeqnum, str ); str += STlength( str ); *(str++) = ':'; CVna( xid->xa_branchFlag, str ); str += STlength( str ); STcat( str, ERx( ":EX" ) ); return; }
/* ** ConcateStrings: ** * The function that concates strings (ioBuffer, aString, ..) ** ** Parameter: ** 1) ioBuffer: In Out Buffer ** 2) aString : String to be concated. ** 3) ... : Ellipse for other strings...with NULL terminated (char*)0 ** Return: ** return 1 if Successful. ** return 0 otherwise. */ int ConcateStrings (char** ioBuffer, char* aString, ...) { int size; va_list Marker; char* strArg; if (!aString) return 0; if (!(*ioBuffer)) { *ioBuffer = (char*)malloc (STlength (aString) +1); *ioBuffer[0] = '\0'; } else { size = STlength ((char*)(*ioBuffer)) + STlength (aString) +1; *ioBuffer = (char*)realloc ((char*)(*ioBuffer), size); } if (!*ioBuffer) return 0; else STcat (*ioBuffer, aString); va_start (Marker, aString); while (strArg = va_arg (Marker, char*)) { size = STlength (*ioBuffer) + STlength (strArg) +1; *ioBuffer = (char*)realloc(*ioBuffer, size); if (!*ioBuffer) return 0; else STcat (*ioBuffer, strArg); } va_end (Marker); return 1; }
/* ** Name: Disp_Form ** ** Decription: ** Disposition: form-data; recevied with no filename. Implies a page ** variable name. ** Extract the variable and store it in the upload structure for use ** later. ** ** Inputs: ** sess ice session structure ** line pointer to the current line ** linelen length of the line ** ** Outputs: ** pos number of characters handled. ** ** Return: ** GSTAT_OK success ** other failure ** ** History: ** 23-Oct-98 (fanra01) ** Created. */ static GSTATUS Disp_Form (WTS_SESSION* sess, char* line, i4 linelen, i4 * pos) { GSTATUS err = GSTAT_OK; PWTS_UPLOAD load= sess->load; char* p = line + *pos; char* varname; i4 remain = linelen - *pos; i4 i = 0; i4 j = 0; if (STbcompare ("name", 4, p, 0, TRUE) == 0) { /* ** Find the first quote after name */ while ((*p != '\"') && (i < remain)) { CMbyteinc(i,p); CMnext(p); } CMbyteinc(i,p); /* skip the quote */ CMnext(p); varname= p; while ((*p != '\"') && (i < remain)) { j+=CMbytecnt(p); CMbyteinc(i,p); CMnext(p); } CMbyteinc(i,p); /* skip the quote */ CMnext(p); /* ** Allocate space for the variable name a '=' character and an EOS */ if ((err = GAlloc (&load->varname, j+2, FALSE)) == GSTAT_OK) { MEfill (j+2, 0, load->varname); MECOPY_VAR_MACRO (varname, j, load->varname); STcat (load->varname, "="); } *pos += i; load->state = US_VAL; } else { HandlerException (sess, line, linelen, pos); } return (err); }
char * xfnewfname(char *table_name, char *owner) { char short_owner[4]; char *prefix; if (uncalled) { if (IIGNssStartSpace(1, ERx(""), XF_UNIQUE, XF_UNIQUE, GN_LOWER, GNA_XUNDER, (void (*)()) NULL) != OK) { return (NULL); } uncalled = FALSE; } Namebuf[0] = EOS; STcopy(table_name, Prefixbuf); /* map any funny bytes to underscores. */ map_funny(Prefixbuf); if (IIGNgnGenName(1, Prefixbuf, &prefix) != OK) return (NULL); STcopy(prefix, Namebuf); STcat(Namebuf, ERx(".")); STcopy(owner, Prefixbuf); /* map any funny bytes to underscores. */ map_funny(Prefixbuf); STcat(Namebuf, Prefixbuf); return (Namebuf); }
/* ** Name: WTSOpenUpLoad() - ** ** Description: ** ** Inputs: ** contentType ** session ** ** Outputs: ** ** Returns: ** GSTATUS : GSTAT_OK ** ** Exceptions: ** None ** ** Side Effects: ** None ** ** History: */ GSTATUS WTSOpenUpLoad( char *contentType, WTS_SESSION *session) { GSTATUS err; i4 length = STlength(MULTIPART); PWTS_UPLOAD load = NULL; char* bound; i4 blen; if (contentType != NULL && STscompare(contentType, length, MULTIPART, length) == 0) { session->status = UPLOAD; if ((err = GAlloc ((char**)&load, sizeof(WTS_UPLOAD), FALSE)) == GSTAT_OK) { session->load = load; bound = STindex (contentType, BOUNDARY, 0) + STlength(BOUNDARY); blen = STlength (bound); /* ** Allocate space for a start boundary and and en boundary ** each having the delimiters and null terminator. */ if (((err = GAlloc (&load->start, blen + 3, FALSE)) == GSTAT_OK) && ((err = GAlloc (&load->end, blen + 5, FALSE)) == GSTAT_OK)) { STcopy ("--",load->start); STlcopy (bound, load->start + 2, blen); STcopy (load->start, load->end); STcat (load->end, "--"); } load->state = US_BEGIN; } } else { session->status = NO_UPLOAD; session->load = NULL; } session->list = NULL; session->variable = NULL; session->vlen = 0; return(GSTAT_OK); }
bool Eval_If(char *commands[]) { STATUS eval_err ; char buffer [128] ; char *tokptr [12] ; register i4 tok_ctr = 0 ; i4 answer = TRUE ; for (tok_ctr=0; tok_ctr<12; tok_ctr++) tokptr[tok_ctr] = 0; *buffer = EOS; for (tok_ctr=2; commands[tok_ctr]; tok_ctr++) STcat(buffer, commands[tok_ctr]); /* Condense the expression. */ *msg = EOS; answer = SEP_Eval_If( buffer, &eval_err, msg); if (eval_err != OK) { testGrade = FAIL; if (*msg == EOS) { disp_line(STpolycat(4,ErrC,ERx("Evaluate Expresion <"),buffer, ERx(">"),msg),0,0); } else { disp_line(msg,0,0); } append_line(msg,1); return(FAIL); } if (answer == TRUE) { return (TRUE); } else { return (FALSE); } }
static bool writeMgrFile( char *altPath ) { char *dirPath; char fullPath[OCFG_MAX_STRLEN]; FILE *pfile; LOCATION loc; STATUS status; # ifdef VMS NMgtAt(SYSTEM_LOCATION_VARIABLE,&dirPath); /* usually II_SYSTEM */ if (dirPath != NULL && *dirPath) STlcopy(dirPath,fullPath,sizeof(fullPath)-20-1); else return (FALSE); STcat(fullPath,"["); STcat(fullPath,SYSTEM_LOCATION_SUBDIRECTORY); /* usually "ingres" */ STcat(fullPath,".files]"); STcat(fullPath,MGR_STR_FILE_NAME); # else NMgtAt(SYSTEM_LOCATION_VARIABLE,&dirPath); /* usually II_SYSTEM */ if (dirPath != NULL && *dirPath) STlcopy(dirPath,fullPath,sizeof(fullPath)-20-1); else return (FALSE); STcat(fullPath,"/"); STcat(fullPath,SYSTEM_LOCATION_SUBDIRECTORY); /* usually "ingres" */ STcat(fullPath,"/files/"); STcat(fullPath,MGR_STR_FILE_NAME); # endif /* ifdef VMS */ if ( LOfroms(PATH & FILENAME, fullPath, &loc) != OK ) return FALSE; if (SIfopen(&loc, "w", (i4)SI_TXT, OCFG_MAX_STRLEN, &pfile) != OK) return FALSE; if (altPath && *altPath) SIfprintf(pfile,"%s=%s\n",MGR_STR_PATH,altPath); SIfprintf(pfile,"%s=%s\n",MGR_STR_MANAGER, driverManager == MGR_VALUE_UNIX_ODBC ? MGR_STR_UNIX_ODBC : MGR_STR_CAI_PT); return TRUE; }
char * xfaddpath(char *filename, i4 in_or_out) { auto char *wholename; if (filename == NULL) { wholename = NULL; } else if (in_or_out == XF_INTOFILE && Xf_into_path != NULL) { STcopy(Xf_into_path, Whole_name); # ifdef UNIX if (Whole_name[STlength(Whole_name)-1] != '/') STcat(Whole_name, ERx("/")); # else # ifdef DESKTOP if (Whole_name[STlength(Whole_name)] != '\\') STcat(Whole_name, ERx("\\")); # endif /* DESKTOP */ # endif wholename = STcat(Whole_name, filename); } else if (in_or_out == XF_FROMFILE && Xf_from_path != NULL) { STcopy(Xf_from_path, Whole_name); # ifdef UNIX if (Whole_name[STlength(Whole_name)-1] != '/') STcat(Whole_name, ERx("/")); # else # ifdef DESKTOP if (Whole_name[STlength(Whole_name)] != '\\') STcat(Whole_name, ERx("\\")); # endif /* DESKTOP */ # endif wholename = STcat(Whole_name, filename); } else { LOcopy(&Xf_dir, Tmppath_buf, &Tmppath); /* add the file name to location */ LOfstfile(filename, &Tmppath); LOtos(&Tmppath, &wholename); } # ifdef NT_GENERIC xlate_backslash(wholename); # endif /* NT_GENERIC */ return (wholename); }
/* ** Name: log_errmsg - logs a user and VMS error status to errlog.log ** ** Description: ** This routine converts OpenVMS status code to an OpenVMS text ** error message, then puts the specified message with ": status" ** appended and then the VMS error message output to the errlog.log ** ** Inputs: ** usrmsg - user specified error text (24 characters) ** code - VMS status code ** flg - 0 send message to error.log only, ** 1 write to standard out and to errlog.log ** ** Outputs: ** None ** ** Returns: ** void ** ** History: ** 22-nov-1993 (eml) ** Created to allow the use ot ERoptlog to write all error messages. ** 31-jan-1994 (bryanp) ** Even if SYS$GETMSG fails, report the "usrmsg" anyway. */ static void log_errmsg( const char *usrmsg, const unsigned int code, const unsigned int flg ) { static $DESCALLOC( bufadr ); char stsbuf[256]; char msgbuf[256]; unsigned short len; STATUS status; $DESCFILL( bufadr, sizeof( stsbuf ), stsbuf ); status = sys$getmsg( code, &len, &bufadr, 0x0F, NULL ); if ( !(status & 1) ) { /* ** "code" was not a valid VMS message status, or at least not one which ** we could turn into message text. So just format it in hex. Assume ** that the result is exactly eight characters long (does CVlx null ** terminate its output? If so, could set len = STlength(stsbuf);). */ CVlx(code, stsbuf); len = 8; } STcopy( usrmsg, msgbuf ); STcat( msgbuf, ": Status" ); stsbuf[len] = '\0'; ERoptlog( msgbuf, stsbuf ); if ( flg ) { SIprintf( "%s = %s\n", msgbuf, stsbuf ); SIflush( stdout ); } return; }
void main(int argc, char *argv[]) { char buf[ 4096 ]; LPSTR lpCmdLine; char *startquote; char *endquote; STprintf(buf, ERx( "iiabf abf" )); lpCmdLine = GetCommandLine(); /* ** The current executable could have been invoked with the ** executable name in quotes. If that is the case, skip ** over the quotes before looking for the arguments. */ lpCmdLine = STskipblank( lpCmdLine, STlength(lpCmdLine) ); if ( *lpCmdLine == '"' ) { startquote = lpCmdLine; CMnext( startquote ); if ( (endquote = STindex( startquote, "\"", 0 )) != NULL ) { CMnext( endquote ); lpCmdLine = endquote; } } if ( lpCmdLine = STindex(lpCmdLine, " ", 0) ) STcat(buf, lpCmdLine); if ( execute(buf) != OK ) PCexit(FAIL); PCexit(OK); }
STATUS Trans_SEPfile(char **Token,LOCTYPE *typeOfLoc,bool Dont_free,i2 ME_tag) { STATUS syserr ; char *newstr = NULL ; char *temp_ptr = NULL ; char *tmp_buffer1 = NULL ; char *tmp_buffer2 = NULL ; char *tmp_ptr1 = NULL ; char *tmp_ptr2 = NULL ; char *tmp_ptr3 = NULL ; char *token_ptr = NULL ; char *tmp_token = NULL ; if (ME_tag == SEP_ME_TAG_NODEL && Dont_free != TRUE) Dont_free = TRUE; if (tracing&TRACE_PARM) { SIfprintf(traceptr,ERx("Trans_SEPfile> *Token = %s\n"),*Token); if (Dont_free) SIfprintf(traceptr,ERx(" Dont_free = TRUE\n")); else SIfprintf(traceptr,ERx(" Dont_free = FALSE\n")); } tmp_token = *Token; if ((token_ptr = FIND_SEPstring(tmp_token,ERx("@FILE("))) == NULL) { if (tracing&TRACE_PARM) SIfprintf(traceptr,ERx("Trans_SEPfile> FIND_SEPstring is FALSE\n")); return (FALSE); } if (tracing&TRACE_PARM) SIfprintf(traceptr,ERx("Trans_SEPfile> FIND_SEPstring is TRUE\n")); tmp_buffer1 = SEP_MEalloc(SEP_ME_TAG_MISC, 128, TRUE, (STATUS *) NULL); tmp_buffer2 = SEP_MEalloc(SEP_ME_TAG_MISC, 128, TRUE, (STATUS *) NULL); if (token_ptr != tmp_token) { for (tmp_ptr1 = tmp_buffer1, tmp_ptr2 = tmp_token; tmp_ptr2 != token_ptr; ) CMcpyinc(tmp_ptr2,tmp_ptr1); } else { tmp_ptr2 = token_ptr; } for (tmp_ptr3 = tmp_buffer2; CMcmpcase(tmp_ptr2,ERx(")")); ) CMcpyinc(tmp_ptr2,tmp_ptr3); CMcpychar(tmp_ptr2,tmp_ptr3); CMnext(tmp_ptr2); newstr = SEP_MEalloc(SEP_ME_TAG_MISC, 128, TRUE, (STATUS *) NULL); if ((syserr = getLocation(tmp_buffer2,newstr,typeOfLoc)) == OK) { if (tracing&TRACE_PARM) { SIfprintf(traceptr,ERx("Trans_SEPfile> newstr = %s\n"),newstr); SIfprintf(traceptr,ERx("Trans_SEPfile> tmp_buffer1 = %s\n"), tmp_buffer1); SIfprintf(traceptr,ERx("Trans_SEPfile> tmp_buffer2 = %s\n"), tmp_buffer2); } STcat(tmp_buffer1, newstr); STcat(tmp_buffer1, tmp_ptr2); if (tracing&TRACE_PARM) SIfprintf(traceptr,ERx("Trans_SEPfile> tmp_buffer1 = %s\n"), tmp_buffer1); temp_ptr = *Token; *Token = STtalloc(ME_tag,tmp_buffer1); if (Dont_free != TRUE) MEfree(temp_ptr); } MEfree(tmp_buffer1); MEfree(tmp_buffer2); MEfree(newstr); if (tracing&TRACE_PARM) SIfprintf(traceptr,ERx("Trans_SEPfile> *Token = %s\n"),*Token); return (syserr); }
/* ** Tokens are separated by a space or quote: ** Ex1: "ABC=WXX /BN""X"/CL --> 2 token (inside the quote, the "" is equivalent to \") ** 1) "ABC=WXX /BN""X" ** 2) /CL ** Ex2: MAKE IT --> ** 1) MAKE ** 2) IT */ LISTCHAR* MakeListTokens(char* zsText, int* pError) { char buff[8]; char strToken[512]; char stack[256]; LISTCHAR* pListToken = NULL; char tchszCur = '0'; char* pch = zsText; strToken[0] = '\0'; memset (stack, '\0', sizeof (stack)); while (*pch != '\0') { tchszCur = *pch; if (stack[0]) /* We're inside the quote (single or double) */ { char tchTop = stack_top(stack); if (tchTop == tchszCur) /* The current character is a quote (single or double) */ { if (PeekNextChar(pch) != tchTop) /* The next char is not a quote. (Here we found the end quote) */ { stack_PopState(stack); STprintf(buff, "%c", tchszCur); STcat (strToken, buff); } else { /* ** We consider the current quote the escaped of the next quote (consecutive quotes): */ STprintf(buff, "%c", tchszCur); STcat (strToken, buff); STprintf(buff, "%c", PeekNextChar(pch)); STcat (strToken, buff); CMnext(pch); } } else { STprintf(buff, "%c", tchszCur); STcat (strToken, buff); } CMnext(pch); continue; } /* ** We found a space (token separator): */ if (tchszCur == ' ' || tchszCur == '='/* || tchszCur == cSep(!strTokenSeparator.IsEmpty() && strTokenSeparator.Find(tchszCur) != -1)*/) { if (strToken[0]) { pListToken = AddToken(pListToken, strToken); strToken[0] = '\0'; } if (tchszCur == '=') { pListToken = AddToken(pListToken, "="); } } else { if (tchszCur == '\"' || tchszCur == '\'') /* Found the begin quote.*/ { /* ** Note: the begin quote cannote be an escape of quote because ** the quote can be escaped only if it is inside the quote: */ stack_PushState (stack, tchszCur); } STprintf(buff, "%c", tchszCur); STcat (strToken, buff); } CMnext(pch); if (*pch == '\0') { if (strToken[0]) { pListToken = AddToken(pListToken, strToken); strToken[0] = '\0'; } } } if (strToken[0]) { pListToken = AddToken(pListToken, strToken); strToken[0] = '\0'; } if (stack[0]) { pListToken = ListChar_Done(pListToken); if (pError) *pError = 1; } if (pError) *pError = 0; return pListToken; }
i4 main (int argc, char **argv) { STATUS status=OK; PTR drvH=NULL; char **list=NULL; ATTR_ID **attrList=NULL; char **defAttr=NULL; i4 count=0, attrCount = 0, retcount; i4 i; bool badCmdLine = FALSE, rmPkg = FALSE, has_default = FALSE, has_alt = FALSE, isReadOnly = FALSE, mgrSpecified = FALSE, batch = FALSE, def_or_alt=FALSE; i4 pathType = OCFG_SYS_PATH; char altPath[OCFG_MAX_STRLEN] = "\0"; char drvMgr[OCFG_MAX_STRLEN] = "\0"; char line[MAXLINE],prompt[MAXLINE]; char driverPath[OCFG_MAX_STRLEN]; char *dirPath; char driverName[OCFG_MAX_STRLEN]; char *ii_installation; char *p = NULL; char custName[OCFG_MAX_STRLEN]; char etxt[512]; ATTR_ID driverList[6] = { { DRV_ATTR_DRIVER, "\0" }, { DRV_ATTR_DRIVER_ODBC_VER, DRV_STR_VERSION }, { DRV_ATTR_DRIVER_READONLY, DRV_STR_N }, { DRV_ATTR_DRIVER_TYPE, DRV_STR_INGRES }, { DRV_ATTR_VENDOR, DRV_STR_INGRES_CORP }, { DRV_ATTR_DONT_DLCLOSE, DRV_STR_ONE } }; int drvCount = sizeof(driverList) / sizeof(driverList[0]); ATTR_ID **drvList = (ATTR_ID **)MEreqmem( (u_i2) 0, (u_i4)drvCount, TRUE, (STATUS *) NULL); for (i = 0; i < drvCount; i++) { drvList[i] = (ATTR_ID *)MEreqmem( (u_i2) 0, (u_i4)sizeof(ATTR_ID), TRUE, (STATUS *) NULL); drvList[i]->id = driverList[i].id; drvList[i]->value = (char *)MEreqmem( (u_i2) 0, (u_i4)OCFG_MAX_STRLEN, TRUE, (STATUS *) NULL); STcopy(driverList[i].value, drvList[i]->value); } if ( argc > 7 ) badCmdLine = TRUE; /* ** Parse the command line. Reject invalid arguments. */ if ( !badCmdLine && argc > 1 ) { if (checkArgs("-h", argc, argv, NULL, NULL ) ) { display_help(); PCexit(0); } if (checkArgs("-help", argc, argv, NULL, NULL ) ) { display_help(); PCexit(0); } if ( checkArgs("-batch", argc, argv, NULL, NULL ) ) batch = TRUE; if ( checkArgs("-rmpkg", argc, argv, NULL, NULL ) ) rmPkg = TRUE; if (checkArgs("-r", argc, argv, NULL, NULL ) ) isReadOnly = TRUE; if ( checkArgs("-p", argc, argv, altPath, NULL ) ) pathType = OCFG_ALT_PATH; if ( checkArgs("-m", argc, argv, NULL, drvMgr ) ) mgrSpecified = TRUE; } /* ** Set driver manager according to user input. Default is unixODBC. */ if (mgrSpecified && !STbcompare( drvMgr, 0, MGR_STR_CAI_PT, 0, TRUE ) ) driverManager = MGR_VALUE_CAI_PT; else driverManager = MGR_VALUE_UNIX_ODBC; /* ** If none of the arguments are recognized, flag an error. */ if ( !batch && !rmPkg && !isReadOnly && pathType != OCFG_ALT_PATH && !mgrSpecified && argc > 1) badCmdLine = TRUE; if ( badCmdLine ) { display_help(); PCexit(FAIL); } if ( isReadOnly ) STcopy(DRV_STR_Y, drvList[2]->value); else STcopy(DRV_STR_N, drvList[2]->value); if ( !writeMgrFile( altPath ) ) { SIprintf("Aborting due to error writing %s/files/%s\n", SYSTEM_LOCATION_SUBDIRECTORY, MGR_STR_FILE_NAME); PCexit(FAIL); } defAttr = getDefaultInfo(); if (defAttr == NULL) { SIprintf("Aborting due to error reading %s/install/%s\n", SYSTEM_LOCATION_VARIABLE, INFO_STR_FILE_NAME); PCexit(FAIL); } /* ** Get the path of the driver library and create the path/libname string. */ NMgtAt(SYSTEM_LOCATION_VARIABLE,&dirPath); /* usually II_SYSTEM */ if (dirPath != NULL && *dirPath) STlcopy(dirPath,driverPath,sizeof(driverPath)-20-1); else { SIprintf("Error--%s is not defined\n",SYSTEM_LOCATION_VARIABLE); PCexit(FAIL); } # ifdef VMS STcat(driverPath,"["); STcat(driverPath,SYSTEM_LOCATION_SUBDIRECTORY); /* usually "ingres" */ STcat(driverPath,".library]"); if ( isReadOnly ) STcat(driverPath,defAttr[INFO_ATTR_RONLY_DRV_FNAME]); else STcat(driverPath,defAttr[INFO_ATTR_DRIVER_FILE_NAME]); # else STcat(driverPath,"/"); STcat(driverPath,SYSTEM_LOCATION_SUBDIRECTORY); /* usually "ingres" */ STcat(driverPath,"/lib/"); if ( isReadOnly ) STcat(driverPath,defAttr[INFO_ATTR_RONLY_DRV_FNAME]); else STcat(driverPath,defAttr[INFO_ATTR_DRIVER_FILE_NAME]); # endif /* ifdef VMS */ STcopy(driverPath,drvList[0]->value); /* ** Initialize the cache from the odbcinst.ini file. */ openConfig(NULL, pathType, altPath, &drvH, &status); if (status != OK) { STprintf(etxt,"Could not open from path %s.\n", pathType == OCFG_ALT_PATH ? altPath : "/usr/local/etc"); display_err(etxt,status); PCexit(FAIL); } if (rmPkg) { delConfigEntry( drvH, defAttr[INFO_ATTR_DRIVER_NAME], &status ); delConfigEntry( drvH, defAttr[INFO_ATTR_ALT_DRIVER_NAME], &status ); closeConfig(drvH, &status); PCexit(OK); } /* ** Get the driver count. */ retcount = listConfig( drvH, count, list, &status ); if (status != OK) { STprintf(etxt,"Could not list drivers.\n"); display_err(etxt,status); PCexit(FAIL); } count = retcount; if (count) { /* ** Get the list of recognized drivers. */ list = (char **)MEreqmem( (u_i2) 0, (u_i4)(count * sizeof(char *)), TRUE, (STATUS *) NULL); for (i = 0; i < count; i++) list[i] = (char *)MEreqmem( (u_i2) 0, (u_i4)OCFG_MAX_STRLEN, TRUE, (STATUS *) NULL); listConfig( drvH, count, list, &status ); if (status != OK) { STprintf(etxt,"Could not list drivers.\n"); display_err(etxt,status); PCexit(FAIL); } } for (i = 0; i < count; i++) { def_or_alt = FALSE; if (!has_default) { has_default = STbcompare( list[i], 0, defAttr[INFO_ATTR_DRIVER_NAME], 0, TRUE ) == 0 ? TRUE : FALSE; if (has_default) def_or_alt = TRUE; } if (!has_alt) { has_alt = STbcompare( list[i], 0, defAttr[INFO_ATTR_ALT_DRIVER_NAME], 0, TRUE ) == 0 ? TRUE : FALSE; if (has_alt) def_or_alt = TRUE; } if (def_or_alt) { if ( !batch ) { STprintf(prompt, "\tInstallation has pre-defined version of %s.\n\tOverwrite? (Yes/No)", list[i]); if ( line_get( prompt, "", FALSE, line ) == EOF ) { SIprintf("ODBC driver installation safely aborted\n"); PCexit(OK); } STzapblank(line,line); if ( line[0] != 'y' && line [0] != 'Y' ) { SIprintf( "%s left untouched\n", list[i] ); continue; } } /* if (!batch) */ STcopy(list[i],driverName); setConfigEntry( drvH, driverName, drvCount, drvList, &status ); if (status != OK) { STprintf(etxt,"Could not write driver entry.\n"); display_err(etxt,status); PCexit(FAIL); } } /* if (has_default || has_alt) */ else if ( !batch ) { STprintf(prompt, "\tInstallation has custom version of %s.\n\tDelete? (Yes/No)", list[i]); if ( line_get( prompt, "", FALSE, line ) == EOF ) { SIprintf("ODBC driver installation safely aborted\n"); PCexit(OK); } STzapblank(line,line); if ( line[0] != 'y' && line [0] != 'Y' ) { SIprintf( "%s left untouched\n", list[i] ); continue; } STcopy(list[i],driverName); delConfigEntry( drvH, driverName, &status ); if (status != OK) { STprintf(etxt,"Could not write driver entry.\n"); display_err(etxt,status); PCexit(FAIL); } } /* if (!batch) && !has_default */ } /* for (count... */ if (!has_default) { setConfigEntry( drvH, defAttr[INFO_ATTR_DRIVER_NAME], drvCount, drvList, &status ); if (status != OK) { STprintf(etxt,"Could not write driver entry.\n"); display_err(etxt,status); PCexit(FAIL); } } if (!has_alt) { setConfigEntry( drvH, defAttr[INFO_ATTR_ALT_DRIVER_NAME], drvCount, drvList, &status ); if (status != OK) { STprintf(etxt,"Could not write driver entry.\n"); display_err(etxt,status); PCexit(FAIL); } } closeConfig(drvH, &status); if (status != OK) { STprintf(etxt,"Could not close driver info.\n"); display_err(etxt,status); PCexit(FAIL); } if (count) { for (i = 0; i < count; i++) MEfree((PTR)list[i]); MEfree((PTR)list); } for (i = 0; i < drvCount; i++) { MEfree((PTR)drvList[i]->value); MEfree((PTR)drvList[i]); } MEfree((PTR)drvList); PCexit(OK); }
STATUS ERsend(i4 flag, char *message, i4 msg_length, CL_ERR_DESC *err_code) { # ifdef NT_GENERIC static bool er_init = FALSE; static bool is_w95 = FALSE; # else /* !NT_GENERIC */ static int er_ifi = -2; static int ar_ifi = -2; # endif /* !NT_GENERIC */ STATUS status; char tmp_buf[ER_MAX_LEN]; char* logmsg = message; /* Check for bad paramters. */ CL_CLEAR_ERR( err_code ); if ((message == 0 || msg_length == 0) && flag != ER_AUDIT_MSG) return (ER_BADPARAM); if ((flag != ER_ERROR_MSG) && (flag != ER_AUDIT_MSG) && ( flag != ER_OPER_MSG)) return (ER_BADPARAM); # ifndef NT_GENERIC if (flag & ER_AUDIT_MSG) { key_t msg_key; char *ipc_number; struct { long mtype; char mtext[ER_MAX_LEN]; } msg; if (ar_ifi == -2) { NMgtAt("II_AUDIT_IPC", &ipc_number); if (ipc_number && ipc_number[0]) { CVal(ipc_number, &msg_key); ar_ifi = msgget(msg_key, 0); if (ar_ifi == -1) { SETCLERR(err_code, 0, ER_open); return(ER_NO_AUDIT); } } else { SETCLERR(err_code, 0, ER_open); return(ER_NO_AUDIT); } } /* Handle special case to connect only but not send message. */ if (msg_length == 0 && message == 0) return (OK); MEcopy(message, msg_length, msg.mtext); msg.mtype = 1; if (msgsnd(ar_ifi, &msg, msg_length, 0)) { SETCLERR(err_code, 0, ER_open); return(ER_BADSEND); } return (OK); } else # endif /* ! NT_GENERIC */ if (flag & ER_OPER_MSG) { char hostname[GL_MAXNAME]; STATUS status; message[msg_length] = EOS; TRdisplay("ER Operator:\"%s\"\n",message); if (!ERsysinit) ERinitsyslog(); # ifdef NT_GENERIC { wchar_t *wmessage = NULL; /* ** Update the ReportEvent to report information in the event log. */ if ( ReportEvent( EventLog, (WORD) EVENTLOG_INFORMATION_TYPE, (WORD) 0, /* event category */ (DWORD) I_ING_INFO, /* event identifier */ (PSID) NULL, (WORD) 1, /* number of strings */ (DWORD) 0, &message, NULL ) == FALSE) status = GetLastError(); if ( !er_init ) { char VersionString[256]; FUNC_EXTERN BOOL GVosvers(char *OSVersionString); GVosvers(VersionString); is_w95 = ( STstrindex(VersionString, "Microsoft Windows 9", 0, FALSE) != NULL ) ? TRUE : FALSE; if ( !is_w95 ) /* netapi32 only on NT */ { HANDLE hDll; if ((hDll = LoadLibrary(TEXT("netapi32.dll"))) != NULL) { pNetMessageNameAdd = (NET_API_STATUS (*)(LPCWSTR,LPCWSTR)) GetProcAddress(hDll, TEXT("NetMessageNameAdd")); pNetMessageNameDel = (NET_API_STATUS (*)(LPCWSTR,LPCWSTR)) GetProcAddress(hDll, TEXT("NetMessageNameDel")); pNetMessageBufferSend = (NET_API_STATUS (*)(LPCWSTR,LPCWSTR,LPCWSTR,LPBYTE,DWORD)) GetProcAddress(hDll, TEXT("NetMessageBufferSend")); } /* if any problem, pretend we don't support it */ if ( pNetMessageNameAdd == NULL || pNetMessageNameDel == NULL || pNetMessageBufferSend == NULL ) is_w95 = TRUE; } } if ( !is_w95 ) { /* ** Now, send the message to the server console, ** putting up a message box (if the messenger service ** is running. Everything must be in Unicode. */ if ( whostname[0] == 0 ) { unsigned int len = sizeof(hostname); /* ** get the hostname in Unicode format for use ** by messenger service */ GetComputerName( (char *)hostname, &len ); MultiByteToWideChar( GetACP(), 0, hostname, sizeof(hostname), whostname, sizeof(whostname) ); } /* initialize the messenger service */ status = (*pNetMessageNameAdd)( whostname, msgname ); if ( status != NERR_Success ) status = GetLastError(); /* Allocate a buffer for the Unicode */ wmessage = (wchar_t *) MEreqmem( 0, msg_length * sizeof(wchar_t), TRUE, &status ); if ( wmessage ) { /* copy the message to the Unicode buffer */ MultiByteToWideChar( GetACP(), 0, message, msg_length, wmessage, msg_length * sizeof(wchar_t) ); status = (*pNetMessageBufferSend)( whostname, msgname, NULL, (LPBYTE) wmessage, msg_length*sizeof(wchar_t) ); if ( status != NERR_Success ) status = GetLastError(); MEfree( (PTR)wmessage ); } /* re-initialize the messenger service */ status = (*pNetMessageNameDel)( whostname, msgname ); if ( status != NERR_Success ) status = GetLastError(); } } # elif defined(OS_THREADS_USED) && defined(any_aix) syslog_r( LOG_ALERT|LOG_ERR, message ); # else syslog( LOG_ALERT|LOG_ERR, message ); # endif /* NT_GENERIC */ } if (flag & ER_OPER_MSG) { i4 msglen = 0; char* host = PMhost(); MEfill( ER_MAX_LEN, 0, tmp_buf ); /* ** Format the message string for the event log. As the source is ** not known a fixed string of INGSYSLOG is used. */ TRformat( NULL, 0, tmp_buf, ER_MAX_LEN - 1, "%8.8t::[INGSYSLOG , 00000000]: %@ ", STlength(host), host ); msglen = STlength(tmp_buf); STcat( tmp_buf, message ); /* append original message */ msg_length += msglen; logmsg = tmp_buf; } status = ERlog( logmsg, msg_length, err_code ); return( status ); }
/* ** Name: Disp_Fname ** ** Decription: ** Takes the string ** content-disposition: form-data; name="xxxx" filename="yyyy" ** opens an ice temporary file and sets items in the variable string ** as xxxx=icetempfile. ** ** Inputs: ** sess ice session structure ** line pointer to the current line ** linelen length of the line ** ** Outputs: ** pos number of characters handled. ** ** Return: ** GSTAT_OK success ** other failure ** ** History: ** 23-Oct-98 (fanra01) ** Created. */ static GSTATUS Disp_Fname (WTS_SESSION* sess, char* line, i4 linelen, i4 * pos) { GSTATUS err = GSTAT_OK; PWTS_UPLOAD load= sess->load; char* p = line + *pos; char* name; i4 remain = linelen - *pos; i4 i = 0; i4 j = 0; UPLOADED_FILE* upload; if (STbcompare ("name", 4, p, 0, TRUE) == 0) { /* ** Find the first quote after name */ while ((*p != '\"') && (i < remain)) { CMbyteinc(i,p); CMnext(p); } CMbyteinc(i,p); /* skip the quote */ CMnext(p); name= p; while ((*p != '\"') && (i < remain)) { j+=CMbytecnt(p); CMbyteinc(i,p); CMnext(p); } CMbyteinc(i,p); CMnext(p); /* skip the quote */ while ((*p != ';') && (i < remain)) { CMbyteinc(i,p); CMnext(p); } CMbyteinc(i,p); CMnext(p); /* skip the semi colon */ /* ** Allocate space for the variable name a '=' character and an EOS */ if ((err = GAlloc (&load->varname, j+2, FALSE)) == GSTAT_OK) { MEfill (j+2, 0, load->varname); MECOPY_VAR_MACRO (name, j, load->varname); STcat (load->varname, "="); } while (CMwhite(p) && (i < remain)) { CMbyteinc(i, p); CMnext(p); } if (STbcompare ("filename", 8, p, 0, TRUE) == 0) { /* ** Find the first quote after filename */ while ((*p != '\"') && (i < remain)) { CMbyteinc(i,p); CMnext(p); } CMbyteinc(i,p); CMnext(p); /* skip the quote */ name= p; while ((*p != '\"') && (i < remain)) { j+=CMbytecnt(p); CMbyteinc(i,p); CMnext(p); } CMbyteinc(i,p); CMnext(p); /* skip the quote */ /* ** Allocate space for the filename and an EOS */ if ((err = GAlloc (&load->filename, j+1, FALSE)) == GSTAT_OK) { MEfill (j+1, 0, load->filename); MECOPY_VAR_MACRO (name, j, load->filename); asct_trace( ASCT_LOG )( ASCT_TRACE_PARAMS, "Upload session=%s file=%s", ((sess->act_session != NULL) ? ((sess->act_session->user_session) ? sess->act_session->user_session->name : "None") : "None"), load->filename ); } *pos += i; err = G_ME_REQ_MEM(0, upload, UPLOADED_FILE, 1); if (err == GSTAT_OK) { bool status; err = WCSRequest( 0, NULL, SYSTEM_ID, NULL, WSF_ICE_SUFFIX, &upload->file, &status); if (err == GSTAT_OK) { CLEAR_STATUS(WCSLoaded(upload->file, TRUE)); err = WCSOpen (upload->file, "w", SI_BIN, 0); if (err == GSTAT_OK) { i4 nlen = STlength (load->varname); i4 flen = STlength(upload->file->info->path); err = GAlloc(&load->icefname, flen + 1, FALSE); if (err == GSTAT_OK) { MECOPY_VAR_MACRO( upload->file->info->path, flen, load->icefname); err = GAlloc((PTR*)&sess->variable, sess->vlen + nlen + flen + 2, TRUE); if (err == GSTAT_OK && sess->variable != NULL) { if (sess->vlen > 0) { sess->variable[sess->vlen++] = '&'; } MECOPY_VAR_MACRO(load->varname, nlen, sess->variable + sess->vlen); sess->vlen += nlen; if (flen) { MECOPY_VAR_MACRO(load->icefname, flen, sess->variable + sess->vlen); sess->vlen += flen; upload->next = sess->list; sess->list = upload; } sess->variable[sess->vlen] = EOS; } } } else { CLEAR_STATUS(WCSRelease(&upload->file)); } } } load->state = US_FILE; } else { HandlerException (sess, line, linelen, pos); } } else { HandlerException (sess, line, linelen, pos); } return (err); }
/*{ ** Name: RSdelete - propagate a DELETE row ** ** Description: ** Propagates a DELETE transaction row, either by calling a remote ** database procedure or by executing a remote DELETE. ** ** Inputs: ** row - row of data ** ** Outputs: ** none ** ** Returns: ** OK ** else - error */ STATUS RSdelete( RS_TARGET *target, RS_TRANS_ROW *row) { char *stmt=NULL; char *proc_name; STATUS err; bool collision_processed = FALSE; RS_TBLDESC *tbl = row->tbl_desc; II_INT2 nparams; IIAPI_DESCRIPTOR pdesc[DB_MAX_COLS+1]; IIAPI_DATAVALUE pdata[DB_MAX_COLS+1]; DB_DELIM_STR *pnames = NULL; RS_CONN *conn = &RSconns[target->conn_no]; II_LONG procRet; II_PTR stmtHandle; IIAPI_GETEINFOPARM errParm; IIAPI_GETQINFOPARM getQinfoParm; IIAPI_STATUS status; IIAPI_DESCRIPTOR *col; IIAPI_DESCRIPTOR *pds; i4 num_cols=tbl->num_regist_cols; i4 row_width=tbl->row_width; stmt = RSmem_allocate(row_width,num_cols,DB_MAXNAME+8,128); if (stmt == NULL) return (FAIL); messageit(5, 1268, row->rep_key.src_db, row->rep_key.trans_id, row->rep_key.seq_no, target->db_no); err = RScollision(target, row, tbl, &collision_processed); if (err || collision_processed) { MEfree((PTR)stmt); return (err); } /* For URO targets, delete the base row. */ if (target->type == TARG_UNPROT_READ) { char *where_list=NULL; char objname[DB_MAXNAME*2+3]; where_list = RSmem_allocate(row_width,tbl->num_key_cols,DB_MAXNAME+8,0); if (where_list == NULL) { MEfree((PTR)stmt); return (FAIL); } /* ** Iterate through key_desc and create the WHERE list and ** prepare the column descriptors. The data will come directly ** from key_data. */ *where_list = EOS; for (col = row->key_desc, pds = pdesc; col < row->key_desc + tbl->num_key_cols; ++col, ++pds) { if (col != row->key_desc) STcat(where_list, ERx(" AND ")); /* ** The following is special case code to allow existing ** customers in non-SQL92 installations to propagate to ** Gateway databases that use uppercase table and ** column names. */ if (conn->name_case == UI_UPPERCASE) { STcopy(col->ds_columnName, objname); CVupper(objname); STcat(where_list, objname); } else { STcat(where_list, col->ds_columnName); } STcat(where_list, ERx(" = ~V")); *pds = *col; /* struct */ pds->ds_columnType = IIAPI_COL_QPARM; } STcopy(tbl->dlm_table_name, objname); if (target->type == TARG_UNPROT_READ && conn->name_case == UI_UPPERCASE) CVupper(objname); STprintf(stmt, ERx("DELETE FROM %s.%s WHERE %s"), tbl->rem_table_owner, objname, where_list); status = IIsw_query(conn->connHandle, &conn->tranHandle, stmt, tbl->num_key_cols, pdesc, row->key_data, NULL, NULL, &stmtHandle, &getQinfoParm, &errParm); status = RSerror_check(1556, ROWS_SINGLE_ROW, stmtHandle, &getQinfoParm, &errParm, NULL, tbl->table_name); MEfree((PTR)where_list); if (status != OK) { MEfree((PTR)stmt); return (status); } } /* For FP and PRO targets, call the remote database procedure. */ else { pnames = (DB_DELIM_STR *)RSmem_allocate(0, DB_MAX_COLS+1, sizeof(*pnames),0); if (pnames == NULL) { MEfree((PTR)stmt); return (FAIL); } proc_name = pnames[0]; if (RPtblobj_name(tbl->table_name, row->table_no, TBLOBJ_REM_DEL_PROC, proc_name) != OK) { messageit(1, 1816, ERx("RSdelete"), tbl->table_name); RSmem_free(stmt, (char *)pnames, NULL, NULL, NULL); return (RS_INTERNAL_ERR); } if (RSpdp_PrepDbprocParams(proc_name, target, tbl, row, pnames, &nparams, pdesc, pdata) != OK) { RSmem_free(stmt, (char *)pnames, NULL, NULL, NULL); return (RS_INTERNAL_ERR); } status = IIsw_execProcedure(conn->connHandle, &conn->tranHandle, nparams, pdesc, pdata, &procRet, &stmtHandle, &getQinfoParm, &errParm); status = RSerror_check(1573, ROWS_DONT_CARE, stmtHandle, &getQinfoParm, &errParm, NULL, proc_name); if (status != OK) { RSmem_free(stmt, (char *)pnames, NULL, NULL, NULL); return (status); } if (procRet) { messageit(1, procRet, row->rep_key.src_db, row->rep_key.trans_id, row->rep_key.seq_no, target->db_no, tbl->table_name); RSmem_free(stmt, (char *)pnames, NULL, NULL, NULL); return (procRet); } } RSstats_update(target->db_no, tbl->table_no, RS_DELETE); if (target->type != TARG_UNPROT_READ) RSmonitor_notify(&RSconns[target->conn_no], RS_INC_DELETE, RSlocal_conn.db_no, tbl->table_name, tbl->table_owner); RSmonitor_notify(&RSlocal_conn, RS_OUT_DELETE, target->db_no, tbl->table_name, tbl->table_owner); RSmem_free(stmt, (char *)pnames, NULL, NULL, NULL); return (OK); }
int main(int argc, char* argv[]) { time_t ltime; time_t tm_0, tm_1; char szIIdate[64]; char szCommandLineString[1024]; int i; double dtime; time( &tm_0 ); g_pLoadData = (LOADDATA*)malloc (sizeof(LOADDATA)); memset (g_pLoadData, 0, sizeof(LOADDATA)); memset (&g_ReadSizeEvent, 0, sizeof(g_ReadSizeEvent)); memset (&g_dataLoaderStruct, 0, sizeof (g_dataLoaderStruct)); g_dataLoaderStruct.nArraySize = 5; g_dataLoaderStruct.arrayFiles = (INFILES*)malloc (g_dataLoaderStruct.nArraySize * sizeof(INFILES)); memset (&g_mutexWrite2Log, 0, sizeof (g_mutexWrite2Log)); szIIdate[0] = '\0'; if (!IsInputDateCompatible(szIIdate)) { if (szIIdate[0]) DTSTRUCT_SetDateFormat(&g_dataLoaderStruct, szIIdate); } CreateDTLMutex(&g_mutexWrite2Log); /* ** Construct the command line string from the argv[] */ szCommandLineString[0] = '\0'; for (i=1; i<argc; i++) { if (i>1) STcat (szCommandLineString, " "); STcat (szCommandLineString, argv[i]); } /* ** Parse the command line string and update the ** Data Loader structure: */ memset (&g_cmd, 0, sizeof (g_cmd)); if (szCommandLineString[0]) { STATUS st; LOCATION lf; char* strFle = NULL; int nOk = ParseCommandLine (szCommandLineString, &g_cmd); if (nOk == 0) { free (g_pLoadData); /* ** Command line syntax error: */ SIprintf("Command line syntax error !!!\n"); return 1; } else { /* ** Check the MANDATORY command line: */ char* strItem = CMD_GetVnode(&g_cmd); if (strItem && !strItem[0]) { free (g_pLoadData); SIprintf("Command line option missing: the connection string <vnode> is mandatory.\n"); return 1; } strItem = CMD_GetControlFile(&g_cmd); if (strItem && !strItem[0]) { free (g_pLoadData); SIprintf("Command line option missing: the control file is mandatory.\n"); return 1; } } if (CMD_GetReadSize(&g_cmd) > 0) g_lReadSize = CMD_GetReadSize(&g_cmd); /* ** Create the log file if needed: */ strFle = CMD_GetLogFile(&g_cmd); if (!strFle || !strFle[0]) { char szBuff[1024]; char* pFound; STcopy (CMD_GetControlFile(&g_cmd), szBuff); pFound = STrindex (szBuff, ".ctl", -1); if (pFound && (STlength (pFound) == 4) && STcompare(pFound, ".ctl") == 0) { pFound[0] = '\0'; STcat (szBuff, ".log"); CMD_SetLogFile(&g_cmd, szBuff); } } else { char szBuff[1024]; char* pFound; STcopy (CMD_GetLogFile(&g_cmd), szBuff); pFound = STrindex (szBuff, ".", -1); if (!pFound) /* if logfile has no extension then add a .log extension */ { STcopy (strFle, szBuff); STcat (szBuff, ".log"); CMD_SetLogFile(&g_cmd, szBuff); } } LOfroms (PATH&FILENAME, strFle, &lf); st = SIfopen (&lf, "w", SI_TXT, DT_SI_MAX_TXT_REC, &g_fLogFile); if (st != OK) { g_fLogFile = NULL; SIprintf ("Failed to create log file\n"); } time( <ime ); WRITE2LOG3("%s: Release %s - Production on %s\n\n", INGRES_DATA_LOADER, g_sVersion, ctime(<ime)); WRITE2LOG0("Copyright (C) 2005-2006 Ingres Corporation. All Rights Reserved.\n\n"); WRITE2LOG1("Control File:\t%s\n", CMD_GetControlFile(&g_cmd)); if (!g_mutexWrite2Log.nCreated) { E_WRITE2LOG1("%s: Failed to create the Mutex 'g_mutexWrite2Log' for writing log file\n", INGRES_DATA_LOADER); CleanVariables(); return 1; } nOk = ParseControlFile(&g_dataLoaderStruct, &g_cmd); if (nOk == 0) { E_WRITE2LOG1("%s: Syntax error in the control file.\n", INGRES_DATA_LOADER); CleanVariables(); return 1; } else if (nOk == -1) { E_WRITE2LOG1("%s: Cannot open control file.\n", INGRES_DATA_LOADER); CleanVariables(); return 1; } else { int i; int nErrorAccesInfile=0; int nAllwithPosition=1; int nWithPosition = 0; int nPosError = 0; int nMax=0; int nWrongSep = 0; FIELDSTRUCT* pField = &(g_dataLoaderStruct.fields); FIELD* listField = pField->listField; int* aSet = GetControlFileMandatoryOptionSet(); if (aSet[0] == 0) { E_WRITE2LOG1("%s: LOAD DATA is mandatory at the begining of the control file.\n", INGRES_DATA_LOADER); CleanVariables(); return 1; } if (aSet[1] == 0 || !DTSTRUCT_GetInfile(&g_dataLoaderStruct, 0)) { E_WRITE2LOG1("%s: INFILE is mandatory in the control file.\n", INGRES_DATA_LOADER); CleanVariables(); return 1; } for (i=0; i<g_dataLoaderStruct.nFileCount; i++) { strFle = DTSTRUCT_GetInfile(&g_dataLoaderStruct, i); if (access(strFle, 0) == -1) { nErrorAccesInfile = 1; E_WRITE2LOG2("%s: INFILE '%s' cannot be accessed.\n", INGRES_DATA_LOADER, strFle); } } if (nErrorAccesInfile == 1) { CleanVariables(); return 1; } if (aSet[5] == 0 || STlength (DTSTRUCT_GetTable(&g_dataLoaderStruct)) == 0) { E_WRITE2LOG1("%s: INTO TABLE <table>, a table name is mandatory in the control file.\n", INGRES_DATA_LOADER); CleanVariables(); return 1; } if (aSet[6] == 0) { E_WRITE2LOG1("%s: APPEND key word is mandatory in the control file.\n", INGRES_DATA_LOADER); CleanVariables(); return 1; } if (aSet[8] == 0) { E_WRITE2LOG1("%s: The table columns must be specified in the control file.\n", INGRES_DATA_LOADER); CleanVariables(); return 1; } if (g_dataLoaderStruct.fields.szTerminator[0] && g_dataLoaderStruct.fields.szTerminator[0] == '\n') nWrongSep = 1; if (listField) { int p1 = 0, p2 = 0; while (listField) { if (listField->szTerminator[0] && strcmp (listField->szTerminator, "\\n") == 0) nWrongSep = 1; if (listField->pos1 <= p2) nPosError = 1; p1 = listField->pos1; p2 = listField->pos2; if (listField->pos1 <= 0 || listField->pos2 <= 0) nPosError = 1; if (listField->pos1 > listField->pos2 ) nPosError = 1; if (listField->pos2 > nMax) nMax = listField->pos2; if (listField->pos1 == 0 && listField->pos2 == 0) { listField = listField->next; nAllwithPosition = 0; continue; } nWithPosition = 1; listField = listField->next; } } if (nWrongSep == 1) { E_WRITE2LOG1("%s: You should not use the '\\n' as field separator.\n", INGRES_DATA_LOADER); CleanVariables(); return 1; } for (i=0; i<g_dataLoaderStruct.nFileCount; i++) { int j; if ((i>0) && (DTSTRUCT_GetFixLength(&g_dataLoaderStruct, 0) != DTSTRUCT_GetFixLength(&g_dataLoaderStruct, i))) { E_WRITE2LOG1("%s: FIX n, fixed record length must be the same for all INFILE clauses.\n", INGRES_DATA_LOADER); CleanVariables(); return 1; } /* ** Check if there are multiple bad files with the same name: */ for (j=i+1; j<g_dataLoaderStruct.nFileCount;j++) { if (stricmp (g_dataLoaderStruct.arrayFiles[i].badfile, g_dataLoaderStruct.arrayFiles[j].badfile)==0) { E_WRITE2LOG1("%s: Multiple bad files with the same name. You should specify different BADFILE for each INFILE.\n", INGRES_DATA_LOADER); CleanVariables(); return 1; } } } if (DTSTRUCT_GetFixLength(&g_dataLoaderStruct, 0) > 0) { if (nWithPosition && !nAllwithPosition) { E_WRITE2LOG1("%s: FIX n, fixed record length is specified, if you use POSITION (n, p) then all columns must use the POSITION.\n", INGRES_DATA_LOADER); CleanVariables(); return 1; } if (nPosError == 1) { E_WRITE2LOG1("%s: If you use POSITION (n, p) then n, p should be > 0.\n", INGRES_DATA_LOADER); CleanVariables(); return 1; } if (nMax > DTSTRUCT_GetFixLength(&g_dataLoaderStruct, 0)) { E_WRITE2LOG1("%s: In the last POSITION (n, p), p should be <= FIX value.\n", INGRES_DATA_LOADER); CleanVariables(); return 1; } } else { if (nWithPosition == 1) { E_WRITE2LOG1("%s: If you use POSITION (n, p) then you should also specify FIX value.\n", INGRES_DATA_LOADER); CleanVariables(); return 1; } } if (FIELDSTRUCT_GetColumnCount (pField) <= 0) { E_WRITE2LOG1("%s: The list of columns should be specified.\n", INGRES_DATA_LOADER); CleanVariables(); return 1; } } for (i=0; i<g_dataLoaderStruct.nFileCount; i++) { WRITE2LOG1("Data File:\t%s\n", DTSTRUCT_GetInfile(&g_dataLoaderStruct, i)); if (DTSTRUCT_GetFixLength(&g_dataLoaderStruct, i) > 0) WRITE2LOG1(" File processing option string: \"fix %d\"\n", DTSTRUCT_GetFixLength(&g_dataLoaderStruct, i)); WRITE2LOG1(" Bad File:\t%s\n", DTSTRUCT_GetBadfile(&g_dataLoaderStruct, i)); if (DTSTRUCT_GetDiscardFile(&g_dataLoaderStruct, i)) WRITE2LOG1(" Discard File:\t%s\n", DTSTRUCT_GetDiscardFile(&g_dataLoaderStruct, i)); } WRITE2LOG1(" (Allow %d discards)\n", DTSTRUCT_GetDiscardMax(&g_dataLoaderStruct)); WRITE2LOG0("\n\n"); WRITE2LOG1("Table %s\n", DTSTRUCT_GetTable(&g_dataLoaderStruct)); WRITE2LOG0("Insert option in effect for this table: APPEND\n"); /* WRITE2LOG1("Load to Table:\t%s\n", DTSTRUCT_GetTable(&g_dataLoaderStruct)); WRITE2LOG1("Read Size:\t%d\n", g_lReadSize); WRITE2LOG1("Parallel:\t%c\n", (CMD_GetParallel(&g_cmd) == 1)? 'Y': 'N'); */ if (!CheckForKnownDateFormat()) E_WRITE2LOG1("%s: The setting value of II_DATE_FORMAT is unknown.\n", INGRES_DATA_LOADER); memset (&g_mutexLoadData, 0, sizeof (DTLMUTEX)); if (!CreateDTLMutex(&g_mutexLoadData)) { E_WRITE2LOG1("%s: Failed to create the Mutex 'g_mutexLoadData'\n", INGRES_DATA_LOADER); CleanVariables(); return 1; } if (!CreateReadsizeEvent(&g_ReadSizeEvent)) { E_WRITE2LOG1 ("%s: Failed to create the Readsize Condition 'g_ReadSizeEvent'\n", INGRES_DATA_LOADER); CleanVariables(); return 1; } /* ** Create the session: */ nOk = INGRESII_llConnectSession(CMD_GetVnode(&g_cmd)); if (nOk == 0) /* SQL Error */ { char* strError = INGRESII_llGetLastSQLError(); if (strError && strError[0]) /* Error while connecting to the DBMS:*/ WRITE2LOG0(strError); CleanVariables(); return 1; } for (i=0; i<g_dataLoaderStruct.nFileCount; i++) { /* ** Start the thread that reads the input data file and ** puts the data in the FIFO queue: */ StartInputReaderThread(&g_dataLoaderStruct); /* ** The main thread begins a loop reading the data ** from the FIFO queue, transfer the data to the DBMS by ** using the COPY INTO callback program: */ nOk = StartTransferDataThread(&g_dataLoaderStruct); if (nOk == 0) /* SQL Error */ { char* strError = INGRESII_llGetLastSQLError(); if (strError && strError[0]) WRITE2LOG0 (strError); } g_dataLoaderStruct.nCurrent++; memset (g_pLoadData, 0, sizeof(LOADDATA)); } nOk = INGRESII_llDisconnectSession(1, 1); if (nOk == 0) /* SQL Error */ { char* strError = INGRESII_llGetLastSQLError(); if (strError && strError[0]) WRITE2LOG0 (strError); } } else { SIprintf("Usage: \tdataldr [vnode::]dbname[/serverclass] control=controlfile\n"); SIprintf("\t[log=logfile][parallel=y] [direct=y] [readsize=value]"); } time( &tm_1 ); dtime = difftime (tm_1, tm_0); WRITE2LOG0("\n\n"); WRITE2LOG1("Run began on %s", ctime(&tm_0)); WRITE2LOG1("Run ended on %s\n", ctime(&tm_1)); WRITE2LOG0("\n\n"); Time2Chars(dtime, szIIdate); WRITE2LOG1("Elapsed time was: %s\n", szIIdate); STcopy ("00:00:00", szIIdate); if ((g_lCpuEnded - g_lCpuStarted) >= 0) { double ds = 0.0, d1; int lms = g_lCpuEnded - g_lCpuStarted; while (lms >=1000) { lms -= 1000; ds += 1.0; } d1 = (double)lms / 10.0; /* 1/100 s == 10 ms */ d1 = d1 / 100.0; /* into the seconds */ ds += d1; Time2Chars(ds, szIIdate); } WRITE2LOG1("CPU time was: %s\n", szIIdate); /* ** Free the structure before exiting: */ CleanVariables(); return 0; }
void main(int argc, char *argv[]) { #define MAXBUF 4095 #define MAX_NAME 32 char buf[ MAXBUF+1 ]; char repbuf[ MAXBUF+1 ]; int iarg, ibuf, ichr; char *database = NULL; char username[MAX_NAME] = {""}; LOCATION tloc; LOCATION loc_out; LOCATION loc_in; char loc_buf[MAX_LOC + 1]; char tmp_buf[MAX_LOC + 1]; char otmp_buf[MAX_LOC + 1]; char dev[MAX_LOC + 1]; char path[MAX_LOC + 1]; char fprefix[MAX_LOC + 1]; char fsuffix[MAX_LOC + 1]; char version[MAX_LOC + 1]; char odev[MAX_LOC + 1]; char opath[MAX_LOC + 1]; char ofprefix[MAX_LOC + 1]; char ofsuffix[MAX_LOC + 1]; char oversion[MAX_LOC + 1]; char *new_filename; char *temploc; CL_ERR_DESC err_code; char *p1 = NULL; bool usergiven = FALSE; bool Repmod = FALSE; bool nowait = TRUE; char waitflag[3]; if (argc < 2) { usage(); PCexit(FAIL); } /* Get the temporary path location */ NMloc(TEMP, PATH, NULL, &tloc); LOcopy(&tloc, tmp_buf, &loc_in); LOtos(&tloc, &temploc); LOcopy(&tloc, otmp_buf, &loc_out); /* Get the new filename for path location */ LOuniq(ERx("usrmod"), ERx("sql"), &loc_in); LOtos(&loc_in, &new_filename); LOuniq(ERx("usrmod"), ERx("out"), &loc_out); /* Get just the filename for copydb code */ LOdetail(&loc_in, dev, path, fprefix, fsuffix, version); if ( *fsuffix != '\0' ) { STcat(fprefix, "."); STcat(fprefix, fsuffix); } /* Get just the filename for copydb code */ LOdetail(&loc_out, odev, opath, ofprefix, ofsuffix,oversion); STcat(ofprefix, "."); STcat(ofprefix, ofsuffix); STprintf(buf, ERx("copydb -with_modify -nodependency_check -with_index -with_comments -no_persist -parallel -no_repmod -group_tab_idx -no_warn -d\"%s\" -infile=\"%s\" -outfile=\"%s\"" ), temploc, fprefix,ofprefix); ibuf = STlength(buf); for (iarg = 1; (iarg < argc) && (ibuf < MAXBUF); iarg++) { if( STscompare( argv[ iarg ], 1, ERx( "-" ), 1 ) == 0 ) { p1 = argv[ iarg ]; (void) CMnext( p1 ); if ( (STlength(p1) == 0) || !(((STscompare( p1, 1, ERx( "u" ), 1 ) == 0 ) || (STscompare( p1, 5, ERx( "noint" ), 5 ) == 0 ) || (STscompare( p1, 6, ERx( "repmod" ), 6 ) == 0 ) || (STscompare( p1, 1, ERx( "w" ), 6 ) == 0 ) || (STscompare( p1, 6, ERx( "online"), 6 ) == 0 )) && ( argc > 2 ) )) { usage(); PCexit(FAIL); } /* ** Get the username if the -u flag is passed in ** with the input */ if (STscompare( p1, 1, ERx( "u" ), 1 ) == 0 ) { STcopy(&argv[iarg][2] , (char *)&username); usergiven = TRUE; } else if (STscompare( p1, 1, ERx( "r" ), 1 ) == 0 ) { Repmod = TRUE; continue; } else if (STscompare( p1, 1, ERx( "w"), 1 ) == 0) { nowait = TRUE; continue; } } if( STscompare( argv[ iarg ], 1, ERx( "+" ), 1 ) == 0 ) { p1 = argv[ iarg ]; (void) CMnext( p1 ); if (STscompare( p1, 1, ERx( "w" ), 1 ) == 0 ) { nowait = FALSE; continue; } else { usage(); PCexit(FAIL); } } if((database == NULL) && (STscompare( argv[ iarg ], 1, ERx( "+" ), 1 ) != 0) && (STscompare( argv[ iarg ], 1, ERx( "-" ), 1 ) != 0)) { database = argv[ iarg ]; } buf[ibuf++] = ' '; for (ichr = 0; (argv[iarg][ichr] != '\0') && (ibuf < MAXBUF); ichr++, ibuf++) { buf[ibuf] = argv[iarg][ichr]; } buf[ibuf] = '\0'; } /* ** Execute the command. */ if( PCcmdline((LOCATION *) NULL, buf, PC_WAIT, (LOCATION *) NULL, &err_code) != OK ) PCexit(FAIL); /* ** we should run the sql script ** sql dbname < new_filename ** if -u flag given then run: ** sql -uusername dbname < new_filename */ if (usergiven) STprintf(buf, ERx( "sql -u%s -s %s <%s" ), username, database, new_filename ); else STprintf(buf, ERx( "sql -s %s <%s" ), database, new_filename ); /* ** Execute the command. */ if( PCcmdline((LOCATION *) NULL, buf, PC_WAIT, (LOCATION *) NULL, &err_code) != OK ) { STprintf(buf, ERx(" Warning: Non-persistent objects associated with the base table\n in the failed query may have been lost. Please refer to\n %s\n to determine whether any corrective action is required.\n"), new_filename); SIfprintf(stdout, buf); PCexit(FAIL); } /* Now execute the repmod command if the replicator ** modify is also required by the user (-repmod) */ if (Repmod) { if (nowait) STcopy("-w", waitflag) ; else STcopy("+w", waitflag) ; if (usergiven) STprintf(repbuf, ERx( "repmod -u%s %s %s" ), username, database, waitflag ); else STprintf(repbuf, ERx( "repmod %s %s" ), database, waitflag ); if( PCcmdline((LOCATION *) NULL, repbuf, PC_WAIT, (LOCATION *) NULL, &err_code) != OK ) PCexit(FAIL); } /* ** Delete the location */ LOdelete(&loc_in); LOdelete(&loc_out); PCexit(OK); }
int main(int argc, char *argv[]) { #define MAXBUF 4095 char buf[ MAXBUF+1 ]; int iarg, ibuf, ichr; bool debug = FALSE; CL_ERR_DESC err_code; char *p1 = NULL; char pid[MAXBUF]; char *database = ERx(""); char *user = ERx(""); char *xmlfile = ERx(""); char sql_fname[LO_NM_LEN + 1]; char *work_dir = NULL; char directory[MAX_LOC + 1]; char *tmp_dir = NULL; char tmp_buf[MAX_LOC + 1]; char subdir_buf[MAX_LOC + 1]; char sql_loc_buf[MAX_LOC + 1]; char *progname; LOCATION tmp_dir_loc; LOCATION tmp_subdir_loc; LOCATION tmp_buff_loc; LOCATION curr_loc; LOCATION sql_file_loc; char *password = ERx(""); char *groupid = ERx(""); ARGRET rarg; i4 pos; LOCATION xmlfile_loc; FILE *xmlfile_read; STATUS stat = FAIL; char dbuf[256]; char encode[32]; u_i4 tmppid; TM_STAMP tm_stamp; /* Tell EX this is an ingres tool. */ (void) EXsetclient(EX_INGRES_TOOL); /* Call IIUGinit to initialize character set attribute table */ if ( IIUGinit() != OK) PCexit(FAIL); progname = ERget(F_XM0006_IMPXML); FEcopyright(progname, ERx("2001")); /* ** Get arguments from command line */ /* required parameters */ if (FEutaopen(argc, argv, ERx("xmlimport")) != OK) PCexit(FAIL); /* database name is required */ if (FEutaget(ERx("database"), 0, FARG_PROMPT, &rarg, &pos) != OK) PCexit(FAIL); database = rarg.dat.name; if (FEutaget(ERx("xmlfile"), 0, FARG_PROMPT, &rarg, &pos) != OK) PCexit(FAIL); xmlfile = rarg.dat.name; if (FEutaget(ERx("user"), 0, FARG_FAIL, &rarg, &pos) == OK) user = rarg.dat.name; if (FEutaget(ERx("password"), 0, FARG_FAIL, &rarg, &pos) == OK) { char *IIUIpassword(); if ((password = IIUIpassword(ERx("-P"))) == NULL) { FEutaerr(BADARG, 1, ERx("")); PCexit(FAIL); } } if (FEutaget(ERx("groupid"), 0, FARG_FAIL, &rarg, &pos) == OK) groupid = rarg.dat.name; if (FEutaget(ERx("debug"), 0, FARG_FAIL, &rarg, &pos) == OK) debug = TRUE; ibuf = STlength(buf); /* b121678: pid is no longer based on process id, but it's ** a random number instead. */ PCpid(&tmppid); TMget_stamp(&tm_stamp); MHsrand2(tmppid * tm_stamp.tms_usec); STprintf(pid, "%x", MHrand2()); #ifdef xDEBUG SIprintf(" the pid is: %s \n", pid); #endif /* create the sql file */ /* Avoid a name like "foo.xml.sql" on VMS, use pid.sql instead */ STcopy(pid, sql_fname); STcat(sql_fname, ".sql"); /* ** create in the temp location a directory ** with the name pid. set this directory ** as the working directory for impxml */ NMloc (TEMP, PATH, NULL, &tmp_dir_loc); /* make a location for TMP loc */ /* print location name */ LOcopy (&tmp_dir_loc, tmp_buf, &tmp_buff_loc); LOtos (&tmp_buff_loc, &tmp_dir); #ifdef xDEBUG SIprintf ("temploc: %s \n", tmp_dir); #endif /* make a subdir location with filename, pid */ STcopy (pid, subdir_buf); /* Initialize result loc so that everyone is happy */ LOcopy (&tmp_dir_loc, sql_loc_buf, &sql_file_loc); /* Generate location for temp subdirectory */ if (LOfaddpath (&tmp_dir_loc, subdir_buf, &sql_file_loc) != OK) { IIUGerr(E_XM0007_Locname_Failed, UG_ERR_FATAL, 2, tmp_dir, subdir_buf); /* NOTREACHED */ } /* print the location name */ LOcopy (&sql_file_loc, tmp_buf, &tmp_buff_loc); LOtos (&tmp_buff_loc, &work_dir); #ifdef xDEBUG SIprintf ("work dir loc: %s \n", work_dir); #endif /* create the subdir */ if (LOcreate (&sql_file_loc) != OK) { IIUGerr(E_XM0008_Create_Temp_Dir, UG_ERR_ERROR, 1, work_dir); PCexit(FAIL); } STcopy(work_dir, directory); #ifdef xDEBUG SIprintf ("sql file name: %s \n", sql_fname); SIprintf ("xml file name: %s \n", xmlfile); #endif /* Execute the command impxml */ STprintf (buf, ERx( "impxml -d=\"%s\" -o=\"%s\" " ), directory, sql_fname); /* encoding? */ if ( (LOfroms(PATH & FILENAME, xmlfile, &xmlfile_loc) != OK) || (SIopen(&xmlfile_loc, "r", &xmlfile_read) != OK) || (xmlfile_read == NULL) ) { IIUGerr(E_XM0009_Cannot_Open_File, UG_ERR_ERROR, 1, xmlfile); PCexit(FAIL); } /* scan XML declaration for encoding, if any */ if (stat = SIgetrec(dbuf, sizeof(dbuf) - 1, xmlfile_read) == OK) { char *d = dbuf; i4 i = 0; for (d = dbuf; d != (dbuf + sizeof(dbuf)); d++) { if (MEcmp(d, ERx("encoding="), sizeof(ERx("encoding=")) - 1) == 0) { d += sizeof(ERx("encoding=")); while (MEcmp (d, "\'", sizeof(char)) && MEcmp(d, "\"", sizeof(char))) MEcopy(d++, sizeof(char), &encode[i++]); encode[i++] = MIN_CHAR; encode[i] = EOS; STcat(buf, ERx("-x=")); STcat(buf, encode); break; } } } else if (stat != ENDFILE) { /* unable to read file, report error */ IIUGerr(E_XM000A_Cannot_Read_File, UG_ERR_ERROR, 1, xmlfile); PCexit(FAIL); } stat = SIclose(xmlfile_read); STcat(buf, xmlfile); #ifdef xDEBUG SIprintf ( " query send: %s \n", buf); #endif /* Execute the command. */ if( PCcmdline((LOCATION *) NULL, buf, PC_WAIT, (LOCATION *)NULL, &err_code) != OK ) { if (!debug) LOdelete(&sql_file_loc); PCexit(FAIL); } /* ** we should run the sql script ** sql dbname < new_filename */ /* save the current location */ LOcopy(&sql_file_loc, tmp_buf, &curr_loc); /* make a full location path to the location first */ LOfroms(FILENAME, sql_fname, &tmp_buff_loc); LOstfile(&tmp_buff_loc, &curr_loc); LOcopy (&curr_loc, tmp_buf, &tmp_buff_loc); LOtos (&tmp_buff_loc, &tmp_dir); #ifdef xDEBUG SIprintf ("sql file is: %s \n", tmp_dir); #endif /* No space between < and input file for VMS */ STprintf(buf, ERx( "sql -s %s %s %s %s <%s" ), database, user, password, groupid, tmp_dir); #ifdef xDEBUG SIprintf (" query send: %s \n", buf); #endif /* ** Execute the command. */ if( PCcmdline((LOCATION *) NULL, buf, PC_WAIT, (LOCATION *)NULL, &err_code) != OK ) { if (!debug) LOdelete(&sql_file_loc); PCexit(FAIL); } /* ** Delete the location */ if (!debug) LOdelete(&sql_file_loc); PCexit(OK); }
STATUS ip_batch(i4 argc, char *argv[]) { i4 argvx; PKGBLK *pkg; uchar opid; uchar option = opNONE; LOCATION outloc; char line[ MAX_MANIFEST_LINE + 1 ]; LISTELE *lp; /* no command line arguments except mkresponse ** or exresponse allowed for ingbuild in form mode */ if ((argc < 2) || ((argc ==2) && ((pmode == TRUE) || (mkresponse == TRUE) || (exresponse == TRUE))) || ((argc ==3) && (((mkresponse == TRUE) || (exresponse == TRUE)) && (respfilename != NULL)))) /* No command-line args? */ return OK; /* Fine, must be forms mode; return without setting flag. */ batchMode = TRUE; /* We're in command-line mode. */ batchOutf = stdout; /* For now, we'll direct output to the terminal. */ /* Top of loop through the non-positional arguments on the command line. */ for (argvx = 1; argvx < argc; argvx++) { if (argv[argvx][0] != '-') /* Not a switch? Time for positional arg. */ break; /* Get the option code for the current flag and deal with it... */ switch (opid = lookup(&argv[argvx][1])) { /* instruct ingbuild to skip set up */ case opNOSETUP: noSetup = TRUE; break; case opEXPRESS: eXpress = TRUE; break; case opPATCH: continue; /* -install=<list of features> */ case opINSTALL: if (option != opNONE || argval == NULL) USAGE; option = opid; featlist = argval; if( !STbcompare("ice", 3, featlist, STlength(featlist), TRUE) || !STbcompare("ice64", 5, featlist, STlength(featlist), TRUE) ) Install_Ice = TRUE; break; /* ** -version, -products, -all, -describe ** (All the options that don't require values.) */ case opVERSION: case opPACKAGES: case opDESCRIBE: case opALL: if (option == opNONE) { featlist = argval; option = opid; break; } case opIGNORE: ignoreChecksum = TRUE; break; case opEXRESPONSE: exresponse = TRUE; break; case opRESPFILE: break; /* -acceptlicense is still accepted for forward compatibility */ case opACCEPTLIC: #if LICENSE_PROMPT acceptLicense = TRUE; #endif break; /* Fall through */ default: USAGE; } } /* ** When we break from the flags loop, we must have a maximum of one ** remaining argument... */ if (argvx < (argc - 1)) /* Too many non-flags at the end of the line. */ USAGE; if (exresponse && (option == opNONE)) { char *def_file="ingrsp.rsp"; char *filename; FILE *respfile; if (respfilename != NULL) filename = respfilename; else filename = def_file; if (OK == ip_open_response (ERx(""), filename, &respfile, ERx( "r" )) ) { bool found = FALSE; char line[MAX_MANIFEST_LINE + 1]; char *pkg_set = ERx("_set=YES"); char *setp, *realloc; i4 pkglen; i4 buflen = MAX_MANIFEST_LINE + 1; i4 space = buflen; while (SIgetrec((char *)&line, MAX_MANIFEST_LINE, respfile) == OK ) { /* Check for _set=YES */ setp = STstrindex(line, pkg_set, 0, 1); if(setp != NULL) { if(found == FALSE) { featlist = ip_alloc_blk( buflen ); } *setp = NULLCHAR; pkglen = STlength(line); if(found == TRUE) { if(space < (pkglen + 1)) { buflen += MAX_MANIFEST_LINE; realloc = ip_alloc_blk( buflen ); STcopy(featlist, realloc); MEfree(featlist); featlist = realloc; } STcat(featlist, ","); space--; } else { found = TRUE; } STcat(featlist, line); space = space - pkglen; } } /* end read loop */ ip_close_response(respfile); if( found == TRUE) { /* Need to test this does not override any other options that ** may be valid */ option = opINSTALL; } } else { PCexit ( FAIL ); } } /* ** If we have no positionals, no distribution device was provided on ** the command line. That might or might not be ok... */ if (argvx == argc) { switch (option) { case opPATCH: case opVERSION: case opPACKAGES: case opDESCRIBE: break; /* ...yes. */ default: USAGE; /* ...no. */ } } else /* We got a positional, so copy it into the global field. */ { STcopy(argv[argvx], distribDev); if( !IPCLsetDevice( distribDev ) ) USAGE; } if (option == opNONE) /* No option? Default to "all". */ option = opALL; if ( option == opALL ); batch_opALL = TRUE; /* ** First processing pass. If the option doesn't involve doing actual ** installation, just do whatever needs to be done, and return. ** If it's an installation option, mark all requested packages ** as selected, and continue. */ switch (option) { case opPACKAGES: SIfprintf(batchOutf,ERget(S_ST0179_pkg_list_header)); for( lp = distPkgList.head; lp != NULL; lp = lp->cdr ) { pkg = (PKGBLK *) lp->car; if( ip_is_visible( pkg ) || ip_is_visiblepkg( pkg ) ) { SIfprintf( batchOutf, ERx("\t%-16s %-30s\n"), pkg->feature,pkg->name ); } } return OK; case opVERSION: if (instRelID == NULL) { IIUGerr(E_ST017B_not_present,0,1,SystemProductName); return FAIL; } if (featlist == NULL) { SIfprintf(batchOutf, ERx("%s\n"), instRelID); return OK; } if (!apply_list(proc_version)) return FAIL; return OK; case opINSTALL: SCAN_LIST(distPkgList, pkg) { pkg->selected = NOT_SELECTED; } if (!apply_list(proc_install)) return FAIL; break; case opDESCRIBE: _VOID_ apply_list(proc_describe); return OK; default: for( lp = distPkgList.head; lp != NULL; lp = lp->cdr ) { pkg = (PKGBLK *) lp->car; switch (option) { case opALL: if ( ip_is_visible(pkg) || ip_is_visiblepkg( pkg ) ) pkg->selected = SELECTED; break; } } } /* ** If we haven't left yet, that must mean we have an install-class ** option, i.e. one that's going to cause us to actually install ** something. First of all, let's make sure that the user has ** defined II_AUTH_STRING and has selected something to install... */ #ifndef INGRESII if( !authStringEnv ) { IIUGerr( E_ST0117_license_required, 0, 0 ); return( FAIL ); } #endif /* INGRESII */ SCAN_LIST(distPkgList, pkg) { if (pkg->selected == SELECTED) break; } if (pkg == NULL) /* Got all the way through the list? Nothing selected! */ USAGE; /* If Ingres is up, no go; otherwise, do the installation... */ switch (option) { case opALL: case opINSTALL: if (ip_sysstat() == IP_SYSUP) { IIUGerr(E_ST0178_installation_is_up, 0, 2, SystemProductName, installDir); return FAIL; } #if LICENSE_PROMPT if( !acceptLicense ) license_prompt(); #endif ip_install(NULL); break; } return OK; }