static gboolean parse_url(gchar *url, gboolean *json, gchar **method) { if (*url != '/') return FALSE; mbb_base_var_lock(hup_var); if (http_url_prefix == NULL) url++; else if (! strncmp(url, http_url_prefix, http_url_prefix_len)) url += http_url_prefix_len; else url = NULL; mbb_base_var_unlock(hup_var); if (url == NULL) return FALSE; if (strncmp(url, JSON_PREFIX, STRSIZE(JSON_PREFIX))) *json = FALSE; else { url += STRSIZE(JSON_PREFIX); *json = TRUE; } if (strlen(url)) *method = url; else *method = NULL; return TRUE; }
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Support routines for the directives * * skipToEndif * * Skip through the text to a matching "#endif". We do this when we * have processed the allowable text (found an "#else" after * accepting the preceeding text) or when encountering a "#if*def" * while skipping a block of text due to a failed test. */ static char* skipToEndif(char* pzStart) { char* pzScan = pzStart; char* pzRet; for (;;) { /* * 'pzScan' is pointing to the first character on a line. * Check for a directive on the current line before scanning * later lines. */ if (*pzScan == '#') pzScan++; else { char* pz = strstr(pzScan, zCheckList); if (pz == NULL) AG_ABEND(aprf(zNoEndif, pCurCtx->pzCtxFname, pCurCtx->lineNo)); pzScan = pz + STRSIZE(zCheckList); } while (IS_WHITESPACE_CHAR(*pzScan)) pzScan++; switch (findDirective(pzScan)) { case DIR_ENDIF: { /* * We found the endif we are interested in */ char* pz = strchr(pzScan, NL); if (pz != NULL) pzRet = pz+1; else pzRet = pzScan + strlen(pzScan); goto leave_func; } case DIR_IFDEF: case DIR_IFNDEF: /* * We found a nested ifdef/ifndef */ pzScan = skipToEndif(pzScan); break; default: /* * We do not care what we found */ break; /* ignore it */ } /* switch (findDirective(pzScan)) */ } leave_func: while (pzStart < pzRet) { if (*(pzStart++) == NL) pCurCtx->lineNo++; } return pzRet; }
static char* skipToEndmac(char* pzStart) { char* pzScan = pzStart; char* pzRet; for (;;) { /* * 'pzScan' is pointing to the first character on a line. * Check for a directive on the current line before scanning * later lines. */ if (*pzScan == '#') pzScan++; else { char* pz = strstr(pzScan, zCheckList); if (pz == NULL) AG_ABEND(aprf(zNoEndif, pCurCtx->pzCtxFname, pCurCtx->lineNo)); pzScan = pz + STRSIZE(zCheckList); } while (IS_WHITESPACE_CHAR(*pzScan)) pzScan++; if (findDirective(pzScan) == DIR_ENDMAC) { /* * We found the endmac we are interested in */ char* pz = strchr(pzScan, NL); if (pz != NULL) pzRet = pz+1; else pzRet = pzScan + strlen(pzScan); break; } } while (pzStart < pzRet) { if (*(pzStart++) == NL) pCurCtx->lineNo++; } return pzRet; }
int parseRawFormatChetco(char * msg, RawMessage * m, bool showJson) { unsigned int pgn, src, i; unsigned int tstamp; time_t t; struct tm tm; char * p; if (*msg == 0 || *msg == '\n') { return 1; } if (sscanf(msg, "$PCDIN,%x,%x,%x,", &pgn, &tstamp, &src) < 3) { logError("Error reading Chetco message: %s", msg); if (!showJson) fprintf(stdout, "%s", msg); return 2; } t = (time_t) tstamp / 1000; localtime_r(&t, &tm); strftime(m->timestamp, sizeof(m->timestamp), "%Y-%m-%d-%H:%M:%S", &tm); sprintf(m->timestamp + strlen(m->timestamp), ",%u", tstamp % 1000); p = msg + STRSIZE("$PCDIN,01FD07,089C77D!,03,"); // Fixed length where data bytes start; for (i = 0; *p != '*'; i++) { if (scanHex(&p, &m->data[i])) { logError("Error reading message, scanned %zu bytes from %s/%s, index %u", p - msg, msg, p, i); if (!showJson) fprintf(stdout, "%s", msg); return 2; } } return setParsedValues(m, 0, pgn, 255, src, i + 1); }
NET_API_STATUS RxNetShareSetInfo( IN LPTSTR ServerName, IN LPTSTR NetName, IN DWORD Level, IN LPBYTE Buffer, OUT LPDWORD ParmError OPTIONAL ) /*++ Routine Description: Performs the NetShareSetInfo API at a remote down-level server Arguments: ServerName - where to perform the request NetName - name of thing for which to set info Level - level of information - 0, 1, 2, 1004, 1005, 1006, 1009 Buffer - buffer containing info at defined level ParmError - pointer to invalid parameter ordinal Return Value: NET_API_STATUS Success = NERR_Success Failure = ERROR_INVALID_LEVEL ERROR_INVALID_PARAMETER (return code from RxRemoteApi) --*/ { DWORD infolen; // size of structure DWORD parmnum; // we have to cobble down-level parmnum from Level LPDESC pDesc16; // used in call to GetShareInfoDescriptors LPDESC pDesc32; // ditto. Only interested in length of info structure LPDESC pDescSmb; // ditto. Only interested in length of info structure UNREFERENCED_PARAMETER(ParmError); #if DBG // // The ServerName parameter must be a non-NUL(L) string. We know this must // be so since (presumably) the server name was used as the criteria to get // here. Ensure that this is so (in the non-release version) so we trap // stupid mistakes early // NetpAssert(ServerName != NULL); NetpAssert(*ServerName); #endif // // Perform parameter validity checks: // NetName must be non-NULL pointer to non-NULL string // Buffer must be non-NULL pointer to non-NULL pointer // Level must be in range // NB. Assumes that DWORD is unsigned! // if (!VALID_STRING(NetName) || !Buffer) { return ERROR_INVALID_PARAMETER; } // BUGBUG - are there any manifests for these numbers? if (Level < 1 || (Level > 2 && (Level < 1004 || (Level > 1006 && Level != 1009)))) { return ERROR_INVALID_LEVEL; } // // We can set individual info fields using the levels > 1000. We have to // create level and parmnum info for down-level // if (Level > 2) { // // Individual fields are indicated by the old (down-level) parmnum, // augmented by 1000. Split level and parmnum parameters // parmnum = Level - PARMNUM_BASE_INFOLEVEL; Level = 2; pDesc16 = REM16_share_info_2_setinfo; pDesc32 = REM32_share_info_2_setinfo; pDescSmb = REMSmb_share_info_2_setinfo; switch (parmnum) { case 4: // remark case 9: // password infolen = STRSIZE( (LPTSTR)Buffer ); break; case 5: // permissions case 6: // max uses infolen = sizeof(WORD); break; } } else { // // let GetShareInfoDescriptors give us the size of the buffer // that NetShareSetInfo thinks its getting. We have no other way of // determining this (have we?). Levels 0 - 2 set the entire structure // GetShareInfoDescriptors(Level, &pDesc16, &pDesc32, &pDescSmb, &infolen); parmnum = PARMNUM_ALL; } return RxRemoteApi(API_WShareSetInfo, ServerName, // where it will run REMSmb_NetShareSetInfo_P, // parameter descriptor pDesc16, // Data descriptor/16-bit pDesc32, // Data descriptor/32-bit pDescSmb, // Data descriptor/SMB NULL, // Aux descriptor/16-bit NULL, // Aux descriptor/32-bit NULL, // Aux descriptor/SMB FALSE, // this call needs user to be logged on NetName, // pointer to thing to set info on Level, // level of info Buffer, // pointer to buffer sourced by caller infolen, // size of our buffer // // in this case, the field index and parm num are the // same value // MAKE_PARMNUM_PAIR(parmnum, parmnum) // what we're setting ); }
void cstart(multiboot_info_t *bootinfo) { crt_Init(); crt_WriteString(STRSIZE("Starting GraField OS...")); spin(); }
int main(int argc, char **argv) { int r; int handle; struct termios attr; char * name = argv[0]; char * device = 0; struct stat statbuf; int pid = 0; int speed; setProgName(argv[0]); while (argc > 1) { if (strcasecmp(argv[1], "-version") == 0) { printf("%s\n", VERSION); exit(0); } else if (strcasecmp(argv[1], "-w") == 0) { writeonly = 1; } else if (strcasecmp(argv[1], "-p") == 0) { passthru = 1; } else if (strcasecmp(argv[1], "-r") == 0) { readonly = 1; } else if (strcasecmp(argv[1], "-v") == 0) { verbose = 1; } else if (strcasecmp(argv[1], "-t") == 0 && argc > 2) { argc--; argv++; timeout = strtol(argv[1], 0, 10); logDebug("timeout set to %ld seconds\n", timeout); } else if (strcasecmp(argv[1], "-s") == 0 && argc > 2) { argc--; argv++; speed = strtol(argv[1], 0, 10); switch (speed) { case 38400: baudRate = B38400; break; case 57600: baudRate = B57600; break; case 115200: baudRate = B115200; break; case 230400: baudRate = B230400; break; #ifdef B460800 case 460800: baudRate = B460800; break; #endif #ifdef B921600 case 921600: baudRate = B921600; break; #endif default: baudRate = speed; break; } logDebug("speed set to %d (%d) baud\n", speed, baudRate); } else if (strcasecmp(argv[1], "-d") == 0) { setLogLevel(LOGLEVEL_DEBUG); } else if (strcasecmp(argv[1], "-o") == 0) { outputCommands = 1; } else if (!device) { device = argv[1]; } else { device = 0; break; } argc--; argv++; } if (!device) { fprintf(stderr, "Usage: %s [-w] -[-p] [-r] [-v] [-d] [-s <n>] [-t <n>] device\n" "\n" "Options:\n" " -w writeonly mode, no data is read from device\n" " -r readonly mode, no data is sent to device\n" " -p passthru mode, data on stdin is sent to stdout but not to device\n" " -v verbose\n" " -d debug\n" " -s <n> set baudrate to 38400, 57600, 115200, 230400" #ifdef B460800 ", 460800" #endif #ifdef B921600 ", 921600" #endif "\n" " -t <n> timeout, if no message is received after <n> seconds the program quits\n" " -o output commands sent to stdin to the stdout \n" " <device> can be a serial device, a normal file containing a raw log,\n" " or the address of a TCP server in the format tcp://<host>[:<port>]\n" "\n" " Examples: %s /dev/ttyUSB0\n" " %s tcp://192.168.1.1:10001\n" "\n" COPYRIGHT, name, name, name); exit(1); } retry: logDebug("Opening %s\n", device); if (strncmp(device, "tcp:", STRSIZE("tcp:")) == 0) { handle = open_socket_stream(device); logDebug("socket = %d\n", handle); isFile = true; if (handle < 0) { fprintf(stderr, "Cannot open NGT-1-A TCP stream %s\n", device); exit(1); } } else { handle = open(device, O_RDWR | O_NOCTTY | O_NONBLOCK); logDebug("fd = %d\n", handle); if (handle < 0) { logAbort("Cannot open NGT-1-A device %s\n", device); } if (fstat(handle, &statbuf) < 0) { logAbort("Cannot determine device %s\n", device); } isFile = S_ISREG(statbuf.st_mode); } if (isFile) { logInfo("Device is a normal file, do not set the attributes.\n"); } else { logDebug("Device is a serial port, set the attributes.\n"); memset(&attr, 0, sizeof(attr)); if (cfsetspeed(&attr, baudRate) < 0) { logAbort("Could not set baudrate %d\n", speed); } attr.c_cflag |= CS8 | CLOCAL | CREAD; attr.c_iflag |= IGNPAR; attr.c_cc[VMIN] = 1; attr.c_cc[VTIME] = 0; tcflush(handle, TCIFLUSH); tcsetattr(handle, TCSANOW, &attr); logDebug("Device is a serial port, send the startup sequence.\n"); writeMessage(handle, NGT_MSG_SEND, NGT_STARTUP_SEQ, sizeof(NGT_STARTUP_SEQ)); sleep(2); } for (;;) { unsigned char msg[BUFFER_SIZE]; size_t msgLen; int r = isReady(writeonly ? INVALID_SOCKET : handle, readonly ? INVALID_SOCKET : 0, INVALID_SOCKET, timeout); if ((r & FD1_ReadReady) > 0) { if (!readNGT1(handle)) { break; } } if ((r & FD2_ReadReady) > 0) { if (!readIn(msg, sizeof(msg))) { break; } if (!passthru) { parseAndWriteIn(handle, msg); } if (outputCommands) { fprintf(stdout, "%s", msg); fflush(stdout); } } else if (writeonly) { break; } } close(handle); return 0; }
/*=directive shell * * text: * Invokes @code{$SHELL} or @file{/bin/sh} on a script that should * generate AutoGen definitions. It does this using the same server * process that handles the back-quoted @code{`} text. * @strong{CAUTION}@: let not your @code{$SHELL} be @code{csh}. =*/ static char* doDir_shell(char* pzArg, char* pzScan) { static char const zShellText[] = "Computed Definitions"; static char const zEndShell[] = "\n#endshell"; tScanCtx* pCtx; char* pzText = pzScan; /* * The output time will always be the current time. * The dynamic content is always current :) */ outTime = time(NULL); /* * IF there are no data after the '#shell' directive, * THEN we won't write any data * ELSE we have to find the end of the data. */ if (strncmp(pzText, zEndShell+1, STRSIZE(zEndShell)-1) == 0) return pzScan; { static char const noend[] = "Missing #endshell after '#shell' in %s on line %d\n"; char* pz = strstr(pzScan, zEndShell); if (pz == NULL) AG_ABEND(aprf(noend, pCurCtx->pzCtxFname, pCurCtx->lineNo)); while (pzScan < pz) { if (*(pzScan++) == NL) pCurCtx->lineNo++; } *pzScan = NUL; } /* * Advance the scan pointer to the next line after '#endshell' * IF there is no such line, * THEN the scan will resume on a zero-length string. */ pzScan = strchr(pzScan + STRSIZE(zEndShell), NL); if (pzScan == NULL) pzScan = (void*)zNil; /* * Save the scan pointer into the current context */ pCurCtx->pzScan = pzScan; /* * Run the shell command. The output text becomes the * "file text" that is used for more definitions. */ pzText = runShell(pzText); if (pzText == NULL) return pzScan; if (*pzText == NUL) { AGFREE(pzText); return pzScan; } /* * Get the space for the output data and for context overhead. * This is an extra allocation and copy, but easier than rewriting * 'loadData()' for this special context. */ pCtx = (tScanCtx*)AGALOC(sizeof(tScanCtx) + strlen(pzText) + 4, "shell output"); /* * Link the new scan data into the context stack */ pCtx->pCtx = pCurCtx; pCurCtx = pCtx; /* * Set up the rest of the context structure */ AGDUPSTR(pCtx->pzCtxFname, zShellText, "shell text"); pCtx->pzScan = pCtx->pzData = (char*)(pCtx+1); pCtx->lineNo = 0; strcpy(pCtx->pzScan, pzText); AGFREE(pzText); return pCtx->pzScan; }
/* * skipToElseEnd * * Skip through the text to a matching "#endif" or "#else" or * "#elif*def". We do this when we are skipping code due to a failed * "#if*def" test. */ static char* skipToElseEnd(char* pzStart) { char* pzScan = pzStart; char* pzRet; for (;;) { /* * 'pzScan' is pointing to the first character on a line. * Check for a directive on the current line before scanning * later lines. */ if (*pzScan == '#') pzScan++; else { char* pz = strstr(pzScan, zCheckList); if (pz == NULL) AG_ABEND(aprf(zNoEndif, pCurCtx->pzCtxFname, pCurCtx->lineNo)); pzScan = pz + STRSIZE(zCheckList); } while (IS_WHITESPACE_CHAR(*pzScan)) pzScan++; switch (findDirective(pzScan)) { case DIR_ELSE: /* * We found an "else" directive for an "ifdef"/"ifndef" * that we were skipping over. Start processing the text. */ ifdefLevel++; /* FALLTHROUGH */ case DIR_ENDIF: { /* * We reached the end of the "ifdef"/"ifndef" we were * skipping (or we dropped in from above). * Start processing the text. */ char* pz = strchr(pzScan, NL); if (pz != NULL) pzRet = pz+1; else pzRet = pzScan + strlen(pzScan); goto leave_func; } case DIR_IFDEF: case DIR_IFNDEF: /* * We have found a nested "ifdef"/"ifndef". * Call "skipToEndif()" to find *its* end, then * resume looking for our own "endif" or "else". */ pzScan = skipToEndif(pzScan); break; default: /* * We either don't know what it is or we do not care. */ break; } /* switch (findDirective(pzScan)) */ } leave_func: while (pzStart < pzRet) { if (*(pzStart++) == NL) pCurCtx->lineNo++; } return pzRet; }
VOID _CRTAPI1 main( int argc, char *argv[] ) { NET_API_STATUS ApiStatus; PADMIN_OTHER_INFO Admin; PUSER_OTHER_INFO User; PPRINT_OTHER_INFO Print; LPWSTR pString; DWORD dwTime; DWORD VariableInfoSize; DWORD TmpSize; // Size of var portion plus 1 mergestring CHAR response; DWORD i; UNREFERENCED_PARAMETER(argc); UNREFERENCED_PARAMETER(argv); (VOID) printf( "AlTest: starting up...\n" ); // // Alerter service should not crash if username and computer name are // not part of the mailslot message // User = (PUSER_OTHER_INFO) VariableInfo; User->alrtus_errcode = ALERT_CloseBehindError; User->alrtus_numstrings = 1; VariableInfoSize = sizeof(USER_OTHER_INFO); // // Write the mergestring into buffer. In the case of a close behind error // it is the name of the file which failed to close. // #define FILENAME TEXT("PLUTO.TXT") STRCPY((LPTSTR) ((DWORD) User + VariableInfoSize), FILENAME); VariableInfoSize += ((STRLEN(FILENAME) + 1) * sizeof(TCHAR)); TmpSize = VariableInfoSize; // // This should not cause a message to be sent because neither the user // nor computer name is specified. // ApiStatus = NetAlertRaise( ALERT_USER_EVENT, // alert event name VariableInfo, VariableInfoSize ); (VOID) printf( "AlTest 1(USER_ALERT): done NetAlertRaise, status=" FORMAT_API_STATUS ", expect=" FORMAT_API_STATUS ".\n", ApiStatus, ERROR_INVALID_PARAMETER ); for (i = 1; i < 3; i ++) { VariableInfoSize = TmpSize; // // Now include username and computer name // #define USERNAME TEXT("DANL") #define COMPUTERNAME TEXT("danl1") STRCPY((LPTSTR) ((DWORD) User + VariableInfoSize), USERNAME); VariableInfoSize += ((STRLEN(USERNAME) + 1) * sizeof(TCHAR)); // // Put a sequence number at the end of the username // //VariableInfo[STRLEN(USERNAME) - 1] = i + '1'; STRCPY((LPTSTR) ((DWORD) User + VariableInfoSize), COMPUTERNAME); VariableInfoSize += ((STRLEN(COMPUTERNAME) + 1) * sizeof(TCHAR)); // // User alert should be raised successfully. // ApiStatus = NetAlertRaiseEx( ALERT_USER_EVENT, VariableInfo, VariableInfoSize, TEXT("SERVER") ); // service name (VOID) printf( "AlTest 2(USER_ALERT): done NetAlertRaiseEx, status=" FORMAT_API_STATUS ".\n", ApiStatus ); } //-------------------------- // Raise an admin alert // (audit log full) //-------------------------- Admin = (PADMIN_OTHER_INFO) VariableInfo; Admin->alrtad_errcode = ALERT_AuditLogFull; Admin->alrtad_numstrings = 0; ApiStatus = NetAlertRaiseEx( ALERT_ADMIN_EVENT, VariableInfo, sizeof(ADMIN_OTHER_INFO), TEXT("SERVER") ); // service name (VOID) printf( "AlTest 3(ADMIN_ALERT): done NetAlertRaiseEx(admin), status=" FORMAT_API_STATUS ".\n", ApiStatus ); //-------------------------- // Raise an admin alert // (user-defined text) //-------------------------- Admin = (PADMIN_OTHER_INFO) VariableInfo; Admin->alrtad_errcode = MAXULONG; Admin->alrtad_numstrings = 1; pString = (LPWSTR)((LPBYTE)VariableInfo+sizeof(ADMIN_OTHER_INFO)); wcscpy(pString,L"This is a User-Defined Message"); ApiStatus = NetAlertRaiseEx( ALERT_ADMIN_EVENT, VariableInfo, sizeof(ADMIN_OTHER_INFO)+WCSSIZE(pString), TEXT("SERVER") ); // service name (VOID) printf( "AlTest 3.5(ADMIN_ALERT): done NetAlertRaiseEx(admin), status=" FORMAT_API_STATUS ".\n", ApiStatus ); //--------------------------------- // Raise an alert (NON-EX version) // (user-defined text) //--------------------------------- { LPSTD_ALERT pStdAlert = (LPSTD_ALERT)VariableInfo; pStdAlert->alrt_timestamp = 1; wcscpy(pStdAlert->alrt_eventname,ALERT_ADMIN_EVENT); wcscpy(pStdAlert->alrt_servicename, L"Dan'sSvc"); Admin = (LPADMIN_OTHER_INFO)((LPBYTE)VariableInfo + sizeof(STD_ALERT)); pString = (LPWSTR)((LPBYTE)VariableInfo + sizeof(STD_ALERT) + sizeof(ADMIN_OTHER_INFO)); Admin->alrtad_errcode = MAXULONG; Admin->alrtad_numstrings = 1; wcscpy(pString, L"Some User Data"); VariableInfoSize = sizeof(STD_ALERT)+ sizeof(ADMIN_OTHER_INFO) + STRSIZE(pString); ApiStatus = NetAlertRaise( ALERT_ADMIN_EVENT, // alert event name VariableInfo, VariableInfoSize ); (VOID) printf( "AlTest 3.6(ADMIN_ALERT): done NetAlertRaise(admin), status=" FORMAT_API_STATUS ".\n", ApiStatus ); } //--------------------------------- // PRINT ALERT: PRINTER OFFLINE // (queued for printing) //--------------------------------- time((time_t *)&dwTime); printf("time=%d\n",dwTime); Print = (PPRINT_OTHER_INFO) VariableInfo; Print->alrtpr_jobid = 626; Print->alrtpr_status = PRJOB_DESTOFFLINE; Print->alrtpr_submitted = dwTime; Print->alrtpr_size = 72496; // // All print Alerts have the PRINT_OTHER_INFO structure // followed by these same strings in this order... // VariableInfoSize = sizeof(PRINT_OTHER_INFO); // Computername STRCPY((LPTSTR) ((DWORD) Print + VariableInfoSize), TEXT("DANL2-SHAUNAB")); VariableInfoSize += ((STRLEN(TEXT("DANL2-SHAUNAB")) + 1) * sizeof(TCHAR)); // username STRCPY((LPTSTR) ((DWORD) Print + VariableInfoSize), TEXT("DANL1")); VariableInfoSize += ((STRLEN(TEXT("DANL1")) + 1) * sizeof(TCHAR)); // queuename STRCPY((LPTSTR) ((DWORD) Print + VariableInfoSize), TEXT("8/1154 CORPA 14DBDE")); VariableInfoSize += ((STRLEN(TEXT("8/1154 CORPA 14DBDE")) + 1) * sizeof(TCHAR)); // destination STRCPY((LPTSTR) ((DWORD) Print + VariableInfoSize), TEXT("8/1154 CORPA 14DBDE(CORPA)")); VariableInfoSize += ((STRLEN(TEXT("8/1154 CORPA 14DBDE(CORPA)")) + 1) * sizeof(TCHAR)); // status string STRCPY((LPTSTR) ((DWORD) Print + VariableInfoSize), TEXT("ERROR")); VariableInfoSize += ((STRLEN(TEXT("ERROR")) + 1) * sizeof(TCHAR)); #ifdef REMOVE ApiStatus = NetAlertRaiseEx( ALERT_PRINT_EVENT, VariableInfo, VariableInfoSize, TEXT("SPOOLER") ); // service name (VOID) printf( "AlTest 4(PRINT_ALERT): done NetAlertRaiseEx(print), status=" FORMAT_API_STATUS ".\n", ApiStatus ); // // Wait for user reponse before continuing. // printf("continue?....\n"); response = _getch(); if ((response == 'n') || (response == 'N')) { return; } #endif //REMOVE //--------------------------------------- // PRINT ALERT: JOB_COMPLETE //--------------------------------------- Print->alrtpr_status = PRJOB_COMPLETE | PRJOB_QS_PRINTING; Print->alrtpr_jobid = 2434; ApiStatus = NetAlertRaiseEx( ALERT_PRINT_EVENT, VariableInfo, VariableInfoSize, TEXT("SPOOLER") ); // service name (VOID) printf( "AlTest 4.5(PRINT_ALERT): done NetAlertRaiseEx(print), status=" FORMAT_API_STATUS ".\n", ApiStatus ); //--------------------------------------- // PRINT ALERT: NO PAPER - JOB_QUEUED //--------------------------------------- Print->alrtpr_status = PRJOB_DESTNOPAPER; Print->alrtpr_jobid = 628; ApiStatus = NetAlertRaiseEx( ALERT_PRINT_EVENT, VariableInfo, VariableInfoSize, TEXT("SPOOLER") ); // service name (VOID) printf( "AlTest 5(PRINT_ALERT): done NetAlertRaiseEx(print), status=" FORMAT_API_STATUS ".\n", ApiStatus ); //------------------------------------------ // PRINT ALERT: NO PAPER - JOB PRINTING //------------------------------------------ Print->alrtpr_status = PRJOB_DESTNOPAPER | PRJOB_QS_PRINTING; Print->alrtpr_jobid = 629; ApiStatus = NetAlertRaiseEx( ALERT_PRINT_EVENT, VariableInfo, VariableInfoSize, TEXT("SPOOLER") ); // service name (VOID) printf( "AlTest 5(PRINT_ALERT): done NetAlertRaiseEx(print), status=" FORMAT_API_STATUS ".\n", ApiStatus ); }
int main(int argc, char ** argv) { int r; int handle; struct termios attr; char * name = argv[0]; char * device = 0; struct stat statbuf; int pid = 0; setProgName(argv[0]); while (argc > 1) { if (strcasecmp(argv[1], "-w") == 0) { writeonly = 1; } else if (strcasecmp(argv[1], "-p") == 0) { passthru = 1; } else if (strcasecmp(argv[1], "-r") == 0) { readonly = 1; } else if (strcasecmp(argv[1], "-v") == 0) { verbose = 1; } else if (strcasecmp(argv[1], "-t") == 0 && argc > 2) { argc--; argv++; timeout = strtol(argv[1], 0, 10); logDebug("timeout set to %ld seconds\n", timeout); } else if (strcasecmp(argv[1], "-d") == 0) { debug = 1; setLogLevel(LOGLEVEL_DEBUG); } else if (!device) { device = argv[1]; } else { device = 0; break; } argc--; argv++; } if (!device) { fprintf(stderr, "Usage: %s [-w] -[-p] [-r] [-v] [-d] [-t <n>] device\n" "\n" "Options:\n" " -w writeonly mode, no data is read from device\n" " -r readonly mode, no data is sent to device\n" " -p passthru mode, data on stdin is sent to stdout but not to device\n" " -v verbose\n" " -d debug\n" " -t <n> timeout, if no message is received after <n> seconds the program quits\n" " <device> can be a serial device, a normal file containing a raw log,\n" " or the address of a TCP server in the format tcp://<host>[:<port>]\n" "\n" " Examples: %s /dev/ttyUSB0\n" " %s tcp://192.168.1.1:10001\n" "\n" COPYRIGHT, name, name, name); exit(1); } retry: if (debug) fprintf(stderr, "Opening %s\n", device); if (strncmp(device, "tcp:", STRSIZE("tcp:")) == 0) { handle = open_socket_stream(device); if (debug) fprintf(stderr, "socket = %d\n", handle); isFile = true; if (handle < 0) { fprintf(stderr, "Cannot open NGT-1-A TCP stream %s\n", device); exit(1); } } else { handle = open(device, O_RDWR | O_NOCTTY | O_NONBLOCK); if (debug) fprintf(stderr, "fd = %d\n", handle); if (handle < 0) { fprintf(stderr, "Cannot open NGT-1-A device %s\n", device); exit(1); } if (fstat(handle, &statbuf) < 0) { fprintf(stderr, "Cannot determine device %s\n", device); exit(1); } isFile = S_ISREG(statbuf.st_mode); } if (isFile) { if (debug) fprintf(stderr, "Device is a normal file, do not set the attributes.\n"); } else { if (debug) fprintf(stderr, "Device is a serial port, set the attributes.\n"); memset(&attr, 0, sizeof(attr)); cfsetispeed(&attr, B115200); cfsetospeed(&attr, B115200); attr.c_cflag |= CS8 | CLOCAL | CREAD; attr.c_iflag |= IGNPAR; attr.c_cc[VMIN] = 1; attr.c_cc[VTIME] = 0; tcflush(handle, TCIFLUSH); tcsetattr(handle, TCSANOW, &attr); if (debug) fprintf(stderr, "Device is a serial port, send the startup sequence.\n"); writeMessage(handle, NGT_MSG_SEND, NGT_STARTUP_SEQ, sizeof(NGT_STARTUP_SEQ)); sleep(2); } for (;;) { unsigned char msg[BUFFER_SIZE]; size_t msgLen; enum ReadyDescriptor r; r = isready(writeonly ? -1 : handle, readonly ? -1 : 0); if ((r & FD1_Ready) > 0) { if (!readNGT1(handle)) { break; } } if ((r & FD2_Ready) > 0) { if (!readIn(msg, sizeof(msg))) { break; } if (!passthru) { parseAndWriteIn(handle, msg); } fprintf(stdout, "%s", msg); fflush(stdout); } else if (writeonly) { break; } } close(handle); return 0; }