Esempio n. 1
0
void  ugtk_plugin_form_get (struct UgtkPluginForm* psform, UgtkSetting* setting)
{
	GtkTextIter  iter1;
	GtkTextIter  iter2;
	const char*  token;

	setting->plugin_order = gtk_combo_box_get_active ((GtkComboBox*) psform->order);

	setting->aria2.launch = gtk_toggle_button_get_active (psform->launch);
	setting->aria2.shutdown = gtk_toggle_button_get_active (psform->shutdown);

	ug_free (setting->aria2.uri);
	ug_free (setting->aria2.token);
	ug_free (setting->aria2.path);
	ug_free (setting->aria2.args);
	setting->aria2.uri = ug_strdup (gtk_entry_get_text (psform->uri));
	token = gtk_entry_get_text (psform->token);
	if (token[0] == 0)
		setting->aria2.token = NULL;
	else
		setting->aria2.token = ug_strdup (token);
	setting->aria2.path = ug_strdup (gtk_entry_get_text (psform->path));
//	setting->aria2.args = ug_strdup (gtk_entry_get_text (psform->args));
	gtk_text_buffer_get_start_iter (psform->args_buffer, &iter1);
	gtk_text_buffer_get_end_iter (psform->args_buffer, &iter2);
	setting->aria2.args = gtk_text_buffer_get_text (psform->args_buffer, &iter1, &iter2, FALSE);
	remove_line_breaks (setting->aria2.args, -1);

	setting->aria2.limit.upload   = (guint) gtk_spin_button_get_value (psform->upload);
	setting->aria2.limit.download = (guint) gtk_spin_button_get_value (psform->download);
}
Esempio n. 2
0
void  test_utility ()
{
	char*  temp;
	time_t res;
	int    n;

	res = ug_str_rfc822_to_time ("Sat, 07 Sep 2002 00:00:01 GMT");
	if (res != -1)
		puts (ctime (&res));

	res = ug_str_rfc3339_to_time ("2013-09-12T22:50:20+08:00");
	if (res != -1)
		puts (ctime (&res));

	temp = ug_build_filename ("basedir", "path", "file", NULL);
	printf ("ug_build_filename() - %s\n", temp);
	ug_free (temp);

	temp = ug_unescape_uri ("This%20is a test%200.", -1);
	puts (temp);
	ug_free (temp);

	temp = ug_strdup ("\nThis\n one\r");
	puts ("--- ug_str_remove_crlf () --- start ---");
	puts (temp);
	n = ug_str_remove_crlf (temp, temp);
	puts (temp);

	printf ("--- ug_str_remove_crlf () return %d --- end ---", n);
	ug_free (temp);
}
Esempio n. 3
0
void  uget_node_set_name_by_uri (UgetNode* node, UgUri* uuri)
{
	const char* filename;
	int         length;

	ug_free (node->name);

	if (uuri->scheme_len == 6 && strncmp (uuri->uri, "magnet", 6) == 0) {
		length = 0;
		filename = strstr (uuri->uri + uuri->file, "dn=");
		if (filename) {
			filename = filename + 3;
			length = strcspn (filename, "&");
			node->name = ug_unescape_uri (filename, length);
			if (ug_utf8_get_invalid ((uint8_t*) node->name, NULL) != -1) {
				ug_free (node->name);
				node->name = ug_strndup (filename, length);
			}
		}
	}
	else {
		length = ug_uri_file (uuri, &filename);
		if (length == 0)
			node->name = ug_strdup (uuri->uri);
		else
			node->name = ug_uri_get_file (uuri);
	}
}
Esempio n. 4
0
void  ugtk_completion_form_get (struct UgtkCompletionForm* csform, UgtkSetting* setting)
{
	const char*  string;

	ug_free (setting->completion.command);
	string = gtk_entry_get_text (csform->command);
	setting->completion.command = (string[0]) ? ug_strdup (string) : NULL;

	ug_free (setting->completion.on_error);
	string = gtk_entry_get_text (csform->on_error);
	setting->completion.on_error = (string[0]) ? ug_strdup (string) : NULL;
}
Esempio n. 5
0
int  ug_option_parse (UgOption* option, const char* string, int length)
{
	char* beg;
	char* cur;
	char* end;

	if (string == NULL || length == 0)
		return FALSE;
	if (length == -1)
		length = strlen (string);
	string = ug_strndup (string, length);
	// not option
	if (string[0] != '-') {
		*(char**) ug_array_alloc (&option->others, 1) = (char*) string;
		return TRUE;
	}

	// option name
	end = (char*) string + length;
	for (beg = (char*) string;  beg < end;  beg++) {
		if (beg[0] != '-')
			break;
	}
	if (beg == end) {
		ug_free ((void*) string);
		return FALSE;
	}
	if (beg - string == 1)
		option->short_name = TRUE;
	else
		option->short_name = FALSE;
	// option value
	for (cur = beg;  cur < end;  cur++) {
		if (cur[0] == '=') {
			*cur++ = 0;
			break;
		}
	}
	if (cur == end)
		cur = NULL;

	if (option->parse.func (option, beg, cur,
	    option->parse.dest, option->parse.data) == FALSE)
	{
		if (option->discard_unaccepted == FALSE)
			*(char**) ug_array_alloc (&option->unaccepted, 1) = (char*) string;
	}
	ug_free ((void*) string);
	return TRUE;
}
Esempio n. 6
0
void  uget_curl_free (UgetCurl* ugcurl)
{
	if (ugcurl->curl)
		curl_easy_cleanup (ugcurl->curl);
	if (ugcurl->file.output)
		ug_fclose (ugcurl->file.output);
	if (ugcurl->file.post)
		ug_fclose (ugcurl->file.post);
	if (ugcurl->event)
		uget_event_free (ugcurl->event);
	ug_free (ugcurl->header.uri);
	ug_free (ugcurl->header.filename);
	ug_free (ugcurl);
}
Esempio n. 7
0
int  ug_file_copy (const char *src_file_utf8, const char *new_file_utf8)
{
	int	 retval;
	uint16_t*  src_file_wcs;
	uint16_t*  new_file_wcs;

	src_file_wcs = ug_utf8_to_utf16 (src_file_utf8, -1, NULL);
	new_file_wcs = ug_utf8_to_utf16 (new_file_utf8, -1, NULL);
	retval = CopyFileW (src_file_wcs, new_file_wcs, FALSE);
	ug_free (src_file_wcs);
	ug_free (new_file_wcs);
	if (retval == 0)
		return -1;
	return 0;
}
Esempio n. 8
0
int  ug_file_get_lines (const char* filename_utf8, UgList* list)
{
	UgLink* link;
	FILE*   file;
	char*   buf;
	int     len;
	int     count = 0;

	file = ug_fopen (filename_utf8, "r");
	if (file == NULL)
		return 0;
	buf = ug_malloc (8192);
	if (fread (buf, 1, 3, file) == 3) {
		// UTF-8 byte-order mark: 0xEF, 0xBB, 0xBF
		if ((unsigned char)buf[0] != 0xEF || (unsigned char)buf[1] != 0xBB)
			rewind (file);
	}

	while (fgets (buf, 8192, file) != NULL) {
		count++;
		len = strlen (buf);
		if (len > 0 && buf[len-1] == '\n')
			buf[--len] = 0;
		if (list) {
			link = ug_link_new ();
			link->data = ug_strndup (buf, len);
			ug_list_append (list, link);
		}
	}

	ug_free (buf);
	fclose (file);
	return count;
}
Esempio n. 9
0
void ug_file_status_monitor
 (char *Flag)
 
{

/*
 * Turn file status monitor on or off.
 */

  INT_ ierr;

  if (File_Status_Monitor)
  {
    ug_free (stat_struct);

    stat_struct = NULL;
  }

  if (strcmp (Flag, "on") == 0)
  {
    ierr = 0;


    stat_struct = (ug_stat_struct *) ug_malloc (&ierr, sizeof (ug_stat_struct));

    File_Status_Monitor = (ierr == 0) ? 1: 0;
  }
  else
    File_Status_Monitor = 0;

  return;

}
Esempio n. 10
0
void  test_uri (void)
{
	char*  temp;
	char*  hosts[]   = {"ftp.you.com", ".your.org", ".edu", NULL};
	char*  exts[]    = {"png", "bmp", "jpg", NULL};
	char*  schemes[] = {"ftp", "http", "git", NULL};
//	const char*  uri   = "ftp://i.am.ftp.you.com/file.bmp";
	const char*  uri   = "http://my.and.your.org/file%200.png";
//	const char*  uri   = "git://this.edu/file.jpg";
	UgUri  uuri;
	int    index;

	puts ("\n--- test_uri:");

	ug_uri_init (&uuri, uri);
	index = ug_uri_match_hosts (&uuri, hosts);
	printf ("ug_uri_match_hosts () return %d\n", index);
	index = ug_uri_match_schemes (&uuri, schemes);
	printf ("ug_uri_match_schemes () return %d\n", index);
	index = ug_uri_match_file_exts (&uuri, exts);
	printf ("ug_uri_match_file_exts () return %d\n", index);

	temp = ug_uri_get_file (&uuri);
	puts (temp);
	ug_free (temp);
}
Esempio n. 11
0
static void ug_free_tmp_file_struct
 (void)

{

/*
 * Free binary TMP file structure arrays.
 */

  ug_free (UG_TMP_File_Struct_Ptr->TMP_File_Name);
  ug_free (UG_TMP_File_Struct_Ptr->TMP_File_Stream);
  ug_free (UG_TMP_File_Struct_Ptr->TMP_File_Status);

  ug_free (UG_TMP_File_Struct_Ptr);

  UG_TMP_File_Struct_Ptr = NULL;

  return;

}
Esempio n. 12
0
void  uget_node_unref (UgetNode* node)
{
	if (--node->ref_count == 0) {
		if (node->parent)
			uget_node_remove (node->parent, node);
		if (node->real)
			uget_node_remove_fake (node->real, node);

		uget_node_unref_fake (node);
		uget_node_unref_children (node);
//		ug_node_unlink ((UgNode*)node);
		ug_info_final (&node->info);
		ug_free (node->name);

#ifdef HAVE_GLIB
		g_slice_free1 (sizeof (UgetNode), node);
#else
		ug_free (node);
#endif // HAVE_GLIB
	}
}
Esempio n. 13
0
int  ug_create_dir_all (const char* dir, int len)
{
	const char*   dir_end;
	const char*   element_end;	// path element
	char*         element_os;

	if (len == -1)
		len = strlen (dir);
	dir_end = dir + len;
	element_end = dir;

	for (;;) {
		// skip directory separator "\\\\" or "//"
		for (;  element_end < dir_end;  element_end++) {
			if (*element_end != UG_DIR_SEPARATOR)
				break;
		}
		if (element_end == dir_end)
			return 0;
		// get directory name [dir, element_end)
		for (;  element_end < dir_end;  element_end++) {
			if (*element_end == UG_DIR_SEPARATOR)
				break;
		}
		element_os = (char*) ug_malloc (element_end - dir + 1);
		element_os[element_end - dir] = 0;
		strncpy (element_os, dir, element_end - dir);

		if (element_os == NULL)
			break;
		if (ug_create_dir (element_os) == -1) {
			if (ug_file_is_exist (element_os) == FALSE) {
				ug_free (element_os);
				return -1;
			}
		}
		ug_free (element_os);
	}
	return -1;
}
Esempio n. 14
0
int   ug_file_is_exist (const char* filename)
{
	int      attributes;
	wchar_t *wfilename = ug_utf8_to_utf16 (filename, -1, NULL);

	if (wfilename == NULL)
		return FALSE;
	attributes = GetFileAttributesW (wfilename);
	ug_free (wfilename);
	if (attributes == INVALID_FILE_ATTRIBUTES)
		return FALSE;
	return TRUE;
}
Esempio n. 15
0
static void*  ug_file_to_base64  (const char* file, int* length)
{
	int     fd;
	int     fsize, fpos = 0;
	int     result_len;
	void*   buffer;
	void*   result;

//	fd = open (file, O_RDONLY | O_BINARY, S_IREAD);
	fd = ug_open (file, UG_O_READONLY | UG_O_BINARY, UG_S_IREAD);
	if (fd == -1)
		return NULL;
//	lseek (fd, 0, SEEK_END);
	ug_seek (fd, 0, SEEK_END);
	fsize = (int) ug_tell (fd);
	buffer = ug_malloc (fsize);
//	lseek (fd, 0, SEEK_SET);
	ug_seek (fd, 0, SEEK_SET);

	do {
		result_len = ug_read (fd, buffer, fsize - fpos);
//		result_len = read (fd, buffer, fsize - fpos);
		fpos += result_len;
	} while (result_len > 0);
//	close (fd);
	ug_close (fd);

	if (fsize != fpos) {
		ug_free (buffer);
		return NULL;
	}

	result = ug_base64_encode (buffer, fsize, &result_len);
	ug_free (buffer);
	if (length)
		*length = result_len;
	return result;
}
Esempio n. 16
0
int   ug_file_is_dir (const char* dir)
{
	int      attributes;
	wchar_t *wfilename = ug_utf8_to_utf16 (dir, -1, NULL);

	if (wfilename == NULL)
		return FALSE;
	attributes = GetFileAttributesW (wfilename);
	ug_free (wfilename);

	if ((attributes & FILE_ATTRIBUTE_DIRECTORY) != 0)
		return TRUE;
	return FALSE;
}
Esempio n. 17
0
int  ug_modify_file_time (const char *file_utf8, time_t mod_time)
{
	struct _utimbuf utb;
	wchar_t*        file;
	int             retval;

	utb.actime = time (NULL);
	utb.modtime = mod_time;
	file = (wchar_t*) ug_utf8_to_utf16 (file_utf8, -1, NULL);
	retval = _wutime (file, &utb);
	ug_free (file);

	return retval;
}
Esempio n. 18
0
INT_ ug3_ieliel2b
 (INT_ nbface,
  INT_ nelem,
  INT_ nnode,
  INT_1D * ibcibf,
  INT_3D * inibf,
  INT_4D * iniel,
  INT_4D * ieliel)

{

/*
 * Add boundary faces element to element connectivity.
 * 
 * UG3 LIB : Unstructured Grid - General Purpose Routine Library
 * 3D Version : $Id: ug3_ieliel2b.c,v 1.4 2012/08/25 19:01:45 marcum Exp $
 * Copyright 1994-2012, David L. Marcum
 */

  INT_1D *ibfjbf = NULL;
  INT_1D *ibfjn = NULL;
  INT_1D *ielibf = NULL;
  INT_1D *ierribf = NULL;

  INT_ ierr = 0;
  INT_ minl = 0;
  INT_ mmsg = 0;
  INT_ nbfaceu = 0;

  if (ibcibf == NULL) minl = 2;

  ibfjbf = (INT_1D *) ug_malloc (&ierr, (nbface+1) * sizeof (INT_1D));
  ibfjn = (INT_1D *) ug_malloc (&ierr, (nnode+1) * sizeof (INT_1D));
  ielibf = (INT_1D *) ug_malloc (&ierr, (nbface+1) * sizeof (INT_1D));

  if (ierr > 0)
  {
    ug_free (ibfjbf);
    ug_free (ibfjn);
    ug_free (ielibf);
    return (100309);
  }

  ierr = ug3_ielibf (minl, mmsg, nbface, nelem, nnode, &nbfaceu, 
                     ibcibf, ieliel, inibf, iniel, ibfjbf, ibfjn,
                     ielibf, ierribf);

  ug_free (ibfjbf);
  ug_free (ibfjn);
  ug_free (ielibf);

  if (ierr > 0)
    return (ierr);

  return (0);

}
Esempio n. 19
0
void  ugtk_clipboard_form_get (struct UgtkClipboardForm* csform, UgtkSetting* setting)
{
	GtkTextIter  iter1;
	GtkTextIter  iter2;

	gtk_text_buffer_get_start_iter (csform->buffer, &iter1);
	gtk_text_buffer_get_end_iter (csform->buffer, &iter2);

	ug_free (setting->clipboard.pattern);
	setting->clipboard.pattern = gtk_text_buffer_get_text (csform->buffer, &iter1, &iter2, FALSE);
	setting->clipboard.monitor = gtk_toggle_button_get_active (csform->monitor);
	setting->clipboard.quiet = gtk_toggle_button_get_active (csform->quiet);
	setting->clipboard.nth_category = gtk_spin_button_get_value_as_int (csform->nth_spin);
	// remove line break
	remove_line_breaks (setting->clipboard.pattern, -1);
}
Esempio n. 20
0
int  ug_file_copy (const char *src_file_utf8, const char *new_file_utf8)
{
	int		src_fd;
	int		new_fd;
	char*	buf;
	int		buf_len;
	int		retval = 0;

//	new_fd = open (new_file_utf8,
//	               O_BINARY | O_WRONLY | O_CREAT,
//	               S_IREAD | S_IWRITE | S_IRGRP | S_IROTH);
	new_fd = ug_open (new_file_utf8,
	                  UG_O_BINARY | UG_O_WRONLY | UG_O_CREAT,
	                  UG_S_IREAD | UG_S_IWRITE | UG_S_IRGRP | UG_S_IROTH);
	if (new_fd == -1)
		return -1;

//	src_fd = open (src_file_utf8, O_BINARY | O_RDONLY, S_IREAD);
	src_fd = ug_open (src_file_utf8, UG_O_BINARY | UG_O_RDONLY, UG_S_IREAD);
	if (src_fd == -1) {
		ug_close (new_fd);
		return -1;
	}
	// read & write
	buf = ug_malloc (8192);
	for (;;) {
		buf_len = ug_read (src_fd, buf, 8192);
		if (buf_len <=0)
			break;
		if (ug_write (new_fd, buf, buf_len) != buf_len) {
			retval = -1;
			break;
		}
	}
	// clear
	ug_free (buf);
	ug_close (src_fd);
	ug_close (new_fd);
	return retval;
}
Esempio n. 21
0
INT_ ug3_idielm
 (INT_ nelem,
  INT_ nelemc5,
  INT_ nelemc6,
  INT_ nelemc8,
  INT_ nnode,
  INT_1D * idiel,
  INT_4D * iniel,
  INT_5D * inielc5,
  INT_6D * inielc6,
  INT_8D * inielc8)

{

/*
 * Set volume ID flag in mixed element region.
 * 
 * UG3 LIB : Unstructured Grid - General Purpose Routine Library
 * 3D Version : $Id: ug3_idielm.c,v 1.4 2012/08/25 19:01:45 marcum Exp $
 * Copyright 1994-2012, David L. Marcum
 */

  INT_1D *idin = NULL;

  INT_ id, id1, id2, id3, id4, id5, id6, id7, id8, idmax, idmin, ielem, ielemc,
       ierr, iit, inode, inode1, inode2, inode3, inode4, inode5, inode6, inode7,
       inode8, nelemc;

  nelemc = nelemc5 + nelemc6 + nelemc8;

  if (nelem == 0 || nelemc == 0) return (0);

  ierr = 0;

  idin = (INT_1D *) ug_malloc (&ierr, (nnode+1) * sizeof (INT_1D));

  if (ierr > 0)
  {
    ug_free (idin);
    return (100313);
  }

  for (inode = 1; inode <= nnode; ++inode)
  {
    idin[inode] = 0;
  }

  for (ielem = 1; ielem <= nelem; ++ielem)
  {
    id = idiel[ielem];

    inode1 = iniel[ielem][0];
    inode2 = iniel[ielem][1];
    inode3 = iniel[ielem][2];
    inode4 = iniel[ielem][3];

    idin[inode1] = id;
    idin[inode2] = id;
    idin[inode3] = id;
    idin[inode4] = id;
  }

  iit = 1;

  do
  {
    for (ielem = 1; ielem <= nelemc5; ++ielem)
    {
      inode1 = inielc5[ielem][0];
      inode2 = inielc5[ielem][1];
      inode3 = inielc5[ielem][2];
      inode4 = inielc5[ielem][3];
      inode5 = inielc5[ielem][4];

      id1 = idin[inode1];
      id2 = idin[inode2];
      id3 = idin[inode3];
      id4 = idin[inode4];
      id5 = idin[inode5];

      idmax = MAX (id1, id2);
      idmax = MAX (idmax, id3);
      idmax = MAX (idmax, id4);
      idmax = MAX (idmax, id5);

      if (idmax > 0)
      {
        idin[inode1] = idmax;
        idin[inode2] = idmax;
        idin[inode3] = idmax;
        idin[inode4] = idmax;
        idin[inode5] = idmax;
      }
    }

    for (ielem = 1; ielem <= nelemc6; ++ielem)
    {
      inode1 = inielc6[ielem][0];
      inode2 = inielc6[ielem][1];
      inode3 = inielc6[ielem][2];
      inode4 = inielc6[ielem][3];
      inode5 = inielc6[ielem][4];
      inode6 = inielc6[ielem][5];

      id1 = idin[inode1];
      id2 = idin[inode2];
      id3 = idin[inode3];
      id4 = idin[inode4];
      id5 = idin[inode5];
      id6 = idin[inode6];

      idmax = MAX (id1, id2);
      idmax = MAX (idmax, id3);
      idmax = MAX (idmax, id4);
      idmax = MAX (idmax, id5);
      idmax = MAX (idmax, id6);

      if (idmax > 0)
      {
        idin[inode1] = idmax;
        idin[inode2] = idmax;
        idin[inode3] = idmax;
        idin[inode4] = idmax;
        idin[inode5] = idmax;
        idin[inode6] = idmax;
      }
    }

    for (ielem = 1; ielem <= nelemc8; ++ielem)
    {
      inode1 = inielc8[ielem][0];
      inode2 = inielc8[ielem][1];
      inode3 = inielc8[ielem][2];
      inode4 = inielc8[ielem][3];
      inode5 = inielc8[ielem][4];
      inode6 = inielc8[ielem][5];
      inode7 = inielc8[ielem][6];
      inode8 = inielc8[ielem][7];

      id1 = idin[inode1];
      id2 = idin[inode2];
      id3 = idin[inode3];
      id4 = idin[inode4];
      id5 = idin[inode5];
      id6 = idin[inode6];
      id7 = idin[inode7];
      id8 = idin[inode8];

      idmax = MAX (id1, id2);
      idmax = MAX (idmax, id3);
      idmax = MAX (idmax, id4);
      idmax = MAX (idmax, id5);
      idmax = MAX (idmax, id6);
      idmax = MAX (idmax, id7);
      idmax = MAX (idmax, id8);

      if (idmax > 0)
      {
        idin[inode1] = idmax;
        idin[inode2] = idmax;
        idin[inode3] = idmax;
        idin[inode4] = idmax;
        idin[inode5] = idmax;
        idin[inode6] = idmax;
        idin[inode7] = idmax;
        idin[inode8] = idmax;
      }
    }

    idmax = idin[1];
    idmin = idin[1];

    for (inode = 2; inode <= nnode; ++inode)
    {
      idmax = MAX (idmax, idin[inode]);
      idmin = MIN (idmin, idin[inode]);
    }

    ++iit;
  }
  while (iit < nelemc && idmin == 0);

  ielemc = nelem;

  for (ielem = 1; ielem <= nelemc5; ++ielem)
  {
    ++ielemc;

    inode1 = inielc5[ielem][0];

    idiel[ielemc] = idin[inode1];
  }

  for (ielem = 1; ielem <= nelemc6; ++ielem)
  {
    ++ielemc;

    inode1 = inielc6[ielem][0];

    idiel[ielemc] = idin[inode1];
  }

  for (ielem = 1; ielem <= nelemc8; ++ielem)
  {
    ++ielemc;

    inode1 = inielc8[ielem][0];

    idiel[ielemc] = idin[inode1];
  }

  ug_free (idin);

  return (0);

}
Esempio n. 22
0
// return FALSE if plug-in was stopped.
static int  plugin_sync (UgetPluginAria2* plugin)
{
	int        index;
	UgetNode*  node;
	UgetEvent* event;
	struct {
		UgetCommon*      common;
		UgetProgress*    progress;
	} temp;

	if (plugin->stopped == TRUE)
		return FALSE;
	if (plugin->synced == TRUE)
		return TRUE;

	node = plugin->node;
	// ------------------------------------------------
	// update progress
	temp.progress = ug_info_realloc (&node->info, UgetProgressInfo);
	temp.progress->complete       = plugin->completedLength;
	temp.progress->total          = plugin->totalLength;
	temp.progress->download_speed = plugin->downloadSpeed;
	temp.progress->upload_speed   = plugin->uploadSpeed;
	temp.progress->uploaded       = plugin->uploadLength;
	temp.progress->consume_time   = time(NULL) - plugin->start_time;
	// ratio
	if (temp.progress->uploaded && temp.progress->complete)
		temp.progress->ratio = (double)temp.progress->uploaded / (double)temp.progress->complete;
	else
		temp.progress->ratio = 0.0;
	// If total size is unknown, don't calculate percent.
	if (temp.progress->total)
		temp.progress->percent = (temp.progress->complete * 100) / temp.progress->total;
	else
		temp.progress->percent = 0;
	// If total size and average speed is unknown, don't calculate remain time.
	if (temp.progress->download_speed > 0 && temp.progress->total > 0)
		temp.progress->remain_time = (temp.progress->total - temp.progress->complete) / temp.progress->download_speed;

	// ------------------------------------------------
	temp.common = ug_info_realloc (&node->info, UgetCommonInfo);
	// sync changed limit from UgetNode
	if (plugin->limit[1] != temp.common->max_upload_speed ||
		plugin->limit[0] != temp.common->max_download_speed)
	{
		plugin->limit_by_user = TRUE;
	}

	// add nodes by files
	if (plugin->files_per_gid_prev != plugin->files_per_gid) {
#ifndef NDEBUG
		// debug
		if (temp.common->debug_level) {
			printf ("n_files: old %d - new %d\n",
					plugin->files_per_gid_prev,
					plugin->files_per_gid);
		}
#endif
		// add child node if aria2 add/create more files
		index = plugin->files_per_gid_prev;
		for (;  index < plugin->files.length;  index++) {
			if (plugin_insert_node (plugin, plugin->files.at[index].path, FALSE)) {
#ifndef NDEBUG
				// debug
				if (temp.common->debug_level)
					printf ("new child node name = %s\n", plugin->files.at[index].path);
#endif
			}
		}
		plugin->files_per_gid_prev  = plugin->files_per_gid;
	}

	// change node name.
	if (plugin->node_named == FALSE && plugin->files_per_gid > 0) {
		plugin->node_named  = TRUE;
		if (plugin->uri_type == URI_NET && temp.common->file == NULL) {
			ug_uri_init (&plugin->uri_part, node->children->name);
			index = plugin->uri_part.file;
			if (index != -1) {
				ug_free (node->name);
				node->name = ug_uri_get_file (&plugin->uri_part);
				event = uget_event_new (UGET_EVENT_NAME);
				uget_plugin_post ((UgetPlugin*) plugin, event);
#ifndef NDEBUG
				// debug
				if (temp.common->debug_level)
					printf ("base node name = %s\n", node->name);
#endif
			}
		}
	}

	switch (plugin->status) {
	case ARIA2_STATUS_ACTIVE:
		if (plugin->completedLength > 0 &&
		    plugin->completedLength == plugin->totalLength)
		{
#ifndef NDEBUG
			// debug
			if (temp.common->debug_level) {
				if ((node->state & UGET_STATE_UPLOADING) == 0)
					printf ("uploading...\n");
			}
#endif
			node->state |= UGET_STATE_UPLOADING;
		}
		break;

	case ARIA2_STATUS_WAITING:
		// clear uploading state
		node->state &= ~UGET_STATE_UPLOADING;
		break;

	case ARIA2_STATUS_COMPLETE:
		// clear uploading state
		node->state &= ~UGET_STATE_UPLOADING;
		// remove completed gid
		ug_free (plugin->gids.at[0]);
		plugin->gids.length -= 1;
		memmove (plugin->gids.at, plugin->gids.at + 1,
				sizeof (char*) * plugin->gids.length);
		// If there is only one followed gid and file, change uri.
		if (plugin->gids.length == 1 && plugin->files.length == 1) {
			// If URI scheme is not "magnet" and aria2 runs in local device
			if (global.data->uri_remote == FALSE &&
				plugin->uri_type != URI_MAGNET)
			{
				// change URI
				ug_free (temp.common->uri);
				ug_free (temp.common->file);
				temp.common->file = NULL;
				if (node->children && node->children->name)
					temp.common->uri = ug_strdup (node->children->name);
				else
					temp.common->uri = ug_strdup (plugin->files.at[0].path);
				uget_node_set_name_by_uri_string (node, temp.common->uri);
				// set node type
				node->children->type = UGET_NODE_ATTACHMENT;
#ifndef NDEBUG
				// debug
				if (temp.common->debug_level)
					printf ("uri followed to %s\n", temp.common->uri);
#endif
			}
		}
		// If no followed gid, it was completed.
		else if (plugin->gids.length == 0) {
			node->state |= UGET_STATE_COMPLETED;
			event = uget_event_new (UGET_EVENT_COMPLETED);
			uget_plugin_post ((UgetPlugin*)plugin, event);
		}
		// clear plugin->files
		ug_array_foreach (&plugin->files, (UgForeachFunc)aria2_file_clear, NULL);
		plugin->files.length = 0;
		plugin->files_per_gid = 0;
		plugin->files_per_gid_prev = 0;
		break;

	case ARIA2_STATUS_ERROR:
		// clear uploading state
		node->state &= ~UGET_STATE_UPLOADING;
#ifdef NO_RETRY_IF_CONNECT_FAILED
		// download speed was too slow
		if (plugin->errorCode == 5) {
#else
		// download speed was too slow  or  name resolution failed
		if (plugin->errorCode == 5 || plugin->errorCode == 19) {
#endif
			// retry
			if (temp.common->retry_count < temp.common->retry_limit || temp.common->retry_limit == 0) {
				temp.common->retry_count++;
				plugin->restart = TRUE;
#ifndef NDEBUG
				// debug
				if (temp.common->debug_level)
					printf ("retry %d\n", temp.common->retry_count);
#endif
			}
			else {
//				plugin->node->state |= UGET_STATE_ERROR;
				event = uget_event_new_error (
						UGET_EVENT_ERROR_TOO_MANY_RETRIES, NULL);
				uget_plugin_post ((UgetPlugin*) plugin, event);
			}
		}
		else {
			if (plugin->errorCode > 30)
				plugin->errorCode = 1;
			// if this is last gid.
			if (plugin->gids.length == 1) {
//				plugin->node->state |= UGET_STATE_ERROR;
#ifdef HAVE_GLIB
				event = uget_event_new_error (0,
						gettext (error_string[plugin->errorCode]));
#else
				event = uget_event_new_error (0,
						error_string[plugin->errorCode]);
#endif
				uget_plugin_post ((UgetPlugin*)plugin, event);
			}
		}

		// remove stopped gid
		ug_free (plugin->gids.at[0]);
		plugin->gids.length -= 1;
		memmove (plugin->gids.at, plugin->gids.at + 1,
				sizeof (char*) * plugin->gids.length);
		break;

	case ARIA2_STATUS_REMOVED:
		// clear uploading state
		node->state &= ~UGET_STATE_UPLOADING;
		// debug
		event = uget_event_new_normal (0, _("aria2: gid was removed."));
		uget_plugin_post ((UgetPlugin*)plugin, event);
		// remove completed gid
		ug_free (plugin->gids.at[0]);
		plugin->gids.length -= 1;
		memmove (plugin->gids.at, plugin->gids.at + 1,
				sizeof (char*) * plugin->gids.length);
		break;
	}

	// If we have followed gid, don't restart.
	if (plugin->gids.length > 0)
		plugin->restart = FALSE;
	else {
#ifndef NDEBUG
		// debug
		if (temp.common->debug_level)
			printf ("gids.length = %d\n", plugin->gids.length);
#endif
		// If no followed gid and no need to retry, it must stop.
		if (plugin->restart == FALSE)
			plugin->stopped = TRUE;
		else {
			plugin->retry_delay = temp.common->retry_delay;
			uget_aria2_request (global.data, plugin->start_request);
		}
	}

	// if plug-in was stopped, don't sync data with thread
	if (plugin->stopped == FALSE)
		plugin->synced = TRUE;
	return TRUE;
}

// ------------------------------------

static int  plugin_insert_node (UgetPluginAria2* plugin,
                                const char* fpath, int is_attachment)
{
	UgetNode*  node;
	char*      ctrl_file;

	// aria2 magnet metadata file
//	if (plugin->uri_type == URI_MAGNET) {
//		if (strncmp ("[METADATA]", fpath, 10) == 0)
//			fpath += 10;
//	}

	for (node = plugin->node->children;  node;  node = node->next) {
		if (strcmp (node->name, fpath) == 0)
			return FALSE;
	}

	// aria2 control file must add first
	ctrl_file = ug_malloc (strlen (fpath) + 6 + 1);  // + ".aria2" + '\0'
	ctrl_file[0] = 0;
	strcat (ctrl_file, fpath);
	strcat (ctrl_file, ".aria2");
	node = uget_node_new (NULL);
	node->name = ctrl_file;
	node->type = UGET_NODE_ATTACHMENT;
	uget_node_prepend (plugin->node, node);
	// download file
	node = uget_node_new (NULL);
	node->name = ug_strdup (fpath);
	uget_node_prepend (plugin->node, node);
	if (is_attachment)
		node->type = UGET_NODE_ATTACHMENT;

	return TRUE;
}
Esempio n. 23
0
int  ug_uri_init (UgUri* upart, const char* uri)
{
	const char* cur;
	const char* tmp;

	// scheme
#if defined _WIN32 || defined _WIN64
	cur = strpbrk (uri, ":\\/?#");  // make sure ':' before '/', '?', and '#'
#else
	cur = strpbrk (uri, ":/?#");    // make sure ':' before '/', '?', and '#'
#endif
	if (cur && cur[0] == ':') {
		if (upart == NULL)
			return cur - uri;
		upart->scheme_len = cur - uri;
		cur++;
	}
	else {
		if (upart == NULL)
			return 0;
		upart->scheme_len = 0;
		cur = uri;
	}

	upart->uri = uri;

#if defined _WIN32 || defined _WIN64
	// Windows Path
	if (upart->scheme_len == 1) {
		upart->scheme_len = 0;
		cur = uri;
	}
#endif // _WIN32 || _WIN64

	// authority & path
	if (upart->scheme_len && cur[0] == '/' && cur[1] == '/') {
		cur += 2;
		upart->authority = cur - uri;
		cur += strcspn (cur, "/");
	}
	else
		upart->authority = -1;
	upart->path = cur - uri;

	// file
	upart->file = -1;
	if (cur[0]) {
		for (; ; ) {
#if defined _WIN32 || defined _WIN64
			tmp = strpbrk (cur, "\\/?#");
			if (tmp == NULL || (tmp[0] != '/' && tmp[0] != '\\')) {
#else
			tmp = strpbrk (cur, "/?#");
			if (tmp == NULL || tmp[0] != '/') {
#endif // _WIN32 || _WIN64
				upart->file = cur - uri;
				break;
			}
			cur = tmp + 1;
		}
	}

	// query
	if ((tmp = strchr (cur, '?')) == NULL)
		upart->query = -1;
	else {
		cur = tmp + 1;
		upart->query = cur - uri;
	}

	// fragment
	if ((tmp = strrchr (cur, '#')) == NULL)
		upart->fragment = -1;
	else {
		cur = tmp + 1;
		upart->fragment = cur - uri;
	}

	// host & port
	upart->port = -1;
	if (upart->authority == -1)
		upart->host = -1;
	else {
		upart->host = upart->authority;
		tmp = uri + upart->authority;
		for (cur = uri + upart->path -1;  cur >= tmp;  cur--) {
			if (cur[0] == '@') {
				upart->host = cur - uri + 1;
				break;
			}
			if (cur[0] == ':')
				upart->port = cur - uri + 1;
		}
	}

	return upart->scheme_len;
}

int  ug_uri_part_scheme (UgUri* uuri, const char** scheme)
{
	if (scheme && uuri->scheme_len)
		*scheme = uuri->uri;
	return uuri->scheme_len;
}

int  ug_uri_part_file (UgUri* uuri, const char** file)
{
	if (uuri->file != -1) {
		if (file)
			*file = uuri->uri + uuri->file;
		if (uuri->query != -1)
			return uuri->query - uuri->file - 1;   // - '?'
		if (uuri->fragment != -1)
			return uuri->fragment - uuri->file - 1;  // - '#'
		return strlen (uuri->uri + uuri->file);
	}
	return 0;
}

int  ug_uri_part_file_ext (UgUri* uuri, const char** ext)
{
	const char* beg;
	const char* end;
	int  len;

	if (uuri->file != -1) {
		len = ug_uri_part_file (uuri, &beg);
		end = uuri->uri + uuri->file + len -1;
		for (;  end >= beg;  end--) {
			if (end[0] == '.') {
				end += 1;	// + '.'
				if (ext)
					*ext = end;
				return len - (end - beg);
			}
		}
	}
	return 0;
}

int  ug_uri_part_query (UgUri* uuri, const char** query)
{
	if (uuri->query != -1) {
		if (query)
			*query = uuri->uri + uuri->query;
		if (uuri->fragment != -1)
			return uuri->fragment - uuri->query -1;  // - '#'
		return strlen (uuri->uri + uuri->query);
	}
	return 0;
}

int  ug_uri_part_fragment (UgUri* uuri, const char** fragment)
{
	if (uuri->fragment != -1) {
		if (fragment)
			*fragment = uuri->uri + uuri->fragment;
		return strlen (uuri->uri + uuri->fragment);
	}
	return 0;
}

int  ug_uri_part_referrer (UgUri* uuri, const char** referrer)
{
	if (referrer)
		*referrer = uuri->uri;
	if (uuri->file == -1)
		return uuri->path;
	return uuri->file;
}

int  ug_uri_part_user (UgUri* uuri, const char** user)
{
	const char* beg;
	const char* end;

	if (uuri->authority == uuri->host)
		return 0;

	beg = uuri->uri + uuri->authority;
	end = uuri->uri + uuri->host - 1;    // - '@'
	if (user)
		*user = beg;
	for (; beg < end;  beg++) {
		if (beg[0] == ':')
			break;
	}
	return beg - uuri->uri - uuri->authority;
}

int  ug_uri_part_password (UgUri* uuri, const char** password)
{
	const char* tmp;
	int  length;

	length = ug_uri_part_user (uuri, &tmp);
	if (length && tmp[length] == ':') {
		tmp += length + 1;  // + ':'
		if (password)
			*password = tmp;
		return uuri->host - (tmp - uuri->uri) - 1;  // - '@'
	}
	return 0;
}

int  ug_uri_part_host (UgUri* uuri, const char** host)
{
	if (uuri->host != -1) {
		if (host)
			*host = uuri->uri + uuri->host;
		if (uuri->port != -1)
			return uuri->port - uuri->host - 1;   // - ':'
		else
			return uuri->path - uuri->host;
	}
	return 0;
}

int  ug_uri_part_port (UgUri* uuri, const char** port)
{
	if (uuri->port != -1) {
		if (port)
			*port = uuri->uri + uuri->port;
		return uuri->path - uuri->port;
	}
	return 0;
}

int  ug_uri_get_port (UgUri* uuri)
{
	if (uuri->port != -1)
		return strtol (uuri->uri + uuri->port, NULL, 10);
	return -1;
}

char* ug_uri_get_file (UgUri* uuri)
{
	const char*	str;
	char*		name;
	int			len;

	len = ug_uri_part_file (uuri, &str);
	if (len == 0)
		return NULL;
	name = ug_unescape_uri (str, len);
	if (ug_utf8_get_invalid ((uint8_t*) name, NULL) == -1)
		return name;

	ug_free (name);
	return ug_strndup (str, len);
}

// ------------------------------------
// match uri functions

int  ug_uri_match_hosts (UgUri* uuri, char** hosts)
{
	const char* str;
	const char* end1;
	const char* end2;
	int         len;
	int         lenHost;
	int         nthHost;

	len = ug_uri_part_host (uuri, &str);
	if (len) {
		for (nthHost = 0;  *hosts;  hosts++, nthHost++) {
			lenHost = strlen (*hosts);
			if (lenHost > len)
				continue;
			// compare host from head
			if (strncasecmp (uuri->uri, *hosts, len) == 0)
				return nthHost;
			// compare host from tail
			end1 = str + len -1;
			end2 = *hosts + lenHost -1;
			for (;  lenHost > 0;  lenHost--, end1--, end2--) {
				if (end1[0] != end2[0])
					break;
			}

			if (lenHost == 0)
				return nthHost;
		}
	}
	return -1;
}

int  ug_uri_match_schemes (UgUri* uuri, char** schemes)
{
	int         len;
	int         index;

	len = ug_uri_part_scheme (uuri, NULL);
	if (len) {
		for (index = 0;  *schemes;  schemes++, index++) {
			if (strncasecmp (uuri->uri, *schemes, len) == 0)
				return index;
		}
	}
	return -1;
}
Esempio n. 24
0
void  ug_json_final (UgJson* json)
{
	ug_free (json->buf.at);
	ug_free (json->stack.at);
}
Esempio n. 25
0
INT_ ug3_bnd_vol_nodes
 (INT_ *nnodeb,
  INT_ nnode,
  INT_ nbface,
  INT_ nelem,
  INT_ nelemc5,
  INT_ nelemc6,
  INT_ nelemc8,
  INT_ nquad,
  INT_3D * inibf,
  INT_4D * iniel,
  INT_5D * inielc5,
  INT_6D * inielc6,
  INT_8D * inielc8,
  INT_4D * iniq,
  DOUBLE_1D * del,
  DOUBLE_1D * ds,
  DOUBLE_3D * x)

{

/*
 * Reorder nodes so that boundary nodes are first followed by interior nodes
 * and increment all connectivity node indicies by one if the input connectivity
 * uses node index 0.
 * 
 * UG3 LIB : Unstructured Grid - General Purpose Routine Library
 * 3D Version : $Id: ug3_bnd_vol_nodes.c,v 1.6 2012/08/25 19:01:45 marcum Exp $
 * Copyright 1994-2012, David L. Marcum
 */

  DOUBLE_1D *save = NULL;

  INT_1D *node_map = NULL;

  INT_ i, i0, ibface, ielem, ierr, inode, inode1, inode2, inode3, inode4,
       inode5, inode6, inode7, inode8, iquad, jnode;

  inode = 1;

  ibface = 1;

  while (ibface <= nbface && inode > 0)
  {
    inode1 = inibf[ibface][0];
    inode2 = inibf[ibface][1];
    inode3 = inibf[ibface][2];

    inode = MIN (inode, inode1);
    inode = MIN (inode, inode2);
    inode = MIN (inode, inode3);

    ++ibface;
  }

  iquad = 1;

  while (iquad <= nquad && inode > 0)
  {
    inode1 = iniq[iquad][0];
    inode2 = iniq[iquad][1];
    inode3 = iniq[iquad][2];
    inode4 = iniq[iquad][3];

    inode = MIN (inode, inode1);
    inode = MIN (inode, inode2);
    inode = MIN (inode, inode3);
    inode = MIN (inode, inode4);

    ++iquad;
  }

  ielem = 1;

  while (ielem <= nelem && inode > 0)
  {
    inode1 = iniel[ielem][0];
    inode2 = iniel[ielem][1];
    inode3 = iniel[ielem][2];
    inode4 = iniel[ielem][3];

    inode = MIN (inode, inode1);
    inode = MIN (inode, inode2);
    inode = MIN (inode, inode3);
    inode = MIN (inode, inode4);

    ++ielem;
  }

  ielem = 1;

  while (ielem <= nelemc5 && inode > 0)
  {
    inode1 = inielc5[ielem][0];
    inode2 = inielc5[ielem][1];
    inode3 = inielc5[ielem][2];
    inode4 = inielc5[ielem][3];
    inode5 = inielc5[ielem][4];

    inode = MIN (inode, inode1);
    inode = MIN (inode, inode2);
    inode = MIN (inode, inode3);
    inode = MIN (inode, inode4);
    inode = MIN (inode, inode5);

    ++ielem;
  }

  ielem = 1;

  while (ielem <= nelemc6 && inode > 0)
  {
    inode1 = inielc6[ielem][0];
    inode2 = inielc6[ielem][1];
    inode3 = inielc6[ielem][2];
    inode4 = inielc6[ielem][3];
    inode5 = inielc6[ielem][4];
    inode6 = inielc6[ielem][5];

    inode = MIN (inode, inode1);
    inode = MIN (inode, inode2);
    inode = MIN (inode, inode3);
    inode = MIN (inode, inode4);
    inode = MIN (inode, inode5);
    inode = MIN (inode, inode6);

    ++ielem;
  }

  ielem = 1;

  while (ielem <= nelemc8 && inode > 0)
  {
    inode1 = inielc8[ielem][0];
    inode2 = inielc8[ielem][1];
    inode3 = inielc8[ielem][2];
    inode4 = inielc8[ielem][3];
    inode5 = inielc8[ielem][4];
    inode6 = inielc8[ielem][5];
    inode7 = inielc8[ielem][6];
    inode8 = inielc8[ielem][7];

    inode = MIN (inode, inode1);
    inode = MIN (inode, inode2);
    inode = MIN (inode, inode3);
    inode = MIN (inode, inode4);
    inode = MIN (inode, inode5);
    inode = MIN (inode, inode6);
    inode = MIN (inode, inode7);
    inode = MIN (inode, inode8);

    ++ielem;
  }

  if (inode == 0)
  {
    i0 = 1;

    for (ibface = 1; ibface <= nbface; ++ibface)
    {
      inibf[ibface][0] = inibf[ibface][0] + i0;
      inibf[ibface][1] = inibf[ibface][1] + i0;
      inibf[ibface][2] = inibf[ibface][2] + i0;
    }

    for (iquad = 1; iquad <= nquad; ++iquad)
    {
      iniq[iquad][0] = iniq[iquad][0] + i0;
      iniq[iquad][1] = iniq[iquad][1] + i0;
      iniq[iquad][2] = iniq[iquad][2] + i0;
      iniq[iquad][3] = iniq[iquad][3] + i0;
    }
  }
  else
    i0 = 0;

  ierr = 0;

  save = (DOUBLE_1D *) ug_malloc (&ierr, (nnode+1) * sizeof (DOUBLE_1D));

  if (ierr > 0)
    return (100315);

  ierr = ug3_bnd_nodes (-1, nnodeb, nnode, nbface, nquad,
                        inibf, iniq, &node_map,
                        del, ds, x);

  if (ierr != 0)
  {
    ug_free (save);
    ug_free (node_map);
    if (ierr > 0)
      return (1);
    else
      return (0);
  }

  for (i = 0; i <=2; ++i)
  {
    for (inode = 1; inode <= nnode; ++inode)
    {
      save[inode] = x[inode][i];
    }

    for (inode = 1; inode <= nnode; ++inode)
    {
      jnode = node_map[inode];

      x[jnode][i] = save[inode];
    }
  }

  if (del != NULL)
  {
    for (inode = 1; inode <= nnode; ++inode)
    {
      save[inode] = del[inode];
    }

    for (inode = 1; inode <= nnode; ++inode)
    {
      jnode = node_map[inode];

      del[jnode] = save[inode];
    }
  }

  if (ds != NULL)
  {
    for (inode = 1; inode <= nnode; ++inode)
    {
      save[inode] = ds[inode];
    }

    for (inode = 1; inode <= nnode; ++inode)
    {
      jnode = node_map[inode];

      ds[jnode] = save[inode];
    }
  }

  ug_free (save);

  for (ibface = 1; ibface <= nbface; ++ibface)
  {
    inode1 = inibf[ibface][0];
    inode2 = inibf[ibface][1];
    inode3 = inibf[ibface][2];

    inibf[ibface][0] = node_map[inode1];
    inibf[ibface][1] = node_map[inode2];
    inibf[ibface][2] = node_map[inode3];
  }

  for (iquad = 1; iquad <= nquad; ++iquad)
  {
    inode1 = iniq[iquad][0];
    inode2 = iniq[iquad][1];
    inode3 = iniq[iquad][2];
    inode4 = iniq[iquad][3];

    iniq[iquad][0] = node_map[inode1];
    iniq[iquad][1] = node_map[inode2];
    iniq[iquad][2] = node_map[inode3];
    iniq[iquad][3] = node_map[inode4];
  }

  for (ielem = 1; ielem <= nelem; ++ielem)
  {
    inode1 = iniel[ielem][0] + i0;
    inode2 = iniel[ielem][1] + i0;
    inode3 = iniel[ielem][2] + i0;
    inode4 = iniel[ielem][3] + i0;

    iniel[ielem][0] = node_map[inode1];
    iniel[ielem][1] = node_map[inode2];
    iniel[ielem][2] = node_map[inode3];
    iniel[ielem][3] = node_map[inode4];
  }

  for (ielem = 1; ielem <= nelemc5; ++ielem)
  {
    inode1 = inielc5[ielem][0] + i0;
    inode2 = inielc5[ielem][1] + i0;
    inode3 = inielc5[ielem][2] + i0;
    inode4 = inielc5[ielem][3] + i0;
    inode5 = inielc5[ielem][4] + i0;

    inielc5[ielem][0] = node_map[inode1];
    inielc5[ielem][1] = node_map[inode2];
    inielc5[ielem][2] = node_map[inode3];
    inielc5[ielem][3] = node_map[inode4];
    inielc5[ielem][4] = node_map[inode5];
  }

  for (ielem = 1; ielem <= nelemc6; ++ielem)
  {
    inode1 = inielc6[ielem][0] + i0;
    inode2 = inielc6[ielem][1] + i0;
    inode3 = inielc6[ielem][2] + i0;
    inode4 = inielc6[ielem][3] + i0;
    inode5 = inielc6[ielem][4] + i0;
    inode6 = inielc6[ielem][5] + i0;

    inielc6[ielem][0] = node_map[inode1];
    inielc6[ielem][1] = node_map[inode2];
    inielc6[ielem][2] = node_map[inode3];
    inielc6[ielem][3] = node_map[inode4];
    inielc6[ielem][4] = node_map[inode5];
    inielc6[ielem][5] = node_map[inode6];
  }

  for (ielem = 1; ielem <= nelemc8; ++ielem)
  {
    inode1 = inielc8[ielem][0] + i0;
    inode2 = inielc8[ielem][1] + i0;
    inode3 = inielc8[ielem][2] + i0;
    inode4 = inielc8[ielem][3] + i0;
    inode5 = inielc8[ielem][4] + i0;
    inode6 = inielc8[ielem][5] + i0;
    inode7 = inielc8[ielem][6] + i0;
    inode8 = inielc8[ielem][7] + i0;

    inielc8[ielem][0] = node_map[inode1];
    inielc8[ielem][1] = node_map[inode2];
    inielc8[ielem][2] = node_map[inode3];
    inielc8[ielem][3] = node_map[inode4];
    inielc8[ielem][4] = node_map[inode5];
    inielc8[ielem][5] = node_map[inode6];
    inielc8[ielem][6] = node_map[inode7];
    inielc8[ielem][7] = node_map[inode8];
  }

  ug_free (node_map);

  return (0);

}
Esempio n. 26
0
void  ugtk_download_form_get (UgtkDownloadForm* dform, UgetNode* node)
{
	UgetCommon*   common;
	UgetHttp*     http;
	UgUri         uuri;
	const gchar*  text;
	gint          number;

	// ------------------------------------------
	// UgetCommon
	common = ug_info_realloc (&node->info, UgetCommonInfo);
	// folder
	text = gtk_entry_get_text ((GtkEntry*)dform->folder_entry);
	ug_free (common->folder);
	common->folder = (*text) ? ug_strdup (text) : NULL;
	ug_str_remove_crlf (common->folder, common->folder);
	// user
	text = gtk_entry_get_text ((GtkEntry*)dform->username_entry);
	ug_free (common->user);
	common->user = (*text) ? ug_strdup (text) : NULL;
	ug_str_remove_crlf (common->user, common->user);
	// password
	text = gtk_entry_get_text ((GtkEntry*)dform->password_entry);
	ug_free (common->password);
	common->password = (*text) ? ug_strdup (text) : NULL;
	ug_str_remove_crlf (common->password, common->password);
	// retry_limit
	number = gtk_spin_button_get_value_as_int ((GtkSpinButton*) dform->spin_retry);
	common->retry_limit = number;
	// retry_delay
	number = gtk_spin_button_get_value_as_int ((GtkSpinButton*) dform->spin_delay);
	common->retry_delay = number;

	// max_upload_speed
	number = gtk_spin_button_get_value_as_int ((GtkSpinButton*) dform->spin_upload_speed) * 1024;
	common->max_upload_speed = number;
	// max_download_speed
	number = gtk_spin_button_get_value_as_int ((GtkSpinButton*) dform->spin_download_speed) * 1024;
	common->max_download_speed = number;

	// max_connections
	number = gtk_spin_button_get_value_as_int ((GtkSpinButton*) dform->spin_connections);
	common->max_connections = number;
	// timestamp
	common->timestamp = gtk_toggle_button_get_active (dform->timestamp);

	// URI
	if (gtk_widget_is_sensitive (dform->uri_entry) == TRUE) {
		text = gtk_entry_get_text ((GtkEntry*)dform->uri_entry);
		ug_free (common->uri);
		common->uri = (*text) ? ug_strdup (text) : NULL;
		ug_str_remove_crlf (common->uri, common->uri);
		if (common->uri) {
			ug_uri_init (&uuri, common->uri);
			// set user
			number = ug_uri_user (&uuri, &text);
			if (number > 0) {
				ug_free (common->user);
				common->user = ug_strndup (text, number);
			}
			// set password
			number = ug_uri_password (&uuri, &text);
			if (number > 0) {
				ug_free (common->password);
				common->password = ug_strndup (text, number);
			}
			// Remove user & password from URL
			if (uuri.authority != uuri.host) {
				memmove ((char*)uuri.uri + uuri.authority, (char*)uuri.uri + uuri.host,
						strlen (uuri.uri + uuri.host) + 1);
			}
		}
	}
	// mirrors
	if (gtk_widget_is_sensitive (dform->mirrors_entry) == TRUE) {
		text = gtk_entry_get_text ((GtkEntry*)dform->mirrors_entry);
		ug_free (common->mirrors);
		common->mirrors = (*text) ? ug_strdup (text) : NULL;
		ug_str_remove_crlf (common->mirrors, common->mirrors);
	}
	// file
	if (gtk_widget_is_sensitive (dform->file_entry) == TRUE) {
		text = gtk_entry_get_text ((GtkEntry*)dform->file_entry);
		ug_free (common->file);
		common->file = (*text) ? ug_strdup (text) : NULL;
		ug_str_remove_crlf (common->file, common->file);
	}

	// ------------------------------------------
	// UgetHttp
	http = ug_info_realloc (&node->info, UgetHttpInfo);
	// referrer
	text = gtk_entry_get_text ((GtkEntry*) dform->referrer_entry);
	ug_free (http->referrer);
	http->referrer = (*text) ? ug_strdup (text) : NULL;
	ug_str_remove_crlf (http->referrer, http->referrer);
	// cookie_file
	text = gtk_entry_get_text ((GtkEntry*) dform->cookie_entry);
	ug_free (http->cookie_file);
	http->cookie_file = (*text) ? ug_strdup (text) : NULL;
	ug_str_remove_crlf (http->cookie_file, http->cookie_file);
	// post_file
	text = gtk_entry_get_text ((GtkEntry*) dform->post_entry);
	ug_free (http->post_file);
	http->post_file = (*text) ? ug_strdup (text) : NULL;
	ug_str_remove_crlf (http->post_file, http->post_file);
	// user_agent
	text = gtk_entry_get_text ((GtkEntry*) dform->agent_entry);
	ug_free (http->user_agent);
	http->user_agent = (*text) ? ug_strdup (text) : NULL;
	ug_str_remove_crlf (http->user_agent, http->user_agent);

	// ------------------------------------------
	// UgetNode
	if (gtk_widget_get_sensitive (dform->radio_pause)) {
		if (gtk_toggle_button_get_active ((GtkToggleButton*) dform->radio_pause))
			node->state |= UGET_STATE_PAUSED;
		else
			node->state &= ~UGET_STATE_PAUSED;
	}
}
Esempio n. 27
0
static UG_THREAD_RETURN_TYPE  uget_curl_thread (UgetCurl* ugcurl)
{
	char*     tempstr;
	CURLcode  code;

	// perform
	do {
		ugcurl->restart = FALSE;
		code = curl_easy_perform (ugcurl->curl);
		curl_easy_getinfo (ugcurl->curl, CURLINFO_RESPONSE_CODE,
				&ugcurl->response);
		ugcurl->tested = TRUE;
	} while (ugcurl->restart);

	// free event
	if (ugcurl->event) {
		uget_event_free (ugcurl->event);
		ugcurl->event = NULL;
	}

	// response error
	if (ugcurl->response >= 400 && ugcurl->scheme_type == SCHEME_HTTP) {
		ugcurl->state = UGET_CURL_ERROR;
		tempstr = ug_strdup_printf ("Server response code : %ld",
				ugcurl->response);
		ugcurl->event = uget_event_new_error (
				UGET_EVENT_ERROR_CUSTOM, tempstr);
		ug_free (tempstr);
		goto exit;
	}

	switch (code) {
	case CURLE_OK:
		ugcurl->state = UGET_CURL_OK;
		break;

	// write error (out of disk space?) (exit)
	case CURLE_WRITE_ERROR:
		if (ugcurl->event_code > 0) {
			ugcurl->state = UGET_CURL_ERROR;
			ugcurl->event = uget_event_new_error (ugcurl->event_code, NULL);
			ugcurl->test_ok = FALSE;
			goto exit;
		}
		if (ugcurl->end > 0 && ugcurl->pos >= ugcurl->end) {
			ugcurl->state = UGET_CURL_OK;
			break;
		}
		// Don't break here
	// out of memory (exit)
	case CURLE_OUT_OF_MEMORY:
		ugcurl->state = UGET_CURL_ERROR;
		ugcurl->event = uget_event_new_error (
				UGET_EVENT_ERROR_OUT_OF_RESOURCE, ugcurl->error_string);
		goto exit;

	// abort by user (exit)
	case CURLE_ABORTED_BY_CALLBACK:
		ugcurl->state = UGET_CURL_ABORT;
		goto exit;

	// can resume (retry)
	case CURLE_RECV_ERROR:
	case CURLE_PARTIAL_FILE:
	case CURLE_OPERATION_TIMEDOUT:
		ugcurl->state = UGET_CURL_RETRY;
		break;

	// can't resume (retry)
	case CURLE_RANGE_ERROR:
	case CURLE_BAD_DOWNLOAD_RESUME:
	case CURLE_FTP_COULDNT_USE_REST:
		ugcurl->state = UGET_CURL_NOT_RESUMABLE;
		ugcurl->resumable = FALSE;
		break;

#ifdef NO_RETRY_IF_CONNECT_FAILED
	// can't connect (error)
	case CURLE_COULDNT_CONNECT:
		ugcurl->state = UGET_CURL_ERROR;
		ugcurl->event = uget_event_new_error (
				UGET_EVENT_ERROR_CONNECT_FAILED, ugcurl->error_string);
		goto exit;
#else
	case CURLE_COULDNT_CONNECT:
	case CURLE_COULDNT_RESOLVE_HOST:
#endif
	// retry
	case CURLE_SEND_ERROR:
	case CURLE_GOT_NOTHING:
	case CURLE_BAD_CONTENT_ENCODING:
		ugcurl->state = UGET_CURL_RETRY;
		ugcurl->event = uget_event_new_error (
				UGET_EVENT_ERROR_CUSTOM, ugcurl->error_string);
		break;

	// too many redirection (exit)
	case CURLE_TOO_MANY_REDIRECTS:
		ugcurl->state = UGET_CURL_ERROR;
		ugcurl->event = uget_event_new_error (
				UGET_EVENT_ERROR_CUSTOM, ugcurl->error_string);
		goto exit;

	// exit
	case CURLE_UNSUPPORTED_PROTOCOL:
		ugcurl->state = UGET_CURL_ERROR;
		ugcurl->event = uget_event_new_error (
				UGET_EVENT_ERROR_UNSUPPORTED_SCHEME, ugcurl->error_string);
		goto exit;

	// other error (exit)
#ifdef NO_RETRY_IF_CONNECT_FAILED
	case CURLE_COULDNT_RESOLVE_HOST:
#endif
	case CURLE_COULDNT_RESOLVE_PROXY:
	case CURLE_FAILED_INIT:
	case CURLE_URL_MALFORMAT:
	case CURLE_FTP_WEIRD_SERVER_REPLY:
	case CURLE_REMOTE_ACCESS_DENIED:
	default:
		ugcurl->state = UGET_CURL_ERROR;
		ugcurl->event = uget_event_new_error (
				UGET_EVENT_ERROR_CUSTOM, ugcurl->error_string);
		goto exit;
	}

exit:
	// if user stop downloading, set state to UGET_CURL_ABORT
	if (ugcurl->stopped == TRUE)
		ugcurl->state = UGET_CURL_ABORT;

	if (ugcurl->state == UGET_CURL_ERROR)
		ugcurl->test_ok = FALSE;
	ugcurl->stopped = TRUE;
	return UG_THREAD_RETURN_VALUE;
}
Esempio n. 28
0
void  uget_curl_run (UgetCurl* ugcurl, int joinable)
{
	CURL*  curl;

	curl = ugcurl->curl;
	uget_curl_decide_login (ugcurl);

	ugcurl->pos = ugcurl->beg;
	ugcurl->state = UGET_CURL_READY;
	ugcurl->stopped = FALSE;    // if thread stop, this value will be TRUE.
	ugcurl->response = 0;
	ugcurl->event_code = 0;
	ugcurl->progress_count = PROGRESS_COUNT_LIMIT;
	// reset speed
	ugcurl->speed[0] = 0;
	ugcurl->speed[1] = 0;

	ug_free (ugcurl->header.uri);
	ug_free (ugcurl->header.filename);
	ugcurl->header.uri = NULL;
	ugcurl->header.filename = NULL;

	curl_easy_setopt (ugcurl->curl, CURLOPT_RESUME_FROM_LARGE,
			(curl_off_t) ugcurl->beg);
	// Progress  --------------------------------------------------------------
	curl_easy_setopt (curl, CURLOPT_PROGRESSFUNCTION,
			(curl_progress_callback) uget_curl_progress);
	curl_easy_setopt (curl, CURLOPT_PROGRESSDATA, ugcurl);
	curl_easy_setopt (curl, CURLOPT_NOPROGRESS, FALSE);

	// Header -----------------------------------------------------------------
	if (ugcurl->tested) {
		switch (ugcurl->scheme_type) {
		case SCHEME_HTTP:
			curl_easy_setopt (curl, CURLOPT_HEADERFUNCTION,
					(curl_write_callback) uget_curl_header_http);
			curl_easy_setopt (curl, CURLOPT_HEADERDATA, ugcurl);
			break;

		default:
			curl_easy_setopt (curl, CURLOPT_POSTQUOTE, NULL);
			curl_easy_setopt (curl, CURLOPT_HEADERFUNCTION, NULL);
			curl_easy_setopt (curl, CURLOPT_HEADERDATA, NULL);
			break;
		}
	}
	else {
		// setup by scheme type
		switch (ugcurl->scheme_type) {
		case SCHEME_HTTP:
			curl_easy_setopt (curl, CURLOPT_HEADERFUNCTION,
					(curl_write_callback) uget_curl_header_http0);
			curl_easy_setopt (curl, CURLOPT_HEADERDATA, ugcurl);
			break;

		case SCHEME_FTP:
//			curl_easy_setopt (curl, CURLOPT_POSTQUOTE,
//					ugcurl->ftp_command);
			curl_easy_setopt (curl, CURLOPT_HEADERFUNCTION,
					(curl_write_callback) uget_curl_header_ftp0);
			curl_easy_setopt (curl, CURLOPT_HEADERDATA, ugcurl);
			break;

		default:
			curl_easy_setopt (curl, CURLOPT_HEADERFUNCTION, NULL);
			curl_easy_setopt (curl, CURLOPT_HEADERDATA, NULL);
			break;
		}
	}

	// Output -----------------------------------------------------------------
	curl_easy_setopt (curl, CURLOPT_NOBODY, 0L);
	curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION,
	                        uget_curl_output_default);
	curl_easy_setopt (curl, CURLOPT_WRITEDATA, ugcurl);

	ug_thread_create (&ugcurl->thread, (UgThreadFunc)uget_curl_thread, ugcurl);
	if (joinable == FALSE)
		ug_thread_unjoin (&ugcurl->thread);
}
Esempio n. 29
0
void ug_io_free_grid
 (INT_1D * Surf_Grid_BC_Flag,
  INT_1D * Surf_ID_Flag,
  INT_1D * Surf_Reconnection_Flag,
  INT_4D * Surf_Quad_Connectivity,
  INT_3D * Surf_Tria_Connectivity,
  INT_8D * Vol_Hex_Connectivity,
  INT_1D * Vol_ID_Flag,
  INT_5D * Vol_Pent_5_Connectivity,
  INT_6D * Vol_Pent_6_Connectivity,
  INT_4D * Vol_Tet_Connectivity,
  DOUBLE_3D * Coordinates,
  DOUBLE_1D * Initial_Normal_Spacing,
  DOUBLE_1D * BL_Thickness)

{

/*
 * Free grid data arrays.
 *
 * UG_IO LIB : Unstructured Grid - Input/Output Routine Library
 * $Id: ug_io_free_grid.c,v 1.12 2012/08/23 04:01:49 marcum Exp $
 * Copyright 1994-2012, David L. Marcum
 * 
 */

  ug_free (Surf_Grid_BC_Flag);
  ug_free (Surf_ID_Flag);
  ug_free (Surf_Quad_Connectivity);
  ug_free (Surf_Tria_Connectivity);
  ug_free (Surf_Reconnection_Flag);
  ug_free (Vol_Hex_Connectivity);
  ug_free (Vol_ID_Flag);
  ug_free (Vol_Pent_5_Connectivity);
  ug_free (Vol_Pent_6_Connectivity);
  ug_free (Vol_Tet_Connectivity);
  ug_free (Coordinates);
  ug_free (Initial_Normal_Spacing);
  ug_free (BL_Thickness);

  return;

}
Esempio n. 30
0
static size_t uget_curl_header_http0 (char *buffer, size_t size,
                                      size_t nmemb, UgetCurl* ugcurl)
{
	char*    file;
	char*    temp;
	int      length;

	file   = NULL;
	length = strlen (buffer);

	if (ugcurl->response == 0) {
		curl_easy_getinfo (ugcurl->curl, CURLINFO_RESPONSE_CODE,
				&ugcurl->response);
		// This will abort the transfer and return CURL_WRITE_ERROR.
		if (ugcurl->response >= 400)
			return 0;
	}

	if (length > 15 && strncasecmp (buffer, "Accept-Ranges: ", 15) == 0) {
		buffer += 15;
		if (strncasecmp (buffer, "none", 4) == 0)
			ugcurl->resumable = FALSE;
		else
			ugcurl->resumable = TRUE;
	}
	else if (length > 14 && strncasecmp (buffer, "Content-Type: ", 14) == 0) {
		buffer += 14;
		length = strcspn (buffer, "\r\n");
		if (length >= 9 && strncasecmp (buffer, "text/html", 9) == 0)
			ugcurl->html = TRUE;
		else
			ugcurl->html = FALSE;
	}
	// handle HTTP header "Location:"
	else if (length > 10 && strncasecmp (buffer, "Location: ", 10) == 0) {
		// exclude header and character '\r', '\n'
		buffer += 10;
		length = strcspn (buffer, "\r\n");
		if (ugcurl->header_store) {
			ug_free (ugcurl->header.uri);
			ugcurl->header.uri = ug_strndup (buffer, length);
			uget_curl_decide_scheme (ugcurl, ugcurl->header.uri);
		}
		else {
			temp = ug_strndup (buffer, length);
			uget_curl_decide_scheme (ugcurl, temp);
			ug_free (temp);
		}
		// decide login data (user & password) by scheme
		uget_curl_decide_login (ugcurl);
		// uget_curl_decide_scheme() has called ug_uri_init()
		// to initialize ugcurl->uri.part
//		ug_uri_init (&ugcurl->uri.part, ugcurl->header.uri);
		if (ugcurl->uri.part.file != -1 && ugcurl->header_store) {
			ug_free (ugcurl->header.filename);
			ugcurl->header.filename = ug_uri_get_file (&ugcurl->uri.part);
		}
		if (ugcurl->scheme_type == SCHEME_FTP) {
			curl_easy_setopt (ugcurl->curl, CURLOPT_HEADERFUNCTION,
					(curl_write_callback) uget_curl_header_ftp0);
		}
	}
	// handle HTTP header "Content-Location:"
	else if (length > 18 && strncasecmp (buffer, "Content-Location: ", 18) == 0) {
		// exclude header and character '\r', '\n'
		buffer += 18;
		temp = ug_strndup (buffer, strcspn (buffer, "\r\n"));
		ug_uri_init (&ugcurl->uri.part, temp);
		if (ugcurl->uri.part.file != -1 && ugcurl->header_store) {
			ug_free (ugcurl->header.filename);
			ugcurl->header.filename = ug_uri_get_file (&ugcurl->uri.part);
		}
		ug_free (temp);
	}
	// handle HTTP header "Content-Disposition:"
	else if (length > 21 && strncasecmp (buffer, "Content-Disposition: ", 21) == 0) {
		// exclude header and character '\r', '\n'
		buffer += 21;
		buffer = ug_strndup (buffer, strcspn (buffer, "\r\n"));
		// grab filename
		file = strstr (buffer, "filename=");
		if (file) {
			file += 9;	// value of "filename="
			if (file[0] != '\"')
				temp = ug_strndup (file, strcspn (file, ";"));
			else {
				file += 1;
				temp = ug_strndup (file, strcspn (file, "\""));
			}
			// grab filename
			ug_uri_init (&ugcurl->uri.part, temp);
			if (ugcurl->uri.part.file != -1 && ugcurl->header_store) {
				ug_free (ugcurl->header.filename);
				ugcurl->header.filename = ug_uri_get_file (&ugcurl->uri.part);
			}
			ug_free (temp);
		}
		ug_free (buffer);
	}

	return nmemb;
}