void convert(char *srcname) { if (!test_file(srcname)) return; // read FILE *f_src = fopen(srcname, "r"); char ftag[32]; fscanf(f_src, "%s\n", ftag); if (strcmp(ftag, "PC")) { fprintf(stderr, "Warning: %s contains an invalid PCM header\n", srcname); return; } int w, h; float m; fscanf(f_src, "%d %d\n", &w, &h); fscanf(f_src, "%f\n", &m); if (w <= 0 || h <= 0) { fprintf(stderr, "Warning: %s contains invalid (w, h) dimensions\n", srcname); return; } float *data = malloc(2 * w * h * sizeof(float)); if (fread((unsigned char*)data, 1, 2 * w * h * sizeof(float), f_src) != 2 * w * h * sizeof(float)) { fprintf(stderr, "Warning: %s contains invalid data\n", srcname); free(data); return; } // write char *dstname = floname(srcname); FILE *f_dst= fopen(dstname, "w"); fprintf(f_dst, "PIEH"); fwrite(&w, sizeof(int), 1, f_dst); fwrite(&h, sizeof(int), 1, f_dst); fwrite(data, 1, 2 * w * h * sizeof(float), f_dst); // memory + file management free(data); free(dstname); fclose(f_src); fclose(f_dst); }
file_list *create_filelist(fa_list *al, char *fl, int create) { file_list *st = NULL, *tmpf; fa_list *tmpa; char flavor, *tmpfl, *nm, *temp, tmpreq[13], digit[6], *temp2; struct stat stbuf; int packets = 0; FILE *fp; unsigned char buffer[2]; faddr *fa; DIR *dp = NULL; struct dirent *de; struct stat sb; Syslog('o', "Create_filelist(%s,\"%s\",%d)", al?ascfnode(al->addr,0x1f):"<none>", MBSE_SS(fl), create); made_request = 0; for (tmpa = al; tmpa; tmpa = tmpa->next) { Syslog('o', "Check address %s", ascfnode(tmpa->addr, 0x1f)); /* * For the main aka, check the outbox. */ if ((tmpa->addr) && Loaded && strlen(nodes.OutBox) && (tmpa->addr->zone == nodes.Aka[0].zone) && (tmpa->addr->net == nodes.Aka[0].net) && (tmpa->addr->node == nodes.Aka[0].node) && (tmpa->addr->point == nodes.Aka[0].point)) { check_filebox(nodes.OutBox, &st); } /* * Check spool files, these are more or less useless but they * create a filelist of files to send which are never send. * It gives the transfer protocols something "to do". */ if (strchr(fl, 'o')) { nm = splname(tmpa->addr); if ((fp = fopen(nm, "w"))) fclose(fp); if ((nm != NULL) && (stat(nm, &stbuf) == 0)) add_list(&st, nm, NULL, DSF, 0L, NULL, 1); } /* * Check .pol files */ nm = polname(tmpa->addr); if ((nm != NULL) && (stat(nm,&stbuf) == 0)) add_list(&st,nm,NULL,DSF,0L,NULL,1); /* * Check other files, all flavors */ tmpfl = fl; while ((flavor = *tmpfl++)) { Syslog('o', "Check flavor %c", flavor); /* * Check normal mail packets */ nm = pktname(tmpa->addr,flavor); if ((nm != NULL) && (stat(nm,&stbuf) == 0)) { Syslog('o', "found %s", nm); packets++; add_list(&st, nm, tmpkname(), KFS, 0L, NULL, 1); } /* * Check .flo files for file attaches */ nm = floname(tmpa->addr,flavor); check_flo(&st, nm); } if ((session_flags & SESSION_WAZOO) && ((session_flags & SESSION_HYDRA) == 0) && (master || ((session_flags & SESSION_IFNA) == 0))) { /* * we don't distinguish flavoured reqs */ nm = reqname(tmpa->addr); if ((nm != NULL) && (stat(nm, &stbuf) == 0)) { snprintf(tmpreq, 13, "%04X%04X.REQ", tmpa->addr->net, tmpa->addr->node); add_list(&st, nm, tmpreq, DSF, 0L, NULL, 1); made_request = 1; } } } /* * Check T-Mail style fileboxes */ temp = calloc(PATH_MAX, sizeof(char)); if (strlen(CFG.tmailshort) && (dp = opendir(CFG.tmailshort))) { Syslog('o', "Checking T-Mail short box \"%s\"", CFG.tmailshort); while ((de = readdir(dp))) { if (strcmp(de->d_name, ".") && strcmp(de->d_name, "..")) { snprintf(temp, PATH_MAX -1, "%s/%s", CFG.tmailshort, de->d_name); if (stat(temp, &sb) == 0) { Syslog('o' ,"checking \"%s\"", de->d_name); if (S_ISDIR(sb.st_mode)) { int i; char b=0; for (i=0; (i<8) && (!b); ++i) { char c = tolower(de->d_name[i]); if ( (c<'0') || (c>'v') || ((c>'9') && (c<'a')) ) b=1; } if (de->d_name[8]!='.') b=1; for (i=9; (i<11) && (!b); ++i) { char c = tolower(de->d_name[i]); if ( (c<'0') || (c>'v') || ((c>'9') && (c<'a')) ) b=1; } if (b) continue; if (de->d_name[11]==0) flavor='o'; else if ((tolower(de->d_name[11])=='h') && (de->d_name[12]==0)) flavor='h'; else continue; fa = (faddr*)malloc(sizeof(faddr)); fa->name = NULL; fa->domain = NULL; memset(&digit, 0, sizeof(digit)); digit[0] = de->d_name[0]; digit[1] = de->d_name[1]; fa->zone = strtol(digit, NULL, 32); memset(&digit, 0, sizeof(digit)); digit[0] = de->d_name[2]; digit[1] = de->d_name[3]; digit[2] = de->d_name[4]; fa->net = strtol(digit, NULL, 32); memset(&digit, 0, sizeof(digit)); digit[0] = de->d_name[5]; digit[1] = de->d_name[6]; digit[2] = de->d_name[7]; fa->node = strtol(digit, NULL, 32); memset(&digit, 0, sizeof(digit)); digit[0] = de->d_name[9]; digit[1] = de->d_name[10]; fa->point = strtol(digit, NULL, 32); for (tmpa = al; tmpa; tmpa = tmpa->next) { if ((fa->zone==tmpa->addr->zone) && (fa->net==tmpa->addr->net) && (fa->node==tmpa->addr->node) && (fa->point==tmpa->addr->point) && strchr(fl, flavor)) if (SearchFidonet(tmpa->addr->zone)) check_filebox(temp, &st); } tidy_faddr(fa); } } } } closedir(dp); } if (strlen(CFG.tmaillong) && (dp = opendir(CFG.tmaillong))) { temp2 = calloc(PATH_MAX, sizeof(char)); Syslog('o', "Checking T-Mail long box \"%s\"", CFG.tmaillong); while ((de = readdir(dp))) { if (strcmp(de->d_name, ".") && strcmp(de->d_name, "..")) { snprintf(temp, PATH_MAX -1, "%s/%s", CFG.tmaillong, de->d_name); if (stat(temp, &sb) == 0) { Syslog('o' ,"checking \"%s\"", de->d_name); if (S_ISDIR(sb.st_mode)) { char c, d; int n; snprintf(temp2, PATH_MAX -1, "%s", de->d_name); fa = (faddr*)malloc(sizeof(faddr)); fa->name = NULL; fa->domain = NULL; n = sscanf(temp2, "%u.%u.%u.%u.%c%c", &(fa->zone), &(fa->net), &(fa->node), &(fa->point), &c, &d); if ((n==4) || ((n==5) && (tolower(c)=='h'))) { if (n==4) flavor = 'o'; else flavor = 'h'; for (tmpa = al; tmpa; tmpa = tmpa->next) { if ((fa->zone==tmpa->addr->zone) && (fa->net==tmpa->addr->net) && (fa->node==tmpa->addr->node) && (fa->point==tmpa->addr->point) && strchr(fl, flavor)) if (SearchFidonet(tmpa->addr->zone)) check_filebox(temp, &st); } } tidy_faddr(fa); } } } } closedir(dp); free(temp2); } free(temp); /* * For FTS-0001 we need to create at least one packet. */ if (((st == NULL) && (create > 1)) || ((st != NULL) && (packets == 0) && (create > 0))) { Syslog('o', "Create packet for %s", ascfnode(al->addr,0x1f)); if ((fp = openpkt(NULL, al->addr, 'o', TRUE))) { memset(&buffer, 0, sizeof(buffer)); fwrite(buffer, 1, 2, fp); fclose(fp); } add_list(&st, pktname(al->addr,'o'), tmpkname(), KFS, 0L, NULL, 0); } for (tmpf = st; tmpf; tmpf = tmpf->next) Syslog('o',"flist: \"%s\" -> \"%s\" dsp:%d flofp:%p floff:%p", MBSE_SS(tmpf->local), MBSE_SS(tmpf->remote), tmpf->disposition, tmpf->flofp, tmpf->floff); return st; }