int BufReadChannelCmd::Init(char *inData, int inSize) { sc_msg_iter msg(inSize, inData); mBufIndex = msg.geti(); const char *filename = msg.gets(); if (!filename) return kSCErr_WrongArgType; if(mWorld->mRestrictedPath){ mFilename = allocAndRestrictPath(mWorld, filename, mWorld->mRestrictedPath); }else{ mFilename = (char*)World_Alloc(mWorld, strlen(filename)+1); strcpy(mFilename, filename); } mFileOffset = msg.geti(); mNumFrames = msg.geti(-1); mBufOffset = msg.geti(); mLeaveFileOpen = msg.geti(); InitChannels(msg); GET_COMPLETION_MSG(msg); return kSCErr_None; }
int main( int argc, char **argv ) { unsigned int num_channels, compress; struct stat stat_buf; profile_param_info_t *profile_list; char *rfile, *ffile, *filename, *Mdirs, *tstring; char *profile_datadir, *profile_statdir, *nameserver; int c, syntax_only, subdir_index, stdin_profile_params, do_xstat; time_t tslot; tstring = NULL; profile_datadir = NULL; profile_statdir = NULL; Mdirs = NULL; tslot = 0; syntax_only = 0; do_xstat = 0; compress = 0; subdir_index = 0; profile_list = NULL; nameserver = NULL; stdin_profile_params = 0; is_anonymized = 0; strncpy(Ident, "none", IDENTLEN); Ident[IDENTLEN-1] = '\0'; // default file names ffile = "filter.txt"; rfile = NULL; while ((c = getopt(argc, argv, "D:HIL:p:P:hf:r:n:M:S:t:VzZ")) != EOF) { switch (c) { case 'h': usage(argv[0]); exit(0); break; case 'D': nameserver = optarg; if ( !set_nameserver(nameserver) ) { exit(255); } break; case 'I': stdin_profile_params = 1; break; case 'H': do_xstat = 1; break; case 'L': if ( !InitLog("nfprofile", optarg) ) exit(255); break; case 'Z': syntax_only = 1; break; case 'p': profile_datadir = optarg; break; case 'P': profile_statdir = optarg; break; case 'S': subdir_index = atoi(optarg); break; case 'V': printf("%s: Version: %s\n",argv[0], nfdump_version); exit(0); break; case 'f': ffile = optarg; break; case 't': tslot = atoi(optarg); break; case 'M': Mdirs = optarg; break; case 'r': rfile = optarg; break; case 'z': compress = 1; break; default: usage(argv[0]); exit(0); } } if ( subdir_index && !InitHierPath(subdir_index) ) { exit(255); } if ( !profile_datadir ) { LogError("Profile data directory required!\n"); exit(255); } if ( !profile_statdir ) { profile_statdir = profile_datadir; } if ( stat(profile_datadir, &stat_buf) || !S_ISDIR(stat_buf.st_mode) ) { LogError("'%s' not a directory\n", profile_datadir); exit(255); } if ( stdin_profile_params ) { profile_list = ParseParams(profile_datadir); if ( !profile_list ) { exit(254); } } if ( syntax_only ) { filename = NULL; rfile = NULL; } else { char *p; if ( rfile == NULL ) { LogError("-r filename required!\n"); exit(255); } p = strrchr(rfile, '/'); filename = p == NULL ? rfile : ++p; if ( strlen(filename) == 0 ) { LogError("Filename error: zero length filename\n"); exit(254); } } if ( chdir(profile_datadir)) { LogError("Error can't chdir to '%s': %s", profile_datadir, strerror(errno)); exit(255); } num_channels = InitChannels(profile_datadir, profile_statdir, profile_list, ffile, filename, subdir_index, syntax_only, compress, do_xstat); // nothing to do if ( num_channels == 0 ) { LogInfo("No channels to process.\n"); return 0; } if ( syntax_only ) { printf("Syntax check done.\n"); return 0; } if ( !rfile ) { LogError("Input file (-r) required!\n"); exit(255); } extension_map_list = InitExtensionMaps(NEEDS_EXTENSION_LIST); if ( !InitExporterList() ) { exit(255); } SetupInputFileSequence(Mdirs,rfile, NULL); process_data(GetChannelInfoList(), num_channels, tslot, do_xstat); CloseChannels(tslot, compress); FreeExtensionMaps(extension_map_list); return 0; }