Example #1
0
void
check_servers(void)
{
	/* For each server, check the following, in order:
	 *
	 *  - Connection status. Skip the rest if unresolved
	 *  - Ping timeout.      Skip the rest detected
	 *  - Reconnect attempt. Skip the rest if successful
	 *  - Socket input.      Consume all input
	 *  */

	/* TODO: there's probably a better order to check these */

	server *s;

	if ((s = server_head) == NULL)
		return;

	time_t t = time(NULL);

	do {
		if (check_connect(s))
			continue;

		if (check_latency(s, t))
			continue;

		if (check_reconnect(s, t))
			continue;

		check_socket(s, t);

	} while ((s = s->next) != server_head);
}
Example #2
0
int
chdir_edit (GtkWidget * widget, gpointer data)
{
  gftp_window_data * wdata;
  const char *edttxt; 
  char *tempstr;

  wdata = data;
  if (!check_status (_("Chdir"), wdata, gftpui_common_use_threads (wdata->request), 0, 0,
                     wdata->request->chdir != NULL))
    return (0);

  if (check_reconnect (wdata) < 0)
    return (0);

  edttxt = gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (wdata->combo)->entry));

  if (!GFTP_IS_CONNECTED (wdata->request) && *edttxt != '\0')
    {
      toolbar_hostedit (NULL, NULL);
      return (0);
    }

  if ((tempstr = gftp_expand_path (wdata->request, edttxt)) == NULL)
    return (FALSE);

  if (gftpui_run_chdir (wdata, tempstr))
    add_history (wdata->combo, wdata->history, wdata->histlen, edttxt);

  g_free (tempstr);
  return (0);
}
Example #3
0
void end_input_event(void)
{
	screen_update(mpd);
	mpd->events = 0;

	mpdclient_put_connection(mpd);
	check_reconnect();
	auto_update_timer();
}
Example #4
0
/**
 * This function is called by the gidle.c library when MPD sends us an
 * idle event (or when the connection dies).
 */
static void
idle_callback(enum mpd_error error, enum mpd_server_error server_error,
	      const char *message, enum mpd_idle events,
	      void *ctx)
{
	struct mpdclient *c = ctx;

	c->idle = false;

	assert(mpdclient_is_connected(c));

	if (error != MPD_ERROR_SUCCESS) {
		char *allocated;

		if (error == MPD_ERROR_SERVER &&
		    server_error == MPD_SERVER_ERROR_UNKNOWN_CMD) {
			/* the "idle" command is not supported - fall
			   back to timer based polling */
			mpd_glib_free(c->source);
			c->source = NULL;
			auto_update_timer();
			return;
		}

		if (error == MPD_ERROR_SERVER)
			message = allocated = utf8_to_locale(message);
		else
			allocated = NULL;
		screen_status_message(message);
		g_free(allocated);
		screen_bell();
		doupdate();

		mpdclient_disconnect(c);
		screen_update(mpd);
		reconnect_source_id = g_timeout_add(1000, timer_reconnect,
						    NULL);
		return;
	}

	c->events |= events;
	mpdclient_update(c);

#ifndef NCMPC_MINI
	if (options.enable_xterm_title)
		update_xterm_title();
#endif

	screen_update(mpd);
	c->events = 0;

	mpdclient_put_connection(c);
	check_reconnect();
	auto_update_timer();
}
Example #5
0
static void
dochmod (gftp_window_data * wdata)
{
  gftpui_callback_data * cdata;

  mode = 0;
  if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (suid)))
    mode |= S_ISUID;
  if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (sgid)))
    mode |= S_ISGID;
  if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (sticky)))
    mode |= S_ISVTX;

  if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (ur)))
    mode |= S_IRUSR;
  if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (uw)))
    mode |= S_IWUSR;
  if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (ux)))
    mode |= S_IXUSR;

  if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (gr)))
    mode |= S_IRGRP;
  if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (gw)))
    mode |= S_IWGRP;
  if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (gx)))
    mode |= S_IXGRP;

  if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (or)))
    mode |= S_IROTH;
  if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (ow)))
    mode |= S_IWOTH;
  if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (ox)))
    mode |= S_IXOTH;

  if (check_reconnect (wdata) < 0)
    return;

  cdata = g_malloc0 (sizeof (*cdata));
  cdata->request = wdata->request;
  cdata->uidata = wdata;
  cdata->run_function = do_chmod_thread;

  gftpui_common_run_callback_function (cdata);

  g_free (cdata);
}
Example #6
0
static void
do_mpd_update(void)
{
	if (mpdclient_is_connected(mpd) &&
	    (mpd->source == NULL || mpd->events != 0 ||
	     (mpd->status != NULL &&
	      mpd_status_get_state(mpd->status) == MPD_STATE_PLAY)))
		mpdclient_update(mpd);

#ifndef NCMPC_MINI
	if (options.enable_xterm_title)
		update_xterm_title();
#endif

	screen_update(mpd);
	mpd->events = 0;

	mpdclient_put_connection(mpd);
	check_reconnect();
}
Example #7
0
void
transfer_window_files (gftp_window_data * fromwdata, gftp_window_data * towdata)
{
  gftp_file * tempfle, * newfle;
  GList * templist, * filelist;
  gftp_transfer * transfer;
  int num, ret, disconnect;

  if (!check_status (_("Transfer Files"), fromwdata, 1, 0, 1,
       towdata->request->put_file != NULL && fromwdata->request->get_file != NULL))
    return;

  if (!GFTP_IS_CONNECTED (fromwdata->request) || 
      !GFTP_IS_CONNECTED (towdata->request))
    {
      ftp_log (gftp_logging_error, NULL,
               _("Retrieve Files: Not connected to a remote site\n"));
      return;
    }

  if (check_reconnect (fromwdata) < 0 || check_reconnect (towdata) < 0)
    return;

  transfer = g_malloc0 (sizeof (*transfer));
  transfer->fromreq = gftp_copy_request (fromwdata->request);
  transfer->toreq = gftp_copy_request (towdata->request);
  transfer->fromwdata = fromwdata;
  transfer->towdata = towdata;

  num = 0;
  templist = gftp_gtk_get_list_selection (fromwdata);
  filelist = fromwdata->files;
  while (templist != NULL)
    {
      templist = get_next_selection (templist, &filelist, &num);
      tempfle = filelist->data;
      if (strcmp (tempfle->file, "..") != 0)
        {
          newfle = copy_fdata (tempfle);
          transfer->files = g_list_append (transfer->files, newfle);
        }
    }

  if (transfer->files != NULL)
    {
      gftp_swap_socks (transfer->fromreq, fromwdata->request);
      gftp_swap_socks (transfer->toreq, towdata->request);

      ret = gftp_gtk_get_subdirs (transfer);
      if (ret < 0)
        disconnect = 1;
      else
        disconnect = 0;

      if (!GFTP_IS_CONNECTED (transfer->fromreq))
        {
          gftpui_disconnect (fromwdata);
          disconnect = 1;
        } 

      if (!GFTP_IS_CONNECTED (transfer->toreq))
        {
          gftpui_disconnect (towdata);
          disconnect = 1;
        } 

      if (disconnect)
        {
          free_tdata (transfer);
          return;
        }

      gftp_swap_socks (fromwdata->request, transfer->fromreq);
      gftp_swap_socks (towdata->request, transfer->toreq);
    }

  if (transfer->files != NULL)
    {
      gftpui_common_add_file_transfer (transfer->fromreq, transfer->toreq, 
                                       transfer->fromwdata, transfer->towdata, 
                                       transfer->files);
      g_free (transfer);
    }
  else
    free_tdata (transfer);
}