Пример #1
0
static void		add_file(char *name, t_list **file, char *path, int options)
{
	if (name[0] == '.' && options & ALL_OPTION_MASK)
		set_file(name, path, file);
	else if (name[0] != '.')
		set_file(name, path, file);
}
Пример #2
0
static void ft_load_font(char *file)
{
    int current_font_id;
    enum screen_type screen = SCREEN_MAIN;
#if NB_SCREENS > 1
    MENUITEM_STRINGLIST(menu, ID2P(LANG_CUSTOM_FONT), NULL, 
                        ID2P(LANG_MAIN_SCREEN), ID2P(LANG_REMOTE_SCREEN))
    switch (do_menu(&menu, NULL, NULL, false))
    {
        case 0: /* main lcd */
            screen = SCREEN_MAIN;
            set_file(file, (char *)global_settings.font_file, MAX_FILENAME);
            break;
        case 1: /* remote */
            screen = SCREEN_REMOTE;
            set_file(file, (char *)global_settings.remote_font_file, MAX_FILENAME);
            break;
    }
#else
    set_file(file, (char *)global_settings.font_file, MAX_FILENAME);
#endif
    splash(0, ID2P(LANG_WAIT));
    current_font_id = global_status.font_id[screen];
    if (current_font_id >= 0)
        font_unload(current_font_id);
    current_font_id = font_load(file);
    if(screen==SCREEN_MAIN)
        font_set_ui(current_font_id);
    global_status.font_id[screen] = current_font_id;
    viewportmanager_theme_changed(THEME_UI_VIEWPORT);
}    
Пример #3
0
void
_moo_file_props_dialog_set_file (MooFilePropsDialog *dialog,
                                 MooFile            *file,
                                 MooFolder          *folder)
{
    char *text;
    char **info, **p;
    int i;

    g_return_if_fail (MOO_IS_FILE_PROPS_DIALOG (dialog));
    g_return_if_fail ((!file && !folder) || (file && MOO_IS_FOLDER (folder)));

    if (!file)
    {
        gtk_widget_set_sensitive (dialog->notebook, FALSE);
        container_cleanup (GTK_CONTAINER (dialog->table));
        set_file (dialog, NULL, NULL);
        return;
    }

    gtk_widget_set_sensitive (dialog->notebook, TRUE);
    info = _moo_folder_get_file_info (folder, file);
    g_return_if_fail (info != NULL);

    gtk_image_set_from_pixbuf (GTK_IMAGE (dialog->icon),
                               _moo_file_get_icon (file, GTK_WIDGET (dialog), GTK_ICON_SIZE_DIALOG));
    set_file (dialog, file, folder);

    container_cleanup (GTK_CONTAINER (dialog->table));

    for (p = info, i = 0; *p != NULL; ++i)
    {
        GtkWidget *label;

        if (!p[1])
        {
            g_critical ("oops");
            break;
        }

        label = gtk_label_new (NULL);
        text = g_markup_printf_escaped ("<b>%s</b>", *(p++));
        gtk_label_set_markup (GTK_LABEL (label), text);
        g_free (text);
        gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
        gtk_table_attach (GTK_TABLE (dialog->table), label, 0, 1, i, i+1,
                          GTK_EXPAND | GTK_FILL, GtkAttachOptions (0), 0, 0);

        label = gtk_label_new (*(p++));
        gtk_label_set_selectable (GTK_LABEL (label), TRUE);
        gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
        gtk_table_attach (GTK_TABLE (dialog->table), label, 1, 2, i, i+1,
                          GTK_EXPAND | GTK_FILL, GtkAttachOptions (0), 0, 0);
    }

    gtk_widget_show_all (dialog->table);

    g_strfreev (info);
}
Пример #4
0
static void edit_handle_remark_done(void *data, int bnr)
{
    EDITINFO *einf = (EDITINFO *) data;
    FILE *f;
    int close_next = quit_sequence;

    if (!bnr) {
	f = fopen((char*)UstrtoFilename(newname),"wb");
	if (f) {
	    set_file(f);
	    put_filecode(DOCUMENTFILE);
	    save_editwindow(einf->info);
	    unset_file();
	    cleanup_stencilstack();
	    fclose(f);
	    remove_auto_save(einf);
	    einf->saved = MP_True;
	    edit_close(data);
	} else {
	    message(MP_ERROR, translate("Can't save file."));
	    failure=MP_True;
	}
    } else if (bnr==1) {
	edit_auto_save(data, 0);
	einf->saved = MP_True;
	edit_close(data);
    } else if (bnr==2) {
	close_next = MP_False;
	quit_sequence = MP_False;
    }
    free(newname);
    kind_of_remark = NO_REMARK;
    newname = NULL;
    if (close_next) menu_close();
}
Пример #5
0
void
tm_frame_rep::choose_file (object fun, string title, string type,
			   string prompt, url name) {
  command  cb  = dialogue_command (get_server(), fun, 1);
  widget   wid = file_chooser_widget (cb, type, prompt);
  if (!is_scratch (name)) {
    set_directory (wid, as_string (head (name)));
    if ((type != "image") && (type != "")) {
      url u= tail (name);
      string old_suf= suffix (u);
      string new_suf= format_to_suffix (type);
      if ((suffix_to_format (suffix (u)) != type) &&
	  (old_suf != "") && (new_suf != ""))
	{
	  u= unglue (u, N(old_suf) + 1);
	  u= glue (u, "." * new_suf);
	}
      set_file (wid, as_string (u));
    }
  }
  else set_directory (wid, ".");
  dialogue_start (title, wid);
  if (type == "directory") send_keyboard_focus (get_directory (dialogue_wid));
  else send_keyboard_focus (get_file (dialogue_wid));
}
Пример #6
0
static void edit_auto_save(void *data, int dump)
{
    EDITINFO *einf = (EDITINFO *) data;
    FILE *f;
    /* Using dump%s to keep a possible #%s# as extra backup */

    if (!einf->auto_saved && !einf->empty) {
      if (dump) {
	buffer[0]=0;
	Ustrcat(buffer, translate("dump"));
	Ustrcat(buffer, strip_name(einf->filename));
	Ustrcat(buffer, translate(EXTENSION));
      } else {
	buffer[0]=0;
	Ustrcat(buffer, translate("#"));
	Ustrcat(buffer, strip_name(einf->filename));
	Ustrcat(buffer, translate("#" EXTENSION));
      }
	f = open_dirfile(userdir, buffer, "wb");
	if (f) {
	    set_file(f);
	    put_filecode(DOCUMENTFILE);
	    save_editwindow(einf->info);
	    unset_file();
	    cleanup_stencilstack();
	    fclose(f);
	    einf->auto_saved = MP_True;
	} else failure=MP_True;
    }
    /* 
    ** In case of a failure, the document should be saved
    ** in another file, to make sure nothing gets lost.
    **
    */
}
CL_FileDialog_Generic::CL_FileDialog_Generic(
	CL_FileDialog *self,
	const std::string &title,
	const std::string &file,
	const std::string &filter)
	: filedialog(self)
{
	behavior = CL_FileDialog::quit_always;
	button = CL_FileDialog::button_none;
	// TODO: Calculate proper size
	int width = 400;
	int height = 315;
	int x = (CL_Display::get_width() - width) / 2;
	int y = (CL_Display::get_height() - height) / 2;
	filedialog->set_position(CL_Rect(x, y, x + width, y + height));
	filedialog->set_title(title);

	CL_Component *client_area = filedialog->get_client_area();

	width = client_area->get_width();

	label_dir = new CL_Label(CL_Point(10, 12), "Directory:", client_area);
	input_dir = new CL_InputBox(CL_Rect(65, 10, width - 120, 30), client_area);
	input_dir->enable(false);

	button_parent = new CL_Button(CL_Rect(width - 115, 9, width - 65, 28), "Parent", client_area);
	button_createdir = new CL_Button(CL_Rect(width - 60, 9, width - 10, 28), "New", client_area);

	treeview_files = new CL_TreeView(CL_Rect(10, 32, width - 10, 197), client_area);
	treeview_files->add_column("Filename", 200);
	treeview_files->add_column("Size", 80);
	treeview_files->add_column("Type", 100);
	treeview_files->show_root_decoration(false);

	label_file = new CL_Label(CL_Point(10, 207), "Filename:", client_area);
	input_file = new CL_InputBox(CL_Rect(65, 205, width - 10, 225), client_area);

	label_filter = new CL_Label(CL_Point(10, 232), "Filter:", client_area);
	input_filter = new CL_InputBox(CL_Rect(65, 230, width - 10, 250), client_area);

	button_ok = new CL_Button(CL_Rect(10, 260, 100, 280), "OK", client_area);
	button_cancel = new CL_Button(CL_Rect(width - 110, 260, width - 10, 280), "Cancel", client_area);

	slots.connect(self->sig_set_options(), this, &CL_FileDialog_Generic::on_set_options);
	slots.connect(treeview_files->sig_selection_changed(), this, &CL_FileDialog_Generic::on_file_activated);
	slots.connect(button_ok->sig_clicked(), this, &CL_FileDialog_Generic::on_button_quit, true);
	slots.connect(button_cancel->sig_clicked(), this, &CL_FileDialog_Generic::on_button_quit, false);
	slots.connect(button_parent->sig_clicked(), this, &CL_FileDialog_Generic::on_button_parent);
	slots.connect(button_createdir->sig_clicked(), this, &CL_FileDialog_Generic::on_button_createdir);
	slots.connect(input_file->sig_return_pressed(), this, &CL_FileDialog_Generic::on_edit_file);
	slots.connect(input_filter->sig_return_pressed(), this, &CL_FileDialog_Generic::on_edit_filter);
	slots.connect(input_dir->sig_return_pressed(), this, &CL_FileDialog_Generic::on_edit_dir);
	
	set_file(file, false);
	set_filter(filter, false);
	show_hidden = false;

	read_dir();
}
Пример #8
0
static void set(void) {
	if (getuid() != 0) {
		fprintf(stderr, "Error: you need to be root to run this command\n");
		exit(1);
	}

	char *cfgfile;
	if (asprintf(&cfgfile, "%s/firejail/firecfg.config", LIBDIR) == -1)
		errExit("asprintf");

	char *firejail_exec;
	if (asprintf(&firejail_exec, "%s/bin/firejail", PREFIX) == -1)
		errExit("asprintf");

	FILE *fp = fopen(cfgfile, "r");
	if (!fp) {
		fprintf(stderr, "Error: cannot open %s\n", cfgfile);
		exit(1);
	}
	
	char buf[MAX_BUF];
	int lineno = 0;
	while (fgets(buf, MAX_BUF,fp)) {
		lineno++;
		if (*buf == '#') // comments
			continue;

		// do not accept .. and/or / in file name
		if (strstr(buf, "..") || strchr(buf, '/')) {
			fprintf(stderr, "Error: invalid line %d in %s\n", lineno, cfgfile);
			exit(1);
		}
		
		// remove \n
		char *ptr = strchr(buf, '\n');
		if (ptr)
			*ptr = '\0';
			
		// trim spaces
		ptr = buf;
		while (*ptr == ' ' || *ptr == '\t')
			ptr++;
		char *start = ptr;
		
		// empty line
		if (*start == '\0')
			continue;

		// set link
		set_file(start, firejail_exec);
	}

	fclose(fp);
	free(cfgfile);
	free(firejail_exec);
}
Пример #9
0
void
_moo_py_init_print_funcs (void)
{
    static gboolean done;

    if (done)
        return;

    done = TRUE;

    if (PyType_Ready (&MooPyFile_Type) < 0)
    {
        g_critical ("could not init MooPyFile type");
        return;
    }

    set_file ("stdout", print_func);
    set_file ("stderr", printerr_func);
}
Пример #10
0
TEE_Result tee_fs_dirfile_open(bool create, uint8_t *hash,
			       const struct tee_fs_dirfile_operations *fops,
			       struct tee_fs_dirfile_dirh **dirh_ret)
{
	TEE_Result res;
	struct tee_fs_dirfile_dirh *dirh = calloc(1, sizeof(*dirh));
	size_t n;

