/* Copyright (c) 1994-7 Ruslan R. Laishev. All Right reserved !!! */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "smbdef.h" #include #include typedef unsigned int uint; typedef unsigned long ulong; typedef signed int sint; typedef signed long slong; typedef signed int sshort; typedef signed long ushort; int Msg$Process (ulong); void log_error (char *, int); int log_message (char *); int TransWrite (char *,char *); ulong stream = 0; ulong structure_level = SMBMSG$K_STRUCTURE_LEVEL ; ulong status; ulong request; char Msg_Buff [ 1024 ]; $DESCRIPTOR (Msg_Buff_dsc,Msg_Buff); void main (void) { int privs; privs = PRV$M_NETMBX | PRV$M_TMPMBX; status= sys$setprv(1,&privs,0,0); if ( !$VMS_STATUS_SUCCESS (status) ) { log_error ("sys$setprv",status); lib$stop (status); } /* Init */ if ( SS$_NORMAL != (status = smb$initialize (&structure_level)) ) { log_error ("smb$initialize",status); lib$stop (status); } while (1) { /* Wait for message */ if ( SS$_NORMAL != (status = smb$check_for_message ()) ) { sleep (16); continue; } /* Process messages */ if ( SS$_NORMAL != (status = smb$read_message (&stream,&Msg_Buff_dsc,&request)) ) { log_error ("smb$read_message",status); lib$stop (status); } Msg$Process (request); } sys$exit(SS$_NORMAL); } /* --------------------------------------------------------------------- */ int Msg$Process (ulong request) { ulong context, item_code; struct rc {ulong n_cond, e_cond; } rc; ushort size; static char dev [ 256 ]; char iFile [ 130 ]; char buff [512]; $DESCRIPTOR(buff_dsc,buff); switch (request) { /* --------------------------------------------------------------------- */ case SMBMSG$K_START_STREAM: context = 0; item_code = SMBMSG$K_DEVICE_NAME; if ( SS$_NORMAL != (status = smb$read_message_item (&Msg_Buff_dsc,&context,&item_code, &buff_dsc,&size)) ) { if (SMB$_NOMOREITEMS != status) { log_error ("smb$read_message_item",status); lib$stop (status); } } buff [ size ] = 0; log_message(buff); if ( !sscanf ( buff, "%s",dev) ) { log_error ("Please check value with /ON=..",SS$_IVDEVNAM); sys$exit (SS$_IVDEVNAM); } if ( SS$_NORMAL != (status = smb$send_to_jobctl (&stream,&request)) ) { log_error ("smb$send_to_jobctl",status); sys$exit (status); } break; /* --------------------------------------------------------------------- */ case SMBMSG$K_START_TASK: context = 0; item_code = 0; while ( (item_code != SMBMSG$K_FILE_SPECIFICATION) && (status != SMB$_NOMOREITEMS) ) { if ( SS$_NORMAL != (status = smb$read_message_item (&Msg_Buff_dsc,&context,&item_code, &buff_dsc,&size)) ) { if (SMB$_NOMOREITEMS != status) { log_error ("smb$read_message_item",status); sys$exit (status); } } }; /* end while */ buff [ size ] = 0; if (SMB$_NOMOREITEMS != status) { strcpy (iFile,buff); if ( SS$_NORMAL != (status = smb$send_to_jobctl (&stream,&request)) ) { log_error ("smb$send_to_jobctl - SMBMSG$K_START_TASK",status); sys$exit (status); } } if ( rc.e_cond = TransWrite (iFile,dev) ) { log_error("TransWrite report error",rc.e_cond); request = SMBMSG$K_TASK_COMPLETE; rc.n_cond = 1; if ( SS$_NORMAL != (status = smb$send_to_jobctl (&stream,&request,0,0,0,&rc)) ) { log_error ("smb$send_to_jobctl - SMBMSG$K_STOP_TASK",status); sys$exit (status); } } else { request = SMBMSG$K_TASK_COMPLETE; if ( SS$_NORMAL != (status = smb$send_to_jobctl (&stream,&request)) ) { log_error ("smb$send_to_jobctl - SMBMSG$K_TASK_COMPLETE",status); sys$exit (status); } } break; /* --------------------------------------------------------------------- */ case SMBMSG$K_STOP_STREAM: case SMBMSG$K_RESET_STREAM: case SMBMSG$K_PAUSE_TASK: case SMBMSG$K_STOP_TASK: sys$exit(0); case SMBMSG$K_RESUME_TASK: default: if ( SS$_NORMAL != (status = smb$send_to_jobctl (&stream,&request)) ) { log_error ("smb$send_to_jobctl",status); sys$exit (status); } } /* end switch */ return 0; } /* --------------------------------------------------------------------- */ void log_error ( char *prefix, int vms_status ) { char msg[1024]; sprintf (msg, "%s,Error code=:%d",prefix,vms_status ); log_message ( msg ); if ( vms_status ) { sprintf (msg, "Error text=:%s", strerror ( EVMSERR, vms_status ) ); log_message ( msg ); } } int log_message ( char *msg ) { FILE *logfile; unsigned long current_time; char *current_time_str; char *log_file_name; int time_len; if ( ! (log_file_name = getenv ("RUR_IN_SYM_LOG")) ) return 0; if ( ! (logfile = fopen ( log_file_name, "a+" )) ) { if ( ! (logfile = fopen ( log_file_name, "w" )) ) { sys$exit (vaxc$errno); } } time ( ¤t_time ); current_time_str = ctime ( ¤t_time ); time_len = strlen ( current_time_str ); fprintf (logfile, "%.*s, %s\n", time_len - 1, current_time_str, msg); fclose (logfile); } FILE *finp, *fout; int LatRus_Mode0= 0, LatRus_Mode1= 0, LatRus_Mode = 0; char *cp, *TransRus = {""}, *TransLat[] = { {"A"}, {"B"}, {"V"}, {"G"}, {"D"}, {"E"}, {"E"}, {"J"}, {"Z"}, {"I"}, {"iu"}, {"ia"}, {"i"}, {"K"}, {"L"}, {"M"}, {"N"}, {"O"}, {"P"}, {"R"}, {"S"}, {"T"}, {"U"}, {"F"}, {"H"}, {"C"}, {"ch"}, {"sh"}, {"sc"}, {"Y"}, {"x"}, {"e"}}; char ibuff [1024]; char obuff [1024]; int Coding1 (void); int Coding2 (void); //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- int Coding0 (void) { while (fgets (ibuff,sizeof(ibuff) - 5,finp) ) { if ( Coding1() ) { Coding2(); if ( EOF == fputs (obuff,fout) ) { log_error("Writting",vaxc$errno); return vaxc$errno; } } else { if ( EOF == fputs (ibuff,fout) ) { log_error("Writting",vaxc$errno); return vaxc$errno; } } } return 0; } //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- int Coding1 (void) { static char *TransOn0 = " :20 /"; static char *TransOn1 = " :'"; static char *TransOff = "------"; static char *TransField[] = { {" :50 /"},{" :57D/"},{" :59 /"}, {" :70 /"},{" :72 /"},{NULL} }; int TransFieldN = 5, i; /* Searching signature of russian payment: transliteration signature at begin of 20 field (:') */ if ( strstr (ibuff,TransOn0) && strstr(ibuff,TransOn1) ) { LatRus_Mode = 1; return 0;}; if ( LatRus_Mode ) { if ( NULL != strstr (ibuff,TransOff) ) { LatRus_Mode = 0; return 0;} } else return 0; /* Checking for begin of new field */ if ( (ibuff[4]==':') && (ibuff[8]=='/') ) { for (i = 0 ; i < TransFieldN ;i++) { if ( strstr(ibuff,TransField[i]) ) return (LatRus_Mode0 = 1); } LatRus_Mode0 = 0; } return LatRus_Mode0; } //--------------------------------------------------------------------------- int Coding2 (void) { int i; char *icp; char *ocp; icp = &ibuff[0]; ocp = &obuff[0]; memcpy(obuff,ibuff,40); if ( (ibuff[4]==':') && (ibuff[8]=='/') ) { if ( 41 >= strlen(ibuff) ) return 0; } icp += 40; ocp += 40; LatRus_Mode1 = 0; for (;*icp != 0;) { if ( (*icp == 'Y') && (*(icp+1) == 'X') ) { icp += 2; LatRus_Mode1 ^= 1; continue; } if ( (!LatRus_Mode1) && LatRus_Mode0 ) { for (i = 0;i < 32;i++) if ( !strncmp(icp,TransLat[i],strlen(TransLat[i])) ) break; if (i < 32) { *ocp = *(TransRus+i); icp += strlen(TransLat[i]); ocp++; continue; } } *ocp = *icp; ocp++; icp++; } *ocp = 0; return 0; } /*-----------------------------------------------------------*/ int TransWrite (char *iFile,char *oFile) { char fl_nm [ 256 ]; char *cp; log_message(iFile); log_message(oFile); /* strcpy(fl_nm,oFile); if ( cp = strrchr(iFile,']') ) strcat(fl_nm,cp+1); else strcat(fl_nm,iFile); log_message(fl_nm); */ //------ if( NULL == (finp=fopen(iFile,"r")) ) { log_error("Open for input",vaxc$errno); return vaxc$errno; } if( NULL == (fout=fopen(oFile,"w")) ) { log_error("Open for output",vaxc$errno); return vaxc$errno; } if ( Coding0() ) { log_error("Coding0 ()",vaxc$errno); return vaxc$errno; } if ( fclose(finp) ) { log_error("Close input",vaxc$errno); return vaxc$errno; } if ( fclose(fout) ) { log_error("Close output",vaxc$errno); return vaxc$errno; } //------ return 0; }