Implementation(const URI& file) :
    filename(build_filename(file, PE::Comm::instance().rank())),
    xml_filename(file),
    index(0),
    xml_doc("1.0", "ISO-8859-1"),
    m_total_count(0)
  {
    const Uint v = version();
    out_file.open(filename, std::ios_base::out | std::ios_base::binary);
    out_file.write(reinterpret_cast<const char*>(&v), sizeof(Uint));

    PE::Comm& comm = PE::Comm::instance();
    // Rank 0 writes out an XML file that lists all filenames for all CPUs
    if(comm.rank() == 0)
    {
      XmlNode cfbinary = xml_doc.add_node("cfbinary");
      cfbinary.set_attribute("version", to_str(version()));
      node_xml_data.reserve(comm.size());
      XmlNode node_list = cfbinary.add_node("nodes");
      for(Uint i = 0; i != comm.size(); ++i)
      {
        XmlNode node = node_list.add_node("node");
        node.set_attribute("filename", build_filename(file, i));
        node.set_attribute("rank", to_str(i));
        node_xml_data.push_back(node);
      }
    }
  }
Beispiel #2
0
/* This test imports an RTF file, exports it, and imports it again. The export
operation cannot fail, but if either import operation fails, the test fails. It
then compares the plaintext of the two GtkTextBuffers, and if they differ, the
test fails. Otherwise, the test succeeds.
Comparing the plaintext is for lack of a better way to compare the text buffers'
formatting. */
static void
rtf_write_pass_case(gconstpointer name)
{
    GError *error = NULL;
    GtkTextBuffer *buffer1 = gtk_text_buffer_new(NULL);
    GtkTextBuffer *buffer2 = gtk_text_buffer_new(NULL);
    gchar *filename = build_filename(name);
    
	if(!rtf_text_buffer_import(buffer1, filename, &error))
	    g_test_message("Import error message: %s", error->message);
	g_free(filename);
	g_assert(error == NULL);
	gchar *string = rtf_text_buffer_export_to_string(buffer1);
	if(!rtf_text_buffer_import_from_string(buffer2, string, &error))
	    g_test_message("Export error message: %s", error->message);
	g_assert(error == NULL);
	    
	GtkTextIter start, end;
	gtk_text_buffer_get_bounds(buffer1, &start, &end);
	gchar *text1 = gtk_text_buffer_get_slice(buffer1, &start, &end, TRUE);
	gtk_text_buffer_get_bounds(buffer2, &start, &end);
	gchar *text2 = gtk_text_buffer_get_slice(buffer2, &start, &end, TRUE);
	g_assert_cmpstr(text1, ==, text2);
	
	g_free(text1);
	g_free(text2);
	g_object_unref(buffer1);
	g_object_unref(buffer2);
	g_free(string);
}
Beispiel #3
0
int rip (cdrom_drive *drive, text_tag_s **text_tags, char **filenames)
{
  int i, len;
  rip_opts_s *rip_opts = parse_config (NULL);
  
  for (i = 0; text_tags[i] != NULL; i++)
    /* just counting */;
  len = i; 
  for (i = 0; text_tags[i] != NULL; i++) {
    char *filename;
    if (filenames == NULL) {
      filename = build_filename (text_tags[i]);
    }
    else {
      filename = filenames[i];
    }
    encode_ogg (drive, rip_opts, text_tags[i], i + 1, len, filename, filenames);
    free_text_tag (text_tags[i]);
  }
  free (text_tags);

  update_statistics (0, 0, 0, 0, len, 1, NULL);

  free (rip_opts);
  cdda_close (drive);
  return 0;
}
Beispiel #4
0
// ../src/array/array__save.cpp ============================================================= //
//
// Catalyst Lib is free software:  you can redistribute it and/or modifyit under the terms of
// the GNU General Public License as published bythe Free Software Foundation, either version
// 3 of the License, or(at your option) any later version.
//
// Catalyst Lib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along with Catalyst Lib.
// If not, see <http://www.gnu.org/licenses/>.
//
// ========================================================================================== //
//
//
//
inline void save()
{
    input.file_system::init(config -> scratch_dir(),
                                   build_filename());
    switch(input.file_system::exists())
    {
        case true: book_data(); break;
    }
};
/* Check if there's a req.txt file and get the starting filenr from it.
 * Test for the maximum number of ANS files (I believe this is always
 * 4000 but in case there are differences depending on firmware, this
 * code is easy enough */
static bool uemis_init(const char *path)
{
	char *ans_path;
	int i;

	if (!path)
		return false;
	/* let's check if this is indeed a Uemis DC */
	reqtxt_path = build_filename(path, "req.txt");
	reqtxt_file = subsurface_open(reqtxt_path, O_RDONLY, 0666);
	if (!reqtxt_file) {
#if UEMIS_DEBUG & 1
		fprintf(debugfile, ":EE req.txt can't be opened\n");
#endif
		return false;
	}
	if (bytes_available(reqtxt_file) > 5) {
		char tmp[6];
		read(reqtxt_file, tmp, 5);
		tmp[5] = '\0';
#if UEMIS_DEBUG & 2
		fprintf(debugfile, "::r req.txt \"%s\"\n", tmp);
#endif
		if (sscanf(tmp + 1, "%d", &filenr) != 1)
			return false;
	} else {
		filenr = 0;
#if UEMIS_DEBUG & 2
		fprintf(debugfile, "::r req.txt skipped as there were fewer than 5 bytes\n");
#endif
	}
	close(reqtxt_file);

	/* It would be nice if we could simply go back to the first set of
	 * ANS files. But with a FAT filesystem that isn't possible */
	ans_path = build_filename(path, "ANS");
	number_of_files = number_of_file(ans_path);
	free(ans_path);
	/* initialize the array in which we collect the answers */
	for (i = 0; i < NUM_PARAM_BUFS; i++)
		param_buff[i] = "";
	return true;
}
Beispiel #6
0
int pyrip (char *device, PyObject *cfgparser, PyObject *tags, PyObject *filenames)
{
  pthread_t thread = (pthread_t *)malloc (sizeof (pthread_t));
  thread_arg_s *thread_arg;
  PyThreadState *thread_state;
  char **filenames_c;
  text_tag_s **text_tags;
  int size, i;
  PyObject *d, *n;
  rip_opts_s *rip_opts;
  
  thread_arg = (thread_arg_s *)malloc (sizeof (thread_arg));
  rip_opts = parse_config (cfgparser);

  size = PyList_Size (tags);
  
  text_tags = (text_tag_s **)malloc ((sizeof (text_tag_s *) * (size + 1)));
  filenames_c = (char **)malloc ((sizeof (char *) * (size + 1)));
  
  for (i = 0; i < size; i++) {
    printf ("before get item\n");
    d = PyList_GetItem (tags, i);
    
    printf ("Before setTag:\n");
    text_tags[i] = setTag (d);
    //print_text_tag (text_tags[i]);
   
    if (PyInt_Check (filenames)) {
      filenames_c[i] = build_filename (text_tags[i]);
    }
    else {
      n = PyList_GetItem (filenames, i);
      filenames_c[i] = strdup (PyString_AsString (n));
    }
	
    //Py_DECREF (d);
  }
  text_tags[i] = NULL;

  thread_arg->device = strdup (device);
  printf ("device in pyrip is %s\n", device);
  thread_arg->filenames_c = filenames_c;
  thread_arg->text_tags = text_tags;
  thread_arg->rip_opts = rip_opts;
  thread_arg->size = size;

  printf ("creating thread\n");
  
  pthread_create (&thread, NULL, pyrip_thread, thread_arg);
  
  return 0;
}
Beispiel #7
0
/* This test tries to import an RTF file, and succeeds if the import succeeded. */
static void
rtf_parse_pass_case(gconstpointer name)
{
	GError *error = NULL;
	GtkTextBuffer *buffer = gtk_text_buffer_new(NULL);
	gchar *filename = build_filename(name);
	
	if(!rtf_text_buffer_import(buffer, filename, &error))
		g_test_message("Error message: %s", error->message);
    g_free(filename);
	g_object_unref(buffer);
	g_assert(error == NULL);
}
/******************
fopenInputFileNum:
   Attempt to open input image file with the name of the form:
    filename = headIn0..0###TailIn
   Where the image number 0...0### is possibly padded with leading
   zeroes to have a total length of at most MAXPAD.
   
   Routine openInputFileNum returns FILE* infile if successful, NULL otherwise
************/
FILE* fopenInputFileNum(char* fnIn, char* headIn, 
                       int* ppad, int kImage, char* tailIn)
{
    char fileNum[MAXLEN];
    int numLen;
    FILE *infile;

    sprintf(fileNum, "%d", kImage);
    numLen = strlen( fileNum );

    *ppad = numLen;
    while((*ppad)<=MAXPAD) {
      build_filename(fnIn, headIn, *ppad, kImage, tailIn);
      /***
      fprintf(stderr,"DEBUG: Attempting to open %s\n", fnIn);
      ***/
      if ( (infile = fopenInputFile(fnIn)) == NULL ) {
       (*ppad)++;
      } else {
       break;
      }
    }
  
    if (*ppad <= MAXPAD) {
      /*
     fprintf(stderr," Opened input file %s\n",fnIn);
      */
     return(infile); /* Success */
    } else { /* Return unpadded name and error code of NULL */
     *ppad = 0;
     build_filename(fnIn, headIn, *ppad, kImage, tailIn);
/***
     fprintf(stderr," Unsuccesful opening input file %s\n", fnIn);
****/
     return(NULL);
    }
}
Beispiel #9
0
static void
rtf_write_case(gcontpointer name)
{
	GError *error = NULL;
	GtkTextBuffer *buffer = gtk_text_buffer_new(NULL);
	gchar *filename = build_filename(name);
	
	g_assert(rtf_text_buffer_import(buffer, filename, &error));
	g_free(filename);
	g_assert(error == NULL);
	gchar *string = rtf_text_buffer_export_to_string(buffer);
	g_object_unref(buffer);
	g_print("%s\n", string);
	g_free(string);
}
Beispiel #10
0
void Panel::load_applets(void) {
#ifndef EDE_PANEL_LOCAL_APPLETS
	/* FIXME: hardcoded order */
	static const char *applets[] = {
		"start_menu.so",
		"quick_launch.so",
		"pager.so",
		"hider.so",
		"clock.so",
		"taskbar.so",
		"keyboard_layout.so",
		"cpu_monitor.so",
#ifdef __linux__
		"mem_monitor.so",
#endif
		"system_tray.so",
		0
	};

	String dir = Resource::find_data("panel-applets");
	if(dir.empty())
		return;

	String tmp;
	for(int i = 0; applets[i]; i++) {
		tmp = build_filename(dir.c_str(), applets[i]);
		mgr.load(tmp.c_str());
	}

	mgr.fill_group(this);
#else
	mgr.load("./applets/start-menu/start_menu.so");
	mgr.load("./applets/quick-launch/quick_launch.so");
	mgr.load("./applets/pager/pager.so");
	mgr.load("./applets/hider/hider.so");
	mgr.load("./applets/clock/clock.so");
	mgr.load("./applets/taskbar/taskbar.so");
	mgr.load("./applets/keyboard-layout/keyboard_layout.so");
	mgr.load("./applets/cpu-monitor/cpu_monitor.so");
	mgr.load("./applets/mem-monitor/mem_monitor.so");
	mgr.load("./applets/system-tray/system_tray.so");
	mgr.fill_group(this);
#endif
}
 std::vector<int64_t> DiskIOThread::get_all_sizes(std::string _basename){
   DIR *dir;
    struct dirent *fent;
    dir = opendir(datapath.c_str());
    if(dir == NULL) return std::vector<int64_t>();
    int num_files = 0;
    while((fent = readdir(dir)) != NULL){
      int cmp = strncmp(fent->d_name, _basename.c_str(), _basename.size());
      if(cmp == 0) ++num_files;

    }
    closedir(dir);
    std::vector<int64_t> fsize(num_files);
    int i;
    for(i = 0; i < num_files; ++i){
      struct stat fstat;
      int fstat_suc = stat(build_filename(datapath, _basename, i).c_str(), &fstat);
      if(fstat_suc < 0) return std::vector<int64_t>();
      int64_t fs = fstat.st_size;
      fsize[i] = fs;
    }
    return fsize;
  }
Beispiel #12
0
void Splash::run(void) {
	E_ASSERT(slist != NULL);

	if(!show_splash) {
		while(next_client_nosplash()) 
			;
		return;
	}

	fl_register_images();

	String path, splash_theme_path;

#ifdef USE_LOCAL_CONFIG
	splash_theme_path = "splash-themes/";
#else
	splash_theme_path = Resource::find_data("themes/splash-themes", RES_SYS_ONLY);
	if(splash_theme_path.empty()) {
		E_WARNING(E_STRLOC ": Unable to locate splash themes in $XDG_DATA_DIRS directories\n");
		return;
	}
#endif
	splash_theme_path += E_DIR_SEPARATOR;
	splash_theme_path += *splash_theme;

	if(!file_test(splash_theme_path.c_str(), FILE_TEST_IS_DIR)) {
		E_WARNING(E_STRLOC ": Unable to locate '%s' in '%s' theme directory\n", 
				splash_theme->c_str(), splash_theme_path.c_str());
		return;
	}

	/* setup widgets */
	begin();
		Fl_Box* bimg = new Fl_Box(0, 0, w(), h());
		Fl_Image* splash_img = 0;

		path = build_filename(splash_theme_path.c_str(), "background.png");
		splash_img = Fl_Shared_Image::get(path.c_str());

		if(splash_img) {
			int W = splash_img->w();
			int H = splash_img->h();
			/* update window and Box sizes */
			size(W, H);
			bimg->size(W, H);

			bimg->image(splash_img);
		}

		/*
		 * place message box at the bottom with
		 * nice offset (10 px) from window borders
		 */
		msgbox = new Fl_Box(10, h() - 25 - 10, w() - 20, 25);

		/*
		 * Setup icons positions, based on position of msgbox assuming someone 
		 * will not abuse splash to start hundrets of programs, since icons will 
		 * be placed only in horizontal order, one line, so in case their large
		 * number, some of them will go out of window borders.
		 *
		 * Icon box will be 64x64 so larger icons can fit too.
		 *
		 * This code will use Fl_Group (moving group, later, will move all icons
		 * saving me from code mess), but will not update it's w() for two reasons:
		 * icons does not use it, and will be drawn correctly, and second, setting
		 * width will initiate fltk layout engine which will mess everything up.
		 */
		Fl_Group* icon_group = new Fl_Group(10, msgbox->y() - 10 - 64, 0, 64);
		int X = icon_group->x();
		int Y = icon_group->y();

		/* offset between icons */
		int ioffset = 5;

		/* FIXME: use malloc/something instead this */
		icons = new Fl_Box*[slist->size()];

		icon_group->begin();
			int         i = 0;
			const char* imgpath;
			Fl_Image*   iconimg = 0;

			for(StartupItemListIter it = slist->begin(); it != slist->end(); ++it, ++i) {
				Fl_Box* bb = new Fl_Box(X, Y, 64, 64);

				path = build_filename(splash_theme_path.c_str(), (*it)->icon.c_str());
				imgpath = path.c_str();
				iconimg = Fl_Shared_Image::get(imgpath);

				if(!iconimg) {
					bb->label(_("No image"));
					bb->align(FL_ALIGN_INSIDE | FL_ALIGN_WRAP);
				} else 
					bb->image(iconimg);

				bb->hide();

				X += bb->w() + ioffset;
				icons[i] = bb;
			}
		icon_group->end();

		/* see X as width of all icons */
		int gx = w()/2 - X/2;
		/* gx can be negative */
		gx = (gx > 10) ? gx : 10;
		icon_group->position(gx, Y);
	end();

	clear_border();

	/*
	 * If set_override() is used, message boxes will be
	 * popped behind splash. Using it or not ???
	 */
	set_override();

	// make sure window is centered
	int sw = DisplayWidth(fl_display, fl_screen);
	int sh = DisplayHeight(fl_display, fl_screen);
	position(sw/2 - w()/2, sh/2 - h()/2);

	show();
	Fl::add_timeout(TIMEOUT_START, runner_cb, this);

	// to keep splash at the top
#ifndef EDEWM_HAVE_NET_SPLASH
	global_splash = this;
	XSelectInput(fl_display, RootWindow(fl_display, fl_screen), SubstructureNotifyMask);
	Fl::add_handler(splash_xmessage_handler);
#endif
	
	while(shown())
		Fl::wait();

#ifndef EDEWM_HAVE_NET_SPLASH
	Fl::remove_handler(splash_xmessage_handler);
#endif
}
Beispiel #13
0
const char *Desktop::desktop_path(void) {
	if(dpath.empty())
		dpath = build_filename(dir_home().c_str(), "Desktop");
	return dpath.c_str();
}
Beispiel #14
0
static void ok_cb(Fl_Widget*, void *d) {
	if(is_empty_input(name) || is_empty_input(execute) || !img->image()) {
		/* do nothing */
		win->hide();
		return;
	}
	
	Desktop *self = (Desktop*)d;
	
	DesktopFile df;
	df.create_new(DESK_FILE_TYPE_APPLICATION);
	df.set_name(name->value());

	if(comment->value())
		df.set_comment(comment->value());

	df.set_icon((img_path.length() > 1) ? img_path.c_str() : DEFAULT_ICON);
	df.set_exec(execute->value());
	
	if(!is_empty_input(workdir))
		df.set_path(workdir->value());
	
	df.set_startup_notify(start_notify->value());
	df.set_terminal(run_in_terminal->value());

	/* determine filename and save it */
	String file = name->value();
	const char *fp = file.c_str();

	str_tolower((unsigned char*)fp);
	file += EDE_DESKTOP_DESKTOP_EXT;

	/* go through the file and replace spaces with '_' */
	for(String::size_type i = 0; i < file.length(); i++)
		if(isspace(file[i])) file[i] = '_';

	String path = build_filename(self->desktop_path(), file.c_str());
	
	int  X = 0, Y = 0;
	if(curr_icon) {
		X = curr_icon->x();
		Y = curr_icon->y();
		/* try to remove icon from filesystem only when we can't overwrite old icon path */
		self->remove_icon(curr_icon, old_desktop_path != path);
	}

	if(df.save(path.c_str())) {
		DesktopIcon *ic = self->read_desktop_file(path.c_str(), file.c_str());
		if(ic) {
			if(X > 0 || Y > 0) ic->position(X, Y);
			self->add(ic);
		}

		self->redraw();
		
		/* 
		 * In case when we rename icon, icon position will not be saved (because they are saved by icon basename). So
		 * with different paths we are assured the name was changed and we proceed further.
		 */
		if(old_desktop_path != path) self->save_icons_positions();
	} else {
		alert(_("Unable to create '%s' file. Received error is: %s\n"), path.c_str(), df.strerror());
	}

	win->hide();
}
Beispiel #15
0
/*-------------------------------------------------------------------------*/
void xcopy_files(const char *src_pathname,
                 const char *src_filename,
                 const char *dest_pathname,
                 const char *dest_filename) {
  char filepattern[MAXPATH],
       new_src_pathname[MAXPATH],
       new_dest_pathname[MAXPATH],
       src_path_filename[MAXPATH],
       dest_path_filename[MAXPATH],
       tmp_filename[MAXFILE + MAXEXT],
       tmp_pathname[MAXPATH];
  struct ffblk fileblock;
  int fileattrib,
      done;


  if (switch_emptydir ||
      switch_subdir ||
      switch_tree) {
    /* copy files in subdirectories too */
    strmcpy(filepattern, src_pathname, sizeof(filepattern));
    strmcat(filepattern, "*.*", sizeof(filepattern));
    done = findfirst(filepattern, &fileblock, FA_DIREC);
    while (!done) {
      if ((fileblock.ff_attrib & FA_DIREC) != 0 &&
          strcmp(fileblock.ff_name, ".") != 0 &&
          strcmp(fileblock.ff_name, "..") != 0) {
        /* build source pathname */
        strmcpy(new_src_pathname, src_pathname, sizeof(new_src_pathname));
        strmcat(new_src_pathname, fileblock.ff_name, sizeof(new_src_pathname));
        strmcat(new_src_pathname, DIR_SEPARATOR, sizeof(new_src_pathname));

        /* build destination pathname */
        strmcpy(new_dest_pathname, dest_pathname, sizeof(new_dest_pathname));
        strmcat(new_dest_pathname, fileblock.ff_name, sizeof(new_dest_pathname));
        strmcat(new_dest_pathname, DIR_SEPARATOR, sizeof(new_dest_pathname));

        xcopy_files(new_src_pathname, src_filename,
                    new_dest_pathname, dest_filename);
      }

      done = findnext(&fileblock);
    }
  }

  fileattrib = FA_RDONLY + FA_ARCH;
  if (switch_hidden) {
    /* replace hidden and system files too */
    fileattrib = fileattrib + FA_HIDDEN + FA_SYSTEM;
  }

  /* find first source file */
  strmcpy(filepattern, src_pathname, sizeof(filepattern));
  strmcat(filepattern, src_filename, sizeof(filepattern));
  done = findfirst(filepattern, &fileblock, fileattrib);

  if (!done) {
    file_found = -1;
  }

  /* check if destination directory must be created */
  if ((!done || switch_emptydir) &&
      !dir_exists(dest_pathname)) {
    strmcpy(tmp_pathname, dest_pathname, sizeof(tmp_pathname));
    if (make_dir(tmp_pathname) != 0) {
      printf("%s %s\n", catgets(cat, 1, 20, "Unable to create directory"), tmp_pathname);
      if (switch_continue) {
        return;
      }
      else {
        catclose(cat);
        exit(4);
      }
    }
  }

  /* check, if only directory tree should be created */
  if (switch_tree) {
    return;
  }

  /* copy files */
  while (!done) {
    /* check, if copied files should have archive attribute set */
    if ((switch_archive == 0 && switch_archive_reset == 0) ||
        fileblock.ff_attrib & FA_ARCH) {
      /* build source filename including path */
      strmcpy(src_path_filename, src_pathname, sizeof(src_path_filename));
      strmcat(src_path_filename, fileblock.ff_name, sizeof(src_path_filename));

      /* build destination filename including path */
      strmcpy(dest_path_filename, dest_pathname, sizeof(dest_path_filename));
      build_filename(tmp_filename, fileblock.ff_name, dest_filename);
      strmcat(dest_path_filename, tmp_filename, sizeof(dest_path_filename));

      xcopy_file(src_path_filename, dest_path_filename);
    }

    done = findnext(&fileblock);
  }
}
Beispiel #16
0
/* send a request to the dive computer and collect the answer */
static bool uemis_get_answer(const char *path, char *request, int n_param_in,
			     int n_param_out, const char **error_text)
{
	int i = 0, file_length;
	char sb[BUFLEN];
	char fl[13];
	char tmp[101];
	const char *what = translate("gettextFromC", "data");
	bool searching = true;
	bool assembling_mbuf = false;
	bool ismulti = false;
	bool found_answer = false;
	bool more_files = true;
	bool answer_in_mbuf = false;
	char *ans_path;
	int ans_file;
	int timeout = UEMIS_LONG_TIMEOUT;

	reqtxt_file = subsurface_open(reqtxt_path, O_RDWR | O_CREAT, 0666);
	snprintf(sb, BUFLEN, "n%04d12345678", filenr);
	str_append_with_delim(sb, request);
	for (i = 0; i < n_param_in; i++)
		str_append_with_delim(sb, param_buff[i]);
	if (!strcmp(request, "getDivelogs") || !strcmp(request, "getDeviceData") || !strcmp(request, "getDirectory") ||
	    !strcmp(request, "getDivespot") || !strcmp(request, "getDive")) {
		answer_in_mbuf = true;
		str_append_with_delim(sb, "");
		if (!strcmp(request, "getDivelogs"))
			what = translate("gettextFromC", "divelog entry id");
		else if (!strcmp(request, "getDivespot"))
			what = translate("gettextFromC", "divespot data id");
		else if (!strcmp(request, "getDive"))
			what = translate("gettextFromC", "more data dive id");
	}
	str_append_with_delim(sb, "");
	file_length = strlen(sb);
	snprintf(fl, 10, "%08d", file_length - 13);
	memcpy(sb + 5, fl, strlen(fl));
#if UEMIS_DEBUG & 1
	fprintf(debugfile, "::w req.txt \"%s\"\n", sb);
#endif
	if (write(reqtxt_file, sb, strlen(sb)) != strlen(sb)) {
		*error_text = translate("gettextFromC", ERR_FS_SHORT_WRITE);
		return false;
	}
	if (!next_file(number_of_files)) {
		*error_text = translate("gettextFromC", ERR_FS_FULL);
		more_files = false;
	}
	trigger_response(reqtxt_file, "n", filenr, file_length);
	usleep(timeout);
	mbuf = NULL;
	mbuf_size = 0;
	while (searching || assembling_mbuf) {
		if (import_thread_cancelled)
			return false;
		progress_bar_fraction = filenr / 4000.0;
		snprintf(fl, 13, "ANS%d.TXT", filenr - 1);
		ans_path = build_filename(build_filename(path, "ANS"), fl);
		ans_file = subsurface_open(ans_path, O_RDONLY, 0666);
		read(ans_file, tmp, 100);
		close(ans_file);
#if UEMIS_DEBUG & 8
		tmp[100] = '\0';
		fprintf(debugfile, "::t %s \"%s\"\n", ans_path, tmp);
#elif UEMIS_DEBUG & 4
		char pbuf[4];
		pbuf[0] = tmp[0];
		pbuf[1] = tmp[1];
		pbuf[2] = tmp[2];
		pbuf[3] = 0;
		fprintf(debugfile, "::t %s \"%s...\"\n", ans_path, pbuf);
#endif
		free(ans_path);
		if (tmp[0] == '1') {
			searching = false;
			if (tmp[1] == 'm') {
				assembling_mbuf = true;
				ismulti = true;
			}
			if (tmp[2] == 'e')
				assembling_mbuf = false;
			if (assembling_mbuf) {
				if (!next_file(number_of_files)) {
					*error_text = translate("gettextFromC", ERR_FS_FULL);
					more_files = false;
					assembling_mbuf = false;
				}
				reqtxt_file = subsurface_open(reqtxt_path, O_RDWR | O_CREAT, 0666);
				trigger_response(reqtxt_file, "n", filenr, file_length);
			}
		} else {
			if (!next_file(number_of_files - 1)) {
				*error_text = translate("gettextFromC", ERR_FS_FULL);
				more_files = false;
				assembling_mbuf = false;
				searching = false;
			}
			reqtxt_file = subsurface_open(reqtxt_path, O_RDWR | O_CREAT, 0666);
			trigger_response(reqtxt_file, "r", filenr, file_length);
			uemis_increased_timeout(&timeout);
		}
		if (ismulti && more_files && tmp[0] == '1') {
			int size;
			snprintf(fl, 13, "ANS%d.TXT", assembling_mbuf ? filenr - 2 : filenr - 1);
			ans_path = build_filename(build_filename(path, "ANS"), fl);
			ans_file = subsurface_open(ans_path, O_RDONLY, 0666);
			size = bytes_available(ans_file);
			if (size > 3) {
				char *buf;
				int r;
				if (lseek(ans_file, 3, SEEK_CUR) == -1)
					goto fs_error;
				buf = malloc(size - 2);
				if ((r = read(ans_file, buf, size - 3)) != size - 3) {
					free(buf);
					goto fs_error;
				}
				buf[r] = '\0';
				buffer_add(&mbuf, &mbuf_size, buf);
				show_progress(buf, what);
				free(buf);
				param_buff[3]++;
			}
			close(ans_file);
			timeout = UEMIS_TIMEOUT;
			usleep(UEMIS_TIMEOUT);
		}
	}
	if (more_files) {
		int size = 0, j = 0;
		char *buf = NULL;

		if (!ismulti) {
			snprintf(fl, 13, "ANS%d.TXT", filenr - 1);
			ans_path = build_filename(build_filename(path, "ANS"), fl);
			ans_file = subsurface_open(ans_path, O_RDONLY, 0666);
			size = bytes_available(ans_file);
			if (size > 3) {
				int r;
				if (lseek(ans_file, 3, SEEK_CUR) == -1)
					goto fs_error;
				buf = malloc(size - 2);
				if ((r = read(ans_file, buf, size - 3)) != size - 3) {
					free(buf);
					goto fs_error;
				}
				buf[r] = '\0';
				buffer_add(&mbuf, &mbuf_size, buf);
				show_progress(buf, what);
#if UEMIS_DEBUG & 8
				fprintf(debugfile, "::r %s \"%s\"\n", ans_path, buf);
#endif
			}
			size -= 3;
			close(ans_file);
			free(ans_path);
		} else {
			ismulti = false;
		}
#if UEMIS_DEBUG & 8
		fprintf(debugfile, ":r: %s\n", buf);
#endif
		if (!answer_in_mbuf)
			for (i = 0; i < n_param_out && j < size; i++)
				param_buff[i] = next_segment(buf, &j, size);
		found_answer = true;
		free(buf);
	}
#if UEMIS_DEBUG & 1
	for (i = 0; i < n_param_out; i++)
		fprintf(debugfile, "::: %d: %s\n", i, param_buff[i]);
#endif
	return found_answer;
fs_error:
	close (ans_file);
	return false;
}
  // TODO: read/write external should use buffer->valid_db_size instead of passing in additional
  // parameters
  void *DiskIOThread::run_thread(void *_thr_info){
    DiskIOThread *diskio = (DiskIOThread *) _thr_info;

    int ret = zmq_socket_monitor(diskio->sock, "inproc://monitor.router_sock", ZMQ_EVENT_CONNECTED | ZMQ_EVENT_ACCEPTED | ZMQ_EVENT_DISCONNECTED);
    if(ret < 0){
      diskio->status = -1;
      return NULL;
    }

    zmq::socket_t monitor_sock(*diskio->zmq_ctx, ZMQ_PAIR);
    try{
      monitor_sock.connect("inproc://monitor.router_sock");
    }catch(zmq::error_t &e){
      std::cout << "monitor socket create failed" << std::endl;
      return NULL;
    }

    zmq::pollitem_t pollitems[3];
    pollitems[0].socket = diskio->sock;
    pollitems[0].events = ZMQ_POLLIN;
    pollitems[1].socket = monitor_sock;
    pollitems[1].events = ZMQ_POLLIN;
    pollitems[2].socket = diskio->cancel_sock;
    pollitems[2].events = ZMQ_POLLIN;

    while(true){
      try {
        zmq::poll(pollitems, 3);
      }catch(...){
        std::cout << "error from poll!" << std::endl;
        return NULL;
      }

      if(pollitems[2].revents){
        int32_t cid;
        boost::shared_array<uint8_t> data;
        int32_t len = recv_msg(diskio->cancel_sock, cid, data);
        if(len < 0){
          diskio->status = -1;
          return NULL;
        }

        EMsgType type = *((EMsgType *) data.get());
        int32_t extern_cid, sock_idx;

        switch(type){
        case DiskIOCancel:
          extern_cid = zmq_rid_to_cid(cid);
          sock_idx = cid_to_sock_idx(extern_cid);
          diskio->client_valid[sock_idx] = false;
          break;
        case DiskIOEnable:
          extern_cid = zmq_rid_to_cid(cid);
          sock_idx = cid_to_sock_idx(extern_cid);
          diskio->client_valid[sock_idx] = true;
          break;
        default:
          assert(0);
          diskio->status = -1;
          return NULL;
        }
        continue;
      }

      if(pollitems[0].revents){
        int32_t cid;
        boost::shared_array<uint8_t> data;
        int32_t len = recv_msg(diskio->sock, cid, data);
        if(len < 0){
          assert(0);
          diskio->status = -1;
          return NULL;
        }
        //std::cout << "received from cid = " << std::hex << cid << std::dec << std::endl;
        EMsgType type = *((EMsgType *) data.get());
        Buffer *buf;
        std::string base; // for DiskIOExternal, base is actually fullpath
        int32_t extern_cid;
        int32_t sock_idx;
        if(type == DiskIORead || type == DiskIOWrite || type == DiskIOReadExternal
            || type == DiskIOWriteExternal || type == DiskIOWriteRead){
          len = recv_msg(diskio->sock, data);
          if(len < 0){
            assert(0);
            diskio->status = -1;
            return NULL;
          }
          buf = *((Buffer **) data.get());
          len = recv_msg(diskio->sock, data);
          if(len < 0){
            assert(0);
            diskio->status = -1;
            return NULL;
          }
          base = std::string((char *) data.get());
        }

        //std::cout << "request type = " << type << std::endl;

        block_id_t bid;
        int32_t extern_size;
        int32_t dbsize;
        int64_t offset;
        int32_t fidx;
        int32_t suc;
        std::string fname;
        int32_t rsize;
        int32_t wsuc;
        int32_t rd_db_id;
        EMsgType re_type;
        switch(type){
        case DiskIORead:
          bid = buf->get_block_id();

          dbsize = buf->get_db_size();
          fidx = get_file_idx(bid, dbsize, offset);
          fname = build_filename(diskio->datapath, base, fidx);

          extern_cid = zmq_rid_to_cid(cid);
          sock_idx = cid_to_sock_idx(extern_cid);
          if(!diskio->client_valid[sock_idx]){
            rsize = 0;
            re_type = DiskIOReadNotDone;
          }else{
            // read data from specified file, with
            rsize = dir_read(buf->get_db_ptr(), dbsize, fname.c_str(), offset);
            re_type = DiskIOReadDone;
          }

          // finished reading send back message
          suc = send_msg(diskio->sock, cid, (uint8_t *) &re_type, sizeof(Buffer *), ZMQ_SNDMORE);
          if(suc < 0){
            assert(0);
            diskio->status = -1;
            return NULL;
          }
          send_msg(diskio->sock, (uint8_t *) &buf, sizeof(Buffer *), ZMQ_SNDMORE);
          if(suc < 0){
            assert(0);
            diskio->status = -1;
            return NULL;
          }
          suc = send_msg(diskio->sock, (uint8_t *) &rsize, sizeof(int32_t), 0);
          if(suc < 0){
            assert(0);
            diskio->status = -1;
            return NULL;
          }
          break;

        case DiskIOWrite:

          bid = buf->get_block_id();

          dbsize = buf->get_db_size();
          fidx = get_file_idx(bid, dbsize, offset);
          fname = build_filename(diskio->datapath, base, fidx);
          // read data from specified file, with
          wsuc = dir_write(buf->get_db_ptr(), dbsize, fname.c_str(), offset);
          re_type = DiskIOWriteDone;

          // finished reading send back message
          suc = send_msg(diskio->sock, cid, (uint8_t *) &re_type, sizeof(Buffer *), ZMQ_SNDMORE);
          if(suc < 0){
            assert(0);
            diskio->status = -1;
            return NULL;
          }
          send_msg(diskio->sock, (uint8_t *) &buf, sizeof(Buffer *), ZMQ_SNDMORE);
          if(suc < 0){
            assert(0);
            diskio->status = -1;
            return NULL;
          }
          suc = send_msg(diskio->sock, (uint8_t *) &wsuc, sizeof(int32_t), 0);
          if(suc < 0){
            assert(0);
            diskio->status = -1;
            return NULL;
          }
          break;
        case DiskIOWriteRead:
          len = recv_msg(diskio->sock, data);
          if(len < 0){
            assert(0);
            diskio->status = -1;
            return NULL;
          }
          rd_db_id = *((int32_t *) data.get());

          bid = buf->get_block_id();
          dbsize = buf->get_db_size();
          fidx = get_file_idx(bid, dbsize, offset);
          fname = build_filename(diskio->datapath, base, fidx);

          // write data to
          wsuc = dir_write(buf->get_db_ptr(), dbsize, fname.c_str(), offset);

          int32_t resp_val;

          extern_cid = zmq_rid_to_cid(cid);
          sock_idx = cid_to_sock_idx(extern_cid);
          if(!diskio->client_valid[sock_idx]){
            resp_val = 0;
            re_type = DiskIOWriteReadWriteDone;
          }else{
            if(wsuc == 0){
              fidx = get_file_idx(rd_db_id, dbsize, offset);
              fname = build_filename(diskio->datapath, base, fidx);
              rsize = dir_read(buf->get_db_ptr(), dbsize, fname.c_str(), offset);
            }
            if(wsuc < 0 || rsize < 0){
              resp_val = -1;
            }else{
              resp_val = rsize;
            }
            re_type = DiskIOWriteReadDone;
          }
          // finished reading send back message
          suc = send_msg(diskio->sock, cid, (uint8_t *) &re_type, sizeof(Buffer *), ZMQ_SNDMORE);
          if(suc < 0){
            assert(0);
            diskio->status = -1;
            return NULL;
          }
          send_msg(diskio->sock, (uint8_t *) &buf, sizeof(Buffer *), ZMQ_SNDMORE);
          if(suc < 0){
            diskio->status = -1;
            return NULL;
          }
          suc = send_msg(diskio->sock, (uint8_t *) &resp_val, sizeof(int32_t), 0);
          if(suc < 0){
            diskio->status = -1;
            return NULL;
          }
          break;
        case DiskIOReadExternal:

          len = recv_msg(diskio->sock, data);
          if(len < 0){
            assert(0);
            diskio->status = -1;
            return NULL;
          }
          offset = *((int64_t *) data.get());

          len = recv_msg(diskio->sock, data);
          if(len < 0){
            assert(0);
            diskio->status = -1;
            return NULL;
          }
          extern_size = *((int32_t *) data.get());
          //std::cout << "size to read = " << extern_size << std::endl;

          extern_cid = zmq_rid_to_cid(cid);
          sock_idx = cid_to_sock_idx(extern_cid);
          if(!diskio->client_valid[sock_idx]){
            rsize = 0;
            re_type = DiskIOReadExternalNotDone;
          }else{
            //std::cout << "received request to read external data" << std::endl;
            dbsize = buf->get_db_size();
            if(extern_size > dbsize){
              assert(0);
              diskio->status = -1;
              return NULL;
            }
            fname = std::string(base);
            // read data from specified file, with
            rsize = dir_read(buf->get_db_ptr(), extern_size, fname.c_str(), offset);
            re_type = DiskIOReadExternalDone;
          }
          buf->set_valid_db_size(rsize);

          // finished reading send back message
          suc = send_msg(diskio->sock, cid, (uint8_t *) &re_type, sizeof(EMsgType),
                         ZMQ_SNDMORE);
          if(suc < 0){
            assert(0);
            diskio->status = -1;
            return NULL;
          }

          send_msg(diskio->sock, (uint8_t *) &buf, sizeof(Buffer *), ZMQ_SNDMORE);
          if(suc < 0){
            assert(0);
            diskio->status = -1;
            return NULL;
          }

          suc = send_msg(diskio->sock, (uint8_t *) &rsize, sizeof(int32_t), 0);
          if(suc < 0){
            assert(0);
            diskio->status = -1;
            return NULL;
          }
          break;

        case DiskIOWriteExternal:
          len = recv_msg(diskio->sock, data);
          if(len < 0){
            assert(0);
            diskio->status = -1;
            return NULL;
          }
          offset = *((int64_t *) data.get());

          len = recv_msg(diskio->sock, data);
          if(len < 0){
            assert(0);
            diskio->status = -1;
            return NULL;
          }

          // if has been canceled, don't send response
          extern_cid = zmq_rid_to_cid(cid);
          sock_idx = cid_to_sock_idx(extern_cid);
          if(diskio->client_sock[sock_idx] == NULL) continue;

          extern_size = *((int32_t *) data.get());

          dbsize = buf->get_db_size();
          //std::cout << "extern_size = " << extern_size << " dbsize = " << dbsize << std::endl;
          assert(extern_size <= dbsize);

          fname = std::string(base);

          // read data from specified file, with
          rsize = reg_write(buf->get_db_ptr(), extern_size, fname.c_str(), offset);
          re_type = DiskIOWriteExternalDone;

          // finished reading send back message
          suc = send_msg(diskio->sock, cid, (uint8_t *) &re_type, sizeof(Buffer *),
              ZMQ_SNDMORE);
          if(suc < 0){
            assert(0);
            diskio->status = -1;
            return NULL;
          }
          send_msg(diskio->sock, (uint8_t *) &buf, sizeof(Buffer *), ZMQ_SNDMORE);
          if(suc < 0){
            assert(0);
            diskio->status = -1;
            return NULL;
          }
          suc = send_msg(diskio->sock, (uint8_t *) &rsize, sizeof(int32_t), 0);
          if(suc < 0){
            assert(0);
            diskio->status = -1;
            return NULL;
          }
          break;
        case DiskIOShutDown:
          std::cout << "diskio thread received shutdown message" << std::endl;
          return NULL;
          break;
        case DiskIOConn:
          break;
        default:
          std::cout << "!!!!!!!!!diskio thread msgtype = " << type << std::endl;
          assert(0);
          diskio->status = -1;
          return NULL;
        }
        continue;
      }

      if(pollitems[1].revents){
        zmq_event_t *event;
        boost::shared_array<uint8_t> data;
        int len;
        len = recv_msg(monitor_sock, data);

        if (len < 0){
          assert(0);
          diskio->status = -11;
          return NULL;
        }
        assert(len == sizeof(zmq_event_t));
        event = (zmq_event_t *) data.get();

        switch (event->event){
        case ZMQ_EVENT_CONNECTED:
          std::cout << "established connection." << std::endl;
          break;
        case ZMQ_EVENT_ACCEPTED:
          std::cout << "connection accepted" << std::endl;
          break;
        case ZMQ_EVENT_DISCONNECTED:
          std::cout << "client disconnected" << std::endl;
          break;
        default:
          std::cout << "unexpected event" << std::endl;
          return NULL;
        }
        continue;
      }
    }
    return NULL;
  }
Beispiel #18
0
/* This test reads an RTF file into a string, and imports the RTF string into a
GtkTextBuffer, failing if either of these operations fail. It then displays the
RTF code and its rendered result side by side, asking the user whether the RTF
code is rendered correctly. The test succeeds if the user answers Yes, and fails
if the user answers No. */
static void
rtf_parse_human_approval_case(gconstpointer name)
{
    GError *error = NULL;
	GtkWidget *label, *pane, *codescroll, *codeview, *rtfscroll, *rtfview,
		*window, *vbox, *buttons, *yes, *no;
    GtkTextBuffer *rtfbuffer = gtk_text_buffer_new(NULL);
    gchar *text, *filename = build_filename(name);
	gboolean was_correct = FALSE;
	GFile *file = g_file_new_for_path(filename);

	/* Get RTF code */
	if(!g_file_get_contents(filename, &text, NULL, &error))
	    g_test_message("Error message: %s", error->message);
	g_assert(error == NULL);

	/* Import RTF code into text buffer. Import it from a file, even though we
	have already loaded the RTF code to display in the left-hand pane, because
	the RTF code may contain references to images. */
	if(!rtf_text_buffer_import_file(rtfbuffer, file, NULL, &error))
	    g_test_message("Error message: %s", error->message);
	g_assert(error == NULL);
	g_object_unref(file);

	/* Build the interface widgets */
	label = gtk_label_new("Is the RTF code rendered correctly?");
	pane = gtk_hpaned_new();
	codescroll = gtk_scrolled_window_new(NULL, NULL);
	gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(codescroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
	codeview = gtk_text_view_new();
	gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(codeview), GTK_WRAP_CHAR);
	gtk_text_buffer_set_text(gtk_text_view_get_buffer(GTK_TEXT_VIEW(codeview)), text, -1);
	rtfscroll = gtk_scrolled_window_new(NULL, NULL);
	gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(rtfscroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
	rtfview = gtk_text_view_new_with_buffer(rtfbuffer);
	gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(rtfview), GTK_WRAP_WORD);
	buttons = gtk_hbutton_box_new();
	gtk_button_box_set_layout(GTK_BUTTON_BOX(buttons), GTK_BUTTONBOX_END);
	gtk_box_set_spacing(GTK_BOX(buttons), 6);
	yes = gtk_button_new_with_mnemonic("_Yes");
	no = gtk_button_new_with_mnemonic("_No");
	vbox = gtk_vbox_new(FALSE, 0);
	/* Pack everything into containers */
	gtk_container_add(GTK_CONTAINER(codescroll), codeview);
	gtk_container_add(GTK_CONTAINER(rtfscroll), rtfview);
	gtk_paned_add1(GTK_PANED(pane), codescroll);
	gtk_paned_add2(GTK_PANED(pane), rtfscroll);
	gtk_container_add(GTK_CONTAINER(buttons), yes);
	gtk_container_add(GTK_CONTAINER(buttons), no);
	gtk_box_pack_start(GTK_BOX(vbox), pane, TRUE, TRUE, 6);
	gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 6);
	gtk_box_pack_start(GTK_BOX(vbox), buttons, FALSE, FALSE, 6);
	/* Build window */
	window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_window_set_title(GTK_WINDOW(window), filename);
	gtk_window_set_modal(GTK_WINDOW(window), TRUE);
	gtk_window_set_default_size(GTK_WINDOW(window), 1000, 400);
	gtk_paned_set_position(GTK_PANED(pane), 500);
	gtk_container_add(GTK_CONTAINER(window), vbox);
	/* Connect signals */
	g_signal_connect(yes, "clicked", G_CALLBACK(yes_clicked), &was_correct);
	g_signal_connect(no, "clicked", G_CALLBACK(yes_not_clicked), NULL);
	g_signal_connect(window, "delete-event", G_CALLBACK(yes_not_clicked), NULL);
	gtk_widget_show_all(window);
	g_free(filename);

	/* Run it */
	gtk_main();
	gtk_widget_destroy(window);

	g_free(text);
	g_assert(was_correct);
}
Beispiel #19
0
int afi_unpack(uint8_t *buf, size_t size, afi_extract_callback_t unpack_cb)
{
    struct afi_t *afi = (void *)buf;

    if(size < sizeof(struct afi_t))
    {
        cprintf(GREY, "File too small\n");
        return 1;
    }
    cprintf(BLUE, "Header\n");
    cprintf(GREEN, "  Signature:");
    for(int i = 0; i < AFI_SIG_SIZE; i++)
        cprintf(YELLOW, " %02x", afi->hdr.sig[i]);
    if(memcmp(afi->hdr.sig, g_afi_signature, AFI_SIG_SIZE) == 0)
        cprintf(RED, " Ok\n");
    else
    {
        cprintf(RED, " Mismatch\n");
        return 1;
    }

    cprintf_field("  Vendor ID: ", "0x%x\n", afi->hdr.vendor_id);
    cprintf_field("  Product ID: ", "0x%x\n", afi->hdr.product_id);
    cprintf_field("  Version: ", "%x.%x\n", afi->hdr.ver_id[0], afi->hdr.ver_id[1]);
    cprintf_field("  Ext Version: ", "%x.%x\n", afi->hdr.ext_ver_id[0],
        afi->hdr.ext_ver_id[1]);
    cprintf_field("  Date: ", "%02x/%02x/%02x%02x\n", afi->hdr.day, afi->hdr.month,
        afi->hdr.year[0], afi->hdr.year[1]);

    cprintf_field("  AFI size: ", "%d ", afi->hdr.afi_size);
    if(afi->hdr.afi_size == size)
        cprintf(RED, " Ok\n");
    else if(afi->hdr.afi_size < size)
        cprintf(RED, " Ok (file greater than archive)\n");
    else
    {
        cprintf(RED, " Error (file too small)\n");
        return 1;
    }

    cprintf_field("  Reserved: ", "%x %x %x\n", afi->hdr.res[0],
        afi->hdr.res[1], afi->hdr.res[2]);

    cprintf(BLUE, "Entries\n");
    for(int i = 0; i < AFI_ENTRIES; i++)
    {
        if(afi->entry[i].name[0] == 0)
            continue;
        struct afi_entry_t *entry = &afi->entry[i];
        char filename[16];
        build_filename(filename, entry);
        cprintf(RED, "  %s\n", filename);
        cprintf_field("    Type: ", "%02x", entry->type);
        if(isprint(entry->type))
            cprintf(RED, " %c", entry->type);
        printf("\n");
        cprintf_field("    Addr: ", "0x%x\n", entry->addr);
        cprintf_field("    Offset: ", "0x%x\n", entry->offset);
        cprintf_field("    Size: ", "0x%x\n", entry->size);
        cprintf_field("    Desc: ", "%.4s\n", entry->desc);
        cprintf_field("    Checksum: ", "0x%x ", entry->checksum);
        uint32_t chk = afi_checksum(buf + entry->offset, entry->size);
        if(chk != entry->checksum)
        {
            cprintf(RED, "Mismatch\n");
            return 1;
        }
        else
            cprintf(RED, "Ok\n");
        int ret = unpack_cb(filename, buf + entry->offset, entry->size);
        if(ret != 0)
            return ret;
    }

    cprintf(BLUE, "Post Header\n");
    cprintf_field("  Checksum: ", "%x ", afi->post.checksum);
    uint32_t chk = afi_checksum(buf, sizeof(struct afi_t) - 4);
    if(chk != afi->post.checksum)
    {
        cprintf(RED, "Mismatch\n");
        return 1;
    }
    else
        cprintf(RED, "Ok\n");

    return 0;
}