/* * kiswinsound.c * 2005-10-09 goldfndr - Initial creation * 2005-10-14 goldfndr - Removes parentheses, uses doublespace as delimiter * 2005-10-19 goldfndr - Renamed; if passed 1 param, plays WAV file * 2006-02-22 goldfndr - If "FILESECS" is in environment, appends to file instead of registry * * For use with ns04thread.vbs * * Deploy: UseThreading = -2 (ns04settings.vbs) * sound=true, speech=true, flite=true, (kismet_ui.conf) * festival=kiswinsound.exe, soundplay=kiswinsound.exe (kismet_ui.conf) * * * TODO: (actually, all negated due to file appending capability) * - Use winreg.h (RegSetValueExA()) rather than calling regtool * = Detect existing NS_ entry, and if present, append with \r\n * - Maybe rewrite ns04thread.vbs to not need \r\n: \0x14 \0xAD? * - Replace soundplay= (perhaps with arg for urgency): NS_IMMED */ /* gcc -o kiswinsound.exe kiswinsound.c */ #include #include #include #include #include #define REGTOOL "bin/regtool" static char buf[2048]; /* used for copying file or cmd line */ /* vbstimer returns seconds past local midnight (0-86400 or so) */ /* it's equivalent to VBScript's "timer" function */ static long vbstimer(void) { time_t tnow = time(0); struct tm *now = localtime(&tnow); //printf("%d:%d:%d\n", (int)now->tm_hour,(int)now->tm_min,(int)now->tm_sec); return (NULL == now) ? 0 : now->tm_hour * 3600 + now->tm_min * 60 + now->tm_sec; } static int playsound(char *wavfile) { FILE *fi, *fo = fopen("/dev/dsp", "ab"); if (NULL != fo) { fi = fopen(wavfile, "rb"); if (NULL != fi) { while (!feof(fi)) { size_t n = fread(buf, sizeof(char), sizeof(buf), fi); (void)fwrite(buf, sizeof(char), n, fo); } (void)fclose(fo); (void)fclose(fi); return 0; } else { (void)fputs("Error opening input file:", stderr); (void)fputs(wavfile, stderr); return 1; } } else { (void)fputs("Error opening /dev/dsp", stderr); return 2; } } int main(int argc, char **argv) { char *c; /* I don't know if Kismet passes multiple parameters, but I hope not */ if (argc > 1) { /* This code is limited to sound files with no embedded spaces */ return playsound(argv[1]); } if (fgets(buf, (int)sizeof(buf), stdin) == NULL) { return 2; } /* I'm sure there's a predefined function that cleans args */ /* If it was using the registry directly, this might not be needed */ buf[strlen(buf)-3] = '\0'; /* remove "( " and " )" */ for (c = buf; *c > '\0'; ++c) { if ((' ' == c[0] || '(' == c[0]) && ' ' == c[1]) { c[0] = '\r'; c[1] = '\n'; } else if (strchr("[]?\"!$*{}|\\;<>~`", *c) != NULL) { *c = ' '; } } char *appendfile = getenv("FILESECS"); if (NULL != appendfile) { FILE *f = fopen(appendfile, "a"); if (NULL == f) { /* Unable to open file */ (void)fputs("Error opening $FILESECS", stderr); } else { fputs(buf+2, f); fputs("\r\n", f); /* Write vbCRLF seperator */ fclose(f); } } else { char reg[60]; snprintf(reg, sizeof(reg), "/HKCU/Volatile\\ Environment/NS_%ld", vbstimer()); spawnl(_P_NOWAIT, REGTOOL, REGTOOL, "set", "-s", reg, buf+2, NULL); } return 0; }