	if (!dirh)
		return TEE_ERROR_OUT_OF_MEMORY;

	dirh->fops = fops;
	res = fops->open(create, hash, NULL, NULL, &dirh->fh);
	if (res)
		goto out;

	for (n = 0;; n++) {
		struct dirfile_entry dent;

		res = read_dent(dirh, n, &dent);
		if (res) {
			if (res == TEE_ERROR_ITEM_NOT_FOUND)
				res = TEE_SUCCESS;
			goto out;
		}

		if (!dent.oidlen)
			continue;

		if (test_file(dirh, dent.file_number)) {
			DMSG("clearing duplicate file number %" PRIu32,
			     dent.file_number);
			memset(&dent, 0, sizeof(dent));
			res = write_dent(dirh, n, &dent);
			if (res)
				goto out;
			continue;
		}

		res = set_file(dirh, dent.file_number);
		if (res != TEE_SUCCESS)
			goto out;
	}
out:
	if (!res) {
		dirh->ndents = n;
		*dirh_ret = dirh;
	} else {
		tee_fs_dirfile_close(dirh);
	}
	return res;
}
void CL_FileDialog_Generic::on_set_options(const CL_DomElement &options)
{
	if (options.has_attribute("file"))
		set_file(options.get_attribute("file"), false);

	if (options.has_attribute("filter"))
		set_filter(options.get_attribute("filter"), false);

	if (options.has_attribute("show_hidden"))
		show_hidden = CL_String::to_bool(options.get_attribute("show_hidden"));

	read_dir();
}
Пример #12
0
void
create_scroll()
{
    seteuid(getuid(this_object()));
    add_prop(OBJ_I_NO_DROP, "Don't drop the slate, it holds valueable " +
			    "information!\n");
    set_name("slate");
    set_short("slate displaying 'READ ME!'");
    set_long("The slate has a large, square display with backlighting. " +
	     "On the screen the text 'READ ME!' is displayed in big letters.\n");
    set_autoload();
    set_file(APPRENTICE_SCROLL_FILE);
}
Пример #13
0
void
create_scroll()
{
    set_name("book");
    set_adj("blue");
    set_long("It's labeled 'Fairy tails from Genesis'\n");

    add_prop(OBJ_I_VALUE, 678);
    add_prop(OBJ_I_WEIGHT, 40);
    add_prop(OBJ_I_VOLUME, 254);

    set_file("/d/Genesis/doc/examples/obj/book");
}
void CL_FileDialog_Generic::on_file_activated(const CL_TreeNode &node)
{
	CL_TreeItem *treeitem = (CL_TreeItem *)node.get_component();

	std::string item = treeitem->get_text(0);

	if(treeitem->get_text(2) == "Directory")
	{
		CL_Directory::change_to(item);
		read_dir();
	}
	else
	{
		set_file(item, false);
	}
}
Пример #15
0
static bool set_backdrop(void)
{
    /* load the image 
    if(sb_set_backdrop(SCREEN_MAIN, selected_file)) {
        splash(HZ, str(LANG_BACKDROP_LOADED));
        set_file(selected_file, (char *)global_settings.backdrop_file,
            MAX_FILENAME);
        return true;
    } else {
        splash(HZ, str(LANG_BACKDROP_FAILED));
        return false;
    }*/
    set_file(selected_file, (char *)global_settings.backdrop_file,
        MAX_FILENAME);
    skin_backdrop_load_setting();
    return true;
}
Пример #16
0
TEE_Result tee_fs_dirfile_get_tmp(struct tee_fs_dirfile_dirh *dirh,
				  struct tee_fs_dirfile_fileh *dfh)
{
	TEE_Result res;
	int i = 0;

	if (dirh->files) {
		bit_ffc(dirh->files, dirh->nbits, &i);
		if (i == -1)
			i = dirh->nbits;
	}

	res = set_file(dirh, i);
	if (!res)
		dfh->file_number = i;

	return res;
}
Пример #17
0
static void do_file(char *name)
{
    if (name && !strcmp(name,"-"))
	name = NULL;
    set_file(name ? name : "<stdin>");
    if (!name)
	if (dup2(fd0,0) < 0) {
	    perror("dup2");
	    exit(1);
	}
    if (allow_extensions) {
	int i;

	for (i = 0; i != cpp_options*2; i++)
	    add_cpp_arg(cpp_option[i]);
	add_cpp_arg("-I");
	add_cpp_arg(INSTALL_PREFIX "/share/m8cutils/include");
	run_cpp_on_file(name);
    }
    else {
	int fd;

	if (name) {
	    fd = open(name,O_RDONLY);
	    if (fd < 0) {
		perror(name);
		exit(1);
	    }
	    if (dup2(fd,0) < 0) {
		perror("dup2");
		exit(1);
	    }
	}
    }
    id_begin_file();
    (void) yyparse();
    id_end_file();
    remove_macros();
    if (allow_extensions)
	reap_cpp();
}
Пример #18
0
void
rxvt_image::set_file_geometry (rxvt_screen *s, const char *file)
{
  if (!file || !*file)
    return;

  const char *p = strchr (file, ';');

  if (p)
    {
      size_t len = p - file;
      char *f = rxvt_temp_buf<char> (len + 1);
      memcpy (f, file, len);
      f[len] = '\0';
      file = f;
    }

  set_file (s, file);
  alpha = 0x8000;
  set_geometry (p ? p + 1 : "");
}
Пример #19
0
void DocumentView::create_new_file() {
    /*
     *  Creates a new file. We create a Gio::File for a path in the tempfiles directory
     *  but don't actually create a file there. That way the lack of existence of the path
     *  allows us to determine whether the file is new, or has been deleted on disk
     */

    auto temp_files = tempfiles_directory();
    int existing_count = window_.new_file_count();

    //FIXME: This will create multiple files with the same path if we have untitled
    //files in two windows. I'm not sure if this is a problem or not considering these
    //paths are just placeholders. In future it may be!
    auto untitled_filename = _u("Untitled {0}").format(existing_count + 1);
    auto full_path = os::path::join(temp_files, untitled_filename);
    auto file = Gio::File::create_for_path(full_path.encode());

    set_file(file);

    buffer_->set_modified(true);
}
Пример #20
0
static void edit_handle_fileselc_save(void *data, Char *name)
{
    EDITINFO *einf = (EDITINFO *) data;

    if (name) {
	FILE *f;
	int check_found = check_name(einf, name);

	f = fopen((char*)UstrtoFilename(name),"wb");
	if (f) {
	    set_wait_cursor(einf->win_id);
	    set_file(f);
	    put_filecode(DOCUMENTFILE);
	    save_editwindow(einf->info);
	    unset_file();
	    cleanup_stencilstack();
	    fclose(f);
	    remove_auto_save(einf);
	    einf->auto_saved = MP_True;
	    einf->saved = MP_True;
	    if (check_found) {
		einf->view_mode = MP_True;
		message(MP_CLICKREMARK, translate("You have saved the document under a name\n"
			"which is already used by a different window.\n"
			"To make sure that your backups are\n"
			"correct, this copy will be in view mode."));
	    }
	    set_name(einf,name);
	    message(MP_MESSAGE,translate("File saved."));
	    remove_wait_cursor();
	} else {
	    message(MP_ERROR, translate("Can't save file! "));
	    free(newname);
	    failure=MP_True;
	}
    } else
	free(newname);
    kind_of_remark = NO_REMARK;
}
Пример #21
0
int 
Log :: init(const char * name)
{
    //size_t path_len;
    FILE * fp;
    pthread_t write_t;    
    
    pthread_mutex_init(&log_mutex, NULL);
    pthread_cond_init(&log_cond, NULL);
    
     
    fp = fopen(name, "w+");
    if(fp != NULL)
        set_file(fp);
    else
        return -1;

    if (pthread_create(&write_t, NULL, write_log, NULL) != 0) 
    {
        return -1;
    }
    STATUS = LOG_RUN;
    return 0; 
}
Пример #22
0
void socket_input_stream::close()
{
    set_file(-1, 0);
}
Пример #23
0
void DocumentView::open_file(const unicode& filename) {
    auto file = Gio::File::create_for_path(filename.encode());
    set_file(file);
}
Пример #24
0
void
tm_window_rep::set_window_url (url u) {
    if (!is_none (u)) set_file (wid, as_string (u));
}
Пример #25
0
socket_input_stream::socket_input_stream(int file_descriptor, bool owns_file) :
    blocking_(true)
{
    set_file(file_descriptor, owns_file);
}
Пример #26
0
static void set_private_key(struct mailprivacy * privacy,
    char * email, char * file)
{
  set_file(private_keys, email, file);
}
Пример #27
0
static int get_cert_from_sig(struct mailprivacy * privacy,
    mailmessage * msg,
    struct mailmime * mime)
{
  clistiter * cur;
  struct mailmime * signed_mime;
  struct mailmime * signature_mime;
  int res;
  char signature_filename[PATH_MAX];
  char quoted_signature_filename[PATH_MAX];
  char * email;
  char * cert_file;
  char store_cert_filename[PATH_MAX];
  char quoted_store_cert_filename[PATH_MAX];
  int r;
  char command[PATH_MAX];

  if (* cert_dir == '\0')
    return MAIL_ERROR_INVAL;

  if (mime->mm_type != MAILMIME_MULTIPLE)
    return MAIL_ERROR_INVAL;

  email = get_first_from_addr(mime);
  if (email == NULL)
    return MAIL_ERROR_INVAL;
  
  cert_file = get_cert_file(email);
  if (cert_file != NULL)
    return MAIL_NO_ERROR;

  /* get the two parts of the S/MIME message */
  
  cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list);
  if (cur == NULL) {
    res = MAIL_ERROR_INVAL;
    goto err;
  }
  
  signed_mime = cur->data;
  cur = clist_next(cur);
  if (cur == NULL) {
    res = MAIL_ERROR_INVAL;
    goto err;
  }

  signature_mime = cur->data;
  
  r = mailprivacy_fetch_decoded_to_file(privacy,
      signature_filename, sizeof(signature_filename),
      msg, signature_mime);
  if (r != MAILIMF_NO_ERROR) {
    res = r;
    goto err;
  }
  
  r = mail_quote_filename(quoted_signature_filename,
       sizeof(quoted_signature_filename), signature_filename);
  if (r < 0) {
    res = MAIL_ERROR_MEMORY;
    goto unlink_signature;
  }
  
  snprintf(store_cert_filename, sizeof(store_cert_filename),
      "%s/%s" CERTIFICATE_SUFFIX, cert_dir, email);
  
  r = mail_quote_filename(quoted_store_cert_filename,
       sizeof(quoted_store_cert_filename), store_cert_filename);
  if (r < 0) {
    res = MAIL_ERROR_MEMORY;
    goto unlink_signature;
  }
  
  snprintf(command, sizeof(command),
      "openssl pkcs7 -inform DER -in '%s' -out '%s' -print_certs 2>/dev/null",
      quoted_signature_filename, quoted_store_cert_filename);
  
  r = system(command);
  if (WEXITSTATUS(r) != 0) {
    res = MAIL_ERROR_COMMAND;
    goto unlink_signature;
  }

  unlink(signature_filename);
  
  set_file(certificates, email, store_cert_filename);
  
  return MAIL_NO_ERROR;
  
 unlink_signature:
  unlink(signature_filename);
 err:
  return res;
}
Пример #28
0
static int transmit_audio(fax_session *s)
{
	int res = -1;
	struct ast_format original_read_fmt;
	struct ast_format original_write_fmt;
	fax_state_t fax;
	t30_state_t *t30state;
	struct ast_frame *inf = NULL;
	int last_state = 0;
	struct timeval now, start, state_change;
	enum ast_t38_state t38_state;
	struct ast_control_t38_parameters t38_parameters = { .version = 0,
							     .max_ifp = 800,
							     .rate = AST_T38_RATE_14400,
							     .rate_management = AST_T38_RATE_MANAGEMENT_TRANSFERRED_TCF,
							     .fill_bit_removal = 1,
/*
 * spandsp has API calls to support MMR and JBIG transcoding, but they aren't
 * implemented quite yet... so don't offer them to the remote endpoint
 *							     .transcoding_mmr = 1,
 *							     .transcoding_jbig = 1,
*/
	};

	ast_format_clear(&original_read_fmt);
	ast_format_clear(&original_write_fmt);

	/* if in called party mode, try to use T.38 */
	if (s->caller_mode == FALSE) {
		/* check if we are already in T.38 mode (unlikely), or if we can request
		 * a switch... if so, request it now and wait for the result, rather
		 * than starting an audio FAX session that will have to be cancelled
		 */
		if ((t38_state = ast_channel_get_t38_state(s->chan)) == T38_STATE_NEGOTIATED) {
			return 1;
		} else if ((t38_state != T38_STATE_UNAVAILABLE) &&
			   (t38_parameters.request_response = AST_T38_REQUEST_NEGOTIATE,
			    (ast_indicate_data(s->chan, AST_CONTROL_T38_PARAMETERS, &t38_parameters, sizeof(t38_parameters)) == 0))) {
			/* wait up to five seconds for negotiation to complete */
			unsigned int timeout = 5000;
			int ms;

			ast_debug(1, "Negotiating T.38 for receive on %s\n", ast_channel_name(s->chan));
			while (timeout > 0) {
				ms = ast_waitfor(s->chan, 1000);
				if (ms < 0) {
					ast_log(LOG_WARNING, "something bad happened while channel '%s' was polling.\n", ast_channel_name(s->chan));
					return -1;
				}
				if (!ms) {
					/* nothing happened */
					if (timeout > 0) {
						timeout -= 1000;
						continue;
					} else {
						ast_log(LOG_WARNING, "channel '%s' timed-out during the T.38 negotiation.\n", ast_channel_name(s->chan));
						break;
					}
				}
				if (!(inf = ast_read(s->chan))) {
					return -1;
				}
				if ((inf->frametype == AST_FRAME_CONTROL) &&
				    (inf->subclass.integer == AST_CONTROL_T38_PARAMETERS) &&
				    (inf->datalen == sizeof(t38_parameters))) {
					struct ast_control_t38_parameters *parameters = inf->data.ptr;

					switch (parameters->request_response) {
					case AST_T38_NEGOTIATED:
						ast_debug(1, "Negotiated T.38 for receive on %s\n", ast_channel_name(s->chan));
						res = 1;
						break;
					case AST_T38_REFUSED:
						ast_log(LOG_WARNING, "channel '%s' refused to negotiate T.38\n", ast_channel_name(s->chan));
						break;
					default:
						ast_log(LOG_ERROR, "channel '%s' failed to negotiate T.38\n", ast_channel_name(s->chan));
						break;
					}
					ast_frfree(inf);
					if (res == 1) {
						return 1;
					} else {
						break;
					}
				}
				ast_frfree(inf);
			}
		}
	}

#if SPANDSP_RELEASE_DATE >= 20080725
        /* for spandsp shaphots 0.0.6 and higher */
        t30state = &fax.t30;
#else
        /* for spandsp release 0.0.5 */
        t30state = &fax.t30_state;
#endif

	ast_format_copy(&original_read_fmt, ast_channel_readformat(s->chan));
	if (original_read_fmt.id != AST_FORMAT_SLINEAR) {
		res = ast_set_read_format_by_id(s->chan, AST_FORMAT_SLINEAR);
		if (res < 0) {
			ast_log(LOG_WARNING, "Unable to set to linear read mode, giving up\n");
			goto done;
		}
	}

	ast_format_copy(&original_write_fmt, ast_channel_writeformat(s->chan));
	if (original_write_fmt.id != AST_FORMAT_SLINEAR) {
		res = ast_set_write_format_by_id(s->chan, AST_FORMAT_SLINEAR);
		if (res < 0) {
			ast_log(LOG_WARNING, "Unable to set to linear write mode, giving up\n");
			goto done;
		}
	}

	/* Initialize T30 terminal */
	fax_init(&fax, s->caller_mode);

	/* Setup logging */
	set_logging(&fax.logging);
	set_logging(&t30state->logging);

	/* Configure terminal */
	set_local_info(t30state, s);
	set_file(t30state, s);
	set_ecm(t30state, TRUE);

	fax_set_transmit_on_idle(&fax, TRUE);

	t30_set_phase_e_handler(t30state, phase_e_handler, s);

	start = state_change = ast_tvnow();

	ast_activate_generator(s->chan, &generator, &fax);

	while (!s->finished) {
		inf = NULL;

		if ((res = ast_waitfor(s->chan, 25)) < 0) {
			ast_debug(1, "Error waiting for a frame\n");
			break;
		}

		/* Watchdog */
		now = ast_tvnow();
		if (ast_tvdiff_sec(now, start) > WATCHDOG_TOTAL_TIMEOUT || ast_tvdiff_sec(now, state_change) > WATCHDOG_STATE_TIMEOUT) {
			ast_log(LOG_WARNING, "It looks like we hung. Aborting.\n");
			res = -1;
			break;
		}

		if (!res) {
			/* There was timeout waiting for a frame. Loop around and wait again */
			continue;
		}

		/* There is a frame available. Get it */
		res = 0;

		if (!(inf = ast_read(s->chan))) {
			ast_debug(1, "Channel hangup\n");
			res = -1;
			break;
		}

		ast_debug(10, "frame %d/%u, len=%d\n", inf->frametype, (unsigned int) inf->subclass.format.id, inf->datalen);

		/* Check the frame type. Format also must be checked because there is a chance
		   that a frame in old format was already queued before we set channel format
		   to slinear so it will still be received by ast_read */
		if (inf->frametype == AST_FRAME_VOICE && inf->subclass.format.id == AST_FORMAT_SLINEAR) {
			if (fax_rx(&fax, inf->data.ptr, inf->samples) < 0) {
				/* I know fax_rx never returns errors. The check here is for good style only */
				ast_log(LOG_WARNING, "fax_rx returned error\n");
				res = -1;
				break;
			}
			if (last_state != t30state->state) {
				state_change = ast_tvnow();
				last_state = t30state->state;
			}
		} else if ((inf->frametype == AST_FRAME_CONTROL) &&
			   (inf->subclass.integer == AST_CONTROL_T38_PARAMETERS)) {
			struct ast_control_t38_parameters *parameters = inf->data.ptr;

			if (parameters->request_response == AST_T38_NEGOTIATED) {
				/* T38 switchover completed */
				s->t38parameters = *parameters;
				ast_debug(1, "T38 negotiated, finishing audio loop\n");
				res = 1;
				break;
			} else if (parameters->request_response == AST_T38_REQUEST_NEGOTIATE) {
				t38_parameters.request_response = AST_T38_NEGOTIATED;
				ast_debug(1, "T38 request received, accepting\n");
				/* Complete T38 switchover */
				ast_indicate_data(s->chan, AST_CONTROL_T38_PARAMETERS, &t38_parameters, sizeof(t38_parameters));
				/* Do not break audio loop, wait until channel driver finally acks switchover
				 * with AST_T38_NEGOTIATED
				 */
			}
		}

		ast_frfree(inf);
		inf = NULL;
	}

	ast_debug(1, "Loop finished, res=%d\n", res);

	if (inf)
		ast_frfree(inf);

	ast_deactivate_generator(s->chan);

	/* If we are switching to T38, remove phase E handler. Otherwise it will be executed
	   by t30_terminate, display diagnostics and set status variables although no transmittion
	   has taken place yet. */
	if (res > 0) {
		t30_set_phase_e_handler(t30state, NULL, NULL);
	}

	t30_terminate(t30state);
	fax_release(&fax);

done:
	if (original_write_fmt.id != AST_FORMAT_SLINEAR) {
		if (ast_set_write_format(s->chan, &original_write_fmt) < 0)
			ast_log(LOG_WARNING, "Unable to restore write format on '%s'\n", ast_channel_name(s->chan));
	}

	if (original_read_fmt.id != AST_FORMAT_SLINEAR) {
		if (ast_set_read_format(s->chan, &original_read_fmt) < 0)
			ast_log(LOG_WARNING, "Unable to restore read format on '%s'\n", ast_channel_name(s->chan));
	}

	return res;

}

static int transmit_t38(fax_session *s)
{
	int res = 0;
	t38_terminal_state_t t38;
	struct ast_frame *inf = NULL;
	int last_state = 0;
	struct timeval now, start, state_change, last_frame;
	t30_state_t *t30state;
	t38_core_state_t *t38state;

#if SPANDSP_RELEASE_DATE >= 20080725
	/* for spandsp shaphots 0.0.6 and higher */
	t30state = &t38.t30;
	t38state = &t38.t38_fe.t38;
#else
	/* for spandsp releases 0.0.5 */
	t30state = &t38.t30_state;
	t38state = &t38.t38;
#endif

	/* Initialize terminal */
	memset(&t38, 0, sizeof(t38));
	if (t38_terminal_init(&t38, s->caller_mode, t38_tx_packet_handler, s->chan) == NULL) {
		ast_log(LOG_WARNING, "Unable to start T.38 termination.\n");
		res = -1;
		goto disable_t38;
	}

	t38_set_max_datagram_size(t38state, s->t38parameters.max_ifp);

	if (s->t38parameters.fill_bit_removal) {
		t38_set_fill_bit_removal(t38state, TRUE);
	}
	if (s->t38parameters.transcoding_mmr) {
		t38_set_mmr_transcoding(t38state, TRUE);
	}
	if (s->t38parameters.transcoding_jbig) {
		t38_set_jbig_transcoding(t38state, TRUE);
	}

	/* Setup logging */
	set_logging(&t38.logging);
	set_logging(&t30state->logging);
	set_logging(&t38state->logging);

	/* Configure terminal */
	set_local_info(t30state, s);
	set_file(t30state, s);
	set_ecm(t30state, TRUE);

	t30_set_phase_e_handler(t30state, phase_e_handler, s);

	now = start = state_change = ast_tvnow();

	while (!s->finished) {
		inf = NULL;

		if ((res = ast_waitfor(s->chan, 25)) < 0) {
			ast_debug(1, "Error waiting for a frame\n");
			break;
		}

		last_frame = now;

		/* Watchdog */
		now = ast_tvnow();
		if (ast_tvdiff_sec(now, start) > WATCHDOG_TOTAL_TIMEOUT || ast_tvdiff_sec(now, state_change) > WATCHDOG_STATE_TIMEOUT) {
			ast_log(LOG_WARNING, "It looks like we hung. Aborting.\n");
			res = -1;
			break;
		}

		t38_terminal_send_timeout(&t38, ast_tvdiff_us(now, last_frame) / (1000000 / 8000));

		if (!res) {
			/* There was timeout waiting for a frame. Loop around and wait again */
			continue;
		}

		/* There is a frame available. Get it */
		res = 0;

		if (!(inf = ast_read(s->chan))) {
			ast_debug(1, "Channel hangup\n");
			res = -1;
			break;
		}

		ast_debug(10, "frame %d/%d, len=%d\n", inf->frametype, inf->subclass.integer, inf->datalen);

		if (inf->frametype == AST_FRAME_MODEM && inf->subclass.integer == AST_MODEM_T38) {
			t38_core_rx_ifp_packet(t38state, inf->data.ptr, inf->datalen, inf->seqno);
			if (last_state != t30state->state) {
				state_change = ast_tvnow();
				last_state = t30state->state;
			}
		} else if (inf->frametype == AST_FRAME_CONTROL && inf->subclass.integer == AST_CONTROL_T38_PARAMETERS) {
			struct ast_control_t38_parameters *parameters = inf->data.ptr;
			if (parameters->request_response == AST_T38_TERMINATED) {
				ast_debug(1, "T38 down, finishing\n");
				break;
			}
		}

		ast_frfree(inf);
		inf = NULL;
	}

	ast_debug(1, "Loop finished, res=%d\n", res);

	if (inf)
		ast_frfree(inf);

	t30_terminate(t30state);
	t38_terminal_release(&t38);

disable_t38:
	/* if we are not the caller, it's our job to shut down the T.38
	 * session when the FAX transmisson is complete.
	 */
	if ((s->caller_mode == FALSE) &&
	    (ast_channel_get_t38_state(s->chan) == T38_STATE_NEGOTIATED)) {
		struct ast_control_t38_parameters t38_parameters = { .request_response = AST_T38_REQUEST_TERMINATE, };

		if (ast_indicate_data(s->chan, AST_CONTROL_T38_PARAMETERS, &t38_parameters, sizeof(t38_parameters)) == 0) {
			/* wait up to five seconds for negotiation to complete */
			unsigned int timeout = 5000;
			int ms;

			ast_debug(1, "Shutting down T.38 on %s\n", ast_channel_name(s->chan));
			while (timeout > 0) {
				ms = ast_waitfor(s->chan, 1000);
				if (ms < 0) {
					ast_log(LOG_WARNING, "something bad happened while channel '%s' was polling.\n", ast_channel_name(s->chan));
					return -1;
				}
				if (!ms) {
					/* nothing happened */
					if (timeout > 0) {
						timeout -= 1000;
						continue;
					} else {
						ast_log(LOG_WARNING, "channel '%s' timed-out during the T.38 shutdown.\n", ast_channel_name(s->chan));
						break;
					}
				}
				if (!(inf = ast_read(s->chan))) {
					return -1;
				}
				if ((inf->frametype == AST_FRAME_CONTROL) &&
				    (inf->subclass.integer == AST_CONTROL_T38_PARAMETERS) &&
				    (inf->datalen == sizeof(t38_parameters))) {
					struct ast_control_t38_parameters *parameters = inf->data.ptr;

					switch (parameters->request_response) {
					case AST_T38_TERMINATED:
						ast_debug(1, "Shut down T.38 on %s\n", ast_channel_name(s->chan));
						break;
					case AST_T38_REFUSED:
						ast_log(LOG_WARNING, "channel '%s' refused to disable T.38\n", ast_channel_name(s->chan));
						break;
					default:
						ast_log(LOG_ERROR, "channel '%s' failed to disable T.38\n", ast_channel_name(s->chan));
						break;
					}
					ast_frfree(inf);
					break;
				}
				ast_frfree(inf);
			}
		}
	}

	return res;
}
Пример #29
0
void VideoStreamPlaybackTheora::update(float p_delta) {

	if (!file)
		return;

	if (!playing || paused) {
		//printf("not playing\n");
		return;
	};

#ifdef THEORA_USE_THREAD_STREAMING
	thread_sem->post();
#endif

	//print_line("play "+rtos(p_delta));
	time += p_delta;

	if (videobuf_time > get_time()) {
		return; //no new frames need to be produced
	}

	bool frame_done = false;
	bool audio_done = !vorbis_p;

	while (!frame_done || (!audio_done && !vorbis_eos)) {
		//a frame needs to be produced

		ogg_packet op;
		bool no_theora = false;

		while (vorbis_p) {
			int ret;
			float **pcm;

			bool buffer_full = false;

			/* if there's pending, decoded audio, grab it */
			ret = vorbis_synthesis_pcmout(&vd, &pcm);
			if (ret > 0) {

				const int AUXBUF_LEN = 4096;
				int to_read = ret;
				int16_t aux_buffer[AUXBUF_LEN];

				while (to_read) {

					int m = MIN(AUXBUF_LEN / vi.channels, to_read);

					int count = 0;

					for (int j = 0; j < m; j++) {
						for (int i = 0; i < vi.channels; i++) {

							int val = Math::fast_ftoi(pcm[i][j] * 32767.f);
							if (val > 32767) val = 32767;
							if (val < -32768) val = -32768;
							aux_buffer[count++] = val;
						}
					}

					if (mix_callback) {
						int mixed = mix_callback(mix_udata, aux_buffer, m);
						to_read -= mixed;
						if (mixed != m) { //could mix no more
							buffer_full = true;
							break;
						}
					} else {
						to_read -= m; //just pretend we sent the audio
					}
				}

				int tr = vorbis_synthesis_read(&vd, ret - to_read);

				if (vd.granulepos >= 0) {
					//print_line("wrote: "+itos(audio_frames_wrote)+" gpos: "+itos(vd.granulepos));
				}

				//print_line("mix audio!");

				audio_frames_wrote += ret - to_read;

				//print_line("AGP: "+itos(vd.granulepos)+" added "+itos(ret-to_read));

			} else {

				/* no pending audio; is there a pending packet to decode? */
				if (ogg_stream_packetout(&vo, &op) > 0) {
					if (vorbis_synthesis(&vb, &op) == 0) { /* test for success! */
						vorbis_synthesis_blockin(&vd, &vb);
					}
				} else { /* we need more data; break out to suck in another page */
					//printf("need moar data\n");
					break;
				};
			}

			audio_done = videobuf_time < (audio_frames_wrote / float(vi.rate));

			if (buffer_full)
				break;
		}

		while (theora_p && !frame_done) {
			/* theora is one in, one out... */
			if (ogg_stream_packetout(&to, &op) > 0) {

				if (false && pp_inc) {
					pp_level += pp_inc;
					th_decode_ctl(td, TH_DECCTL_SET_PPLEVEL, &pp_level,
							sizeof(pp_level));
					pp_inc = 0;
				}
				/*HACK: This should be set after a seek or a gap, but we might not have
				a granulepos for the first packet (we only have them for the last
				packet on a page), so we just set it as often as we get it.
				To do this right, we should back-track from the last packet on the
				page and compute the correct granulepos for the first packet after
				a seek or a gap.*/
				if (op.granulepos >= 0) {
					th_decode_ctl(td, TH_DECCTL_SET_GRANPOS, &op.granulepos,
							sizeof(op.granulepos));
				}
				ogg_int64_t videobuf_granulepos;
				if (th_decode_packetin(td, &op, &videobuf_granulepos) == 0) {
					videobuf_time = th_granule_time(td, videobuf_granulepos);

					//printf("frame time %f, play time %f, ready %i\n", (float)videobuf_time, get_time(), videobuf_ready);

					/* is it already too old to be useful?  This is only actually
					 useful cosmetically after a SIGSTOP.  Note that we have to
					 decode the frame even if we don't show it (for now) due to
					 keyframing.  Soon enough libtheora will be able to deal
					 with non-keyframe seeks.  */

					if (videobuf_time >= get_time()) {
						frame_done = true;
					} else {
						/*If we are too slow, reduce the pp level.*/
						pp_inc = pp_level > 0 ? -1 : 0;
					}
				} else {
				}

			} else {
				no_theora = true;
				break;
			}
		}

#ifdef THEORA_USE_THREAD_STREAMING
		if (file && thread_eof && no_theora && theora_eos && ring_buffer.data_left() == 0) {
#else
		if (file && /*!videobuf_ready && */ no_theora && theora_eos) {
#endif
			printf("video done, stopping\n");
			stop();
			return;
		};

		if (!frame_done || !audio_done) {
			//what's the point of waiting for audio to grab a page?

			buffer_data();
			while (ogg_sync_pageout(&oy, &og) > 0) {
				queue_page(&og);
			}
		}

		/* If playback has begun, top audio buffer off immediately. */
		//if(stateflag) audio_write_nonblocking();

		/* are we at or past time for this video frame? */
		if (videobuf_ready && videobuf_time <= get_time()) {

			//video_write();
			//videobuf_ready=0;
		} else {
			//printf("frame at %f not ready (time %f), ready %i\n", (float)videobuf_time, get_time(), videobuf_ready);
		}

		float tdiff = videobuf_time - get_time();
		/*If we have lots of extra time, increase the post-processing level.*/
		if (tdiff > ti.fps_denominator * 0.25 / ti.fps_numerator) {
			pp_inc = pp_level < pp_level_max ? 1 : 0;
		} else if (tdiff < ti.fps_denominator * 0.05 / ti.fps_numerator) {
			pp_inc = pp_level > 0 ? -1 : 0;
		}
	}

	video_write();
};

void VideoStreamPlaybackTheora::play() {

	if (!playing)
		time = 0;
	else {
		stop();
	}

	playing = true;
	delay_compensation = ProjectSettings::get_singleton()->get("audio/video_delay_compensation_ms");
	delay_compensation /= 1000.0;
};

void VideoStreamPlaybackTheora::stop() {

	if (playing) {

		clear();
		set_file(file_name); //reset
	}
	playing = false;
	time = 0;
};

bool VideoStreamPlaybackTheora::is_playing() const {

	return playing;
};

void VideoStreamPlaybackTheora::set_paused(bool p_paused) {

	paused = p_paused;
	//pau = !p_paused;
};

bool VideoStreamPlaybackTheora::is_paused(bool p_paused) const {

	return paused;
};

void VideoStreamPlaybackTheora::set_loop(bool p_enable){

};

bool VideoStreamPlaybackTheora::has_loop() const {

	return false;
};

float VideoStreamPlaybackTheora::get_length() const {

	return 0;
};

String VideoStreamPlaybackTheora::get_stream_name() const {

	return "";
};

int VideoStreamPlaybackTheora::get_loop_count() const {

	return 0;
};

float VideoStreamPlaybackTheora::get_playback_position() const {

	return get_time();
};

void VideoStreamPlaybackTheora::seek(float p_time){

	// no
};

void VideoStreamPlaybackTheora::set_mix_callback(AudioMixCallback p_callback, void *p_userdata) {

	mix_callback = p_callback;
	mix_udata = p_userdata;
}
Пример #30
0
void mailprivacy_smime_set_cert_dir(struct mailprivacy * privacy,
    char * directory)
{
  DIR * dir;
  struct dirent * ent;

  chash_clear(certificates);
  
  if (directory == NULL)
    return;
  
  if (* directory == '\0')
    return;

  strncpy(cert_dir, directory, sizeof(cert_dir));
  cert_dir[sizeof(cert_dir) - 1] = '\0';
  
  dir = opendir(directory);
  if (dir == NULL)
    return;
  
  while ((ent = readdir(dir)) != NULL) {
#if 0
    char quoted_filename[PATH_MAX];
    char filename[PATH_MAX];
    char command[PATH_MAX];
    char buf[MAX_EMAIL_SIZE];
    FILE * p;
    int r;
    
    snprintf(filename, sizeof(filename),
        "%s/%s", directory, ent->d_name);
    
    r = mail_quote_filename(quoted_filename, sizeof(quoted_filename), filename);
    
    snprintf(command, sizeof(command),
        "openssl x509 -email -noout -in '%s' 2>/dev/null", quoted_filename);
    
    p = popen(command, "r");
    if (p == NULL)
      continue;
    
    while (fgets(buf, sizeof(buf), p) != NULL)
      set_file(certificates, buf, filename);
    
    pclose(p);
#endif
    char filename[PATH_MAX];
    char email[PATH_MAX];
    char * p;
    
    snprintf(filename, sizeof(filename),
        "%s/%s", directory, ent->d_name);
    
    strncpy(email, ent->d_name, sizeof(email));
    email[sizeof(email) - 1] = '\0';
    
    p = strstr(email, CERTIFICATE_SUFFIX);
    if (p == NULL)
      continue;
    
    if (strlen(p) != sizeof(CERTIFICATE_SUFFIX) - 1)
      continue;
    
    * p = 0;
    
    if (* email == '\0')
      continue;
    
    set_file(certificates, email, filename);
  }
  closedir(dir);
}