Example #1
0
int
file_perms_parse_mode(const unsigned char *mode)
{
  char *eptr = 0;
  int m = 0;

  if (!mode) return -1;
  if (is_empty_string(mode)) return -1;
  m = strtol(mode, &eptr, 8);
  if (!is_empty_string(eptr)) return -1;
  m &= 07777;
  return m;
}
const char* Material::get_non_empty(const ParamArray& params, const char* name) const
{
    if (!params.strings().exist(name))
        return 0;

    const char* value = params.strings().get(name);

    return is_empty_string(value) ? 0 : value;
}
Example #3
0
//remove da lista strings vazias
void trim_string_list(StringList *list, char element){
    String tmp;
    while((tmp = list_next(list))){
        if(is_empty_string(tmp)){
            list_remove(list, --list->index);
        }
    }
    reset_index(list);
}
Example #4
0
int
file_perms_parse_group(const unsigned char *group)
{
  struct group *g = 0;

  if (!group) return -1;
  if (is_empty_string(group)) return -1;
  if (!(g = getgrnam(group))) return -1;
  return g->gr_gid;
}
Example #5
0
bool f_hash_update_file(CObjRef init_context, CStrRef filename,
                        CObjRef stream_context /* = null */) {
  Variant f = f_fopen(filename, "rb");
  if (same(f, false)) {
    return false;
  }

  HashContext *hash = init_context.getTyped<HashContext>();
  for (Variant chunk = f_fread(f, 1024); !is_empty_string(chunk);
       chunk = f_fread(f, 1024)) {
    String schunk = chunk.toString();
    hash->ops->hash_update(hash->context, (unsigned char *)schunk.data(),
                           schunk.size());
  }
  return true;
}
void save_cb(GtkButton* button, gpointer user_data)
{
    /* Load save dialog */
    int response = gtk_dialog_run(GTK_DIALOG(save_dialog));
    if(response != 0) {
        gtk_widget_hide(GTK_WIDGET(save_dialog));
        return;
    }

    /* Get filename */
    char* filename;
    filename = gtk_file_chooser_get_filename(save_dialog);

    /* Check is not empty */
    DEBUG("Selected file: %s\n", filename);
    if((filename == NULL) || is_empty_string(filename)) {
        show_error(window, "Please select a file.");
        g_free(filename);
        save_cb(button, user_data);
        return;
    }
    gtk_widget_hide(GTK_WIDGET(save_dialog));

    /* Check extension */
    if(!g_str_has_suffix(filename, ".bip")) {
        char* new_filename = g_strdup_printf("%s.bip", filename);
        g_free(filename);
        filename = new_filename;
    }

    /* Try to open file for writing */
    FILE* file = fopen(filename, "w");
    if(file == NULL) {
        show_error(window, "An error ocurred while trying to open "
                           "the file. Check you have permissions.");
        g_free(filename);
        return;
    }

    /* Save current context */
    DEBUG("Saving to file %s\n", filename);
    save(file);

    /* Free resources */
    fclose(file);
    g_free(filename);
}
Example #7
0
int64_t f_hash_update_stream(CObjRef context, CObjRef handle,
                         int length /* = -1 */) {
  HashContext *hash = context.getTyped<HashContext>();
  int didread = 0;
  while (length) {
    Variant chunk = f_fread(handle, length > 0 ? length : 1024);
    if (is_empty_string(chunk)) {
      return didread;
    }
    String schunk = chunk.toString();
    hash->ops->hash_update(hash->context, (unsigned char *)schunk.data(),
                           schunk.size());
    didread += schunk.size();
    length -= schunk.size();
  }
  return didread;
}
Example #8
0
static Variant php_hash_do_hash_hmac(CStrRef algo, CStrRef data,
                                     bool isfilename, CStrRef key,
                                     bool raw_output /* = false */) {
  HashEnginePtr ops = php_hash_fetch_ops(algo);
  if (!ops) {
    raise_warning("Unknown hashing algorithm: %s", algo.data());
    return false;
  }
  Variant f;
  if (isfilename) {
    f = f_fopen(data, "rb");
    if (same(f, false)) {
      return false;
    }
  }

  void *context = malloc(ops->context_size);
  ops->hash_init(context);

  char *K = prepare_hmac_key(ops, context, key);

  if (isfilename) {
    for (Variant chunk = f_fread(f, 1024); !is_empty_string(chunk);
         chunk = f_fread(f, 1024)) {
      String schunk = chunk.toString();
      ops->hash_update(context, (unsigned char *)schunk.data(), schunk.size());
    }
  } else {
    ops->hash_update(context, (unsigned char *)data.data(), data.size());
  }

  String raw = String(ops->digest_size, ReserveString);
  char *digest = raw.mutableSlice().ptr;
  ops->hash_final((unsigned char *)digest, context);
  finalize_hmac_key(K, ops, context, digest);
  free(context);

  raw.setSize(ops->digest_size);
  if (raw_output) {
    return raw;
  }
  return StringUtil::HexEncode(raw);
}
void load_cb(GtkButton* button, gpointer user_data)
{
    /* Load load dialog */
    int response = gtk_dialog_run(GTK_DIALOG(load_dialog));
    if(response != 0) {
        gtk_widget_hide(GTK_WIDGET(load_dialog));
        return;
    }

    /* Get filename */
    char* filename;
    filename = gtk_file_chooser_get_filename(load_dialog);

    /* Check is not empty */
    DEBUG("Selected file: %s\n", filename);
    if((filename == NULL) || is_empty_string(filename)) {
        show_error(window, "Please select a file.");
        g_free(filename);
        load_cb(button, user_data);
        return;
    }
    gtk_widget_hide(GTK_WIDGET(load_dialog));

    /* Try to open file for reading */
    if(!file_exists(filename)) {
        show_error(window, "The selected file doesn't exists.");
        return;
    }
    FILE* file = fopen(filename, "r");
    if(file == NULL) {
        show_error(window, "An error ocurred while trying to open "
                           "the file. Check you have permissions.");
        return;
    }

    /* Load file */
    DEBUG("Loading file %s\n", filename);
    load(file);

    /* Free resources */
    fclose(file);
    g_free(filename);
}
Example #10
0
static Variant php_hash_do_hash(const String& algo, const String& data,
                                bool isfilename,
                                bool raw_output) {
  HashEnginePtr ops = php_hash_fetch_ops(algo);
  if (!ops) {
    raise_warning("Unknown hashing algorithm: %s", algo.data());
    return false;
  }
  Variant f;
  if (isfilename) {
    f = HHVM_FN(fopen)(data, "rb");
    if (same(f, false)) {
      return false;
    }
  }

  void *context = malloc(ops->context_size);
  ops->hash_init(context);

  if (isfilename) {
    for (Variant chunk = HHVM_FN(fread)(f.toResource(), 1024);
         !is_empty_string(chunk);
         chunk = HHVM_FN(fread)(f.toResource(), 1024)) {
      String schunk = chunk.toString();
      ops->hash_update(context, (unsigned char *)schunk.data(), schunk.size());
    }
  } else {
    ops->hash_update(context, (unsigned char *)data.data(), data.size());
  }

  String raw = String(ops->digest_size, ReserveString);
  char *digest = raw.mutableData();
  ops->hash_final((unsigned char *)digest, context);
  free(context);

  raw.setSize(ops->digest_size);
  if (raw_output) {
    return raw;
  }
  return HHVM_FN(bin2hex)(raw);
}
void writeback(GtkTreeModel* model, gchar* path, int vars, bool is_var,
                    gchar* new_text, gpointer user_data)
{
    int column = GPOINTER_TO_INT(user_data);
    DEBUG("%s at (%i, %i)\n", new_text, atoi(path), column);

    /* Get the coefficient */
    int coeff = 0;
    if(!is_empty_string(new_text)) {
        char* end;
        coeff = (int) strtol(new_text, &end, 10);
        if(*end != '\0') { /* Conversion wasn't successful */
            DEBUG("Unable to parse %s\n", new_text);
            return;
        }
    }

    /* Get reference to model */
    GtkTreeIter iter;
    gtk_tree_model_get_iter_from_string(model, &iter, path);

    /* Set the model */
    GValue gvali = G_VALUE_INIT;
    g_value_init(&gvali, G_TYPE_INT);

    GValue gvals = G_VALUE_INIT;
    g_value_init(&gvals, G_TYPE_STRING);

    /* Coeff */
    g_value_set_int(&gvali, coeff);
    gtk_list_store_set_value(
        GTK_LIST_STORE(model), &iter, column, &gvali);
    g_value_unset(&gvali);

    /* Text */
    g_value_set_string(&gvals, "");
    if(!is_var) {
        char* text = num_name(coeff, true);
        g_value_set_string(&gvals, text);
        free(text);
    } else if(coeff != 0) {
        char* text = var_name(coeff, column, column == 0);
        g_value_set_string(&gvals, text);
        free(text);
    }
    gtk_list_store_set_value(
        GTK_LIST_STORE(model), &iter, vars + column, &gvals);

    /* Sign */
    g_value_set_string(&gvals, "");
    if(is_var) {
        if((column != 0)  && (coeff != 0)) {
            if(coeff > 0) {
                g_value_set_string(&gvals, PLUS);
            } else {
                g_value_set_string(&gvals, MINUS);
            }
        }
    }
    gtk_list_store_set_value(
        GTK_LIST_STORE(model), &iter, 2 * vars + column, &gvals);
    g_value_unset(&gvals);
}
Example #12
0
int
main (int argc, char **argv)
{
  int index;
  int rc;
  mu_stream_t in, tmp;
  mu_message_t msg;
  mu_header_t hdr;
  mu_iterator_t itr;
  const char *file;
  char *newval;
  mu_off_t size;
  mu_body_t body;
  mu_stream_t bstr;
  
  MU_APP_INIT_NLS ();
  
  mh_argp_init ();
  mh_argp_parse (&argc, &argv, 0, options, mh_option, args_doc, doc,
		 opt_handler, NULL, &index);

  if (index == argc)
    {
      mu_error (_("file name not given"));
      exit (1);
    }
  file = argv[index];

  prompter_init ();
  if (erase_seq)
    prompter_set_erase (erase_seq);
  if (kill_seq)
    prompter_set_erase (kill_seq);

  if ((rc = mu_stdio_stream_create (&strout, MU_STDOUT_FD, MU_STREAM_WRITE)))
    {
      mu_error (_("cannot open stdout: %s"), mu_strerror (rc));
      return 1;
    }
  
  if ((rc = mu_file_stream_create (&in, file, MU_STREAM_RDWR)))
    {
      mu_error (_("cannot open input file `%s': %s"),
		file, mu_strerror (rc));
      return 1;
    }
  rc = mu_stream_to_message (in, &msg);
  mu_stream_unref (in);
  if (rc)
    {
      mu_error (_("input stream %s is not a message (%s)"),
		file, mu_strerror (rc));
      return 1;
    }
  
  if ((rc = mu_temp_file_stream_create (&tmp, NULL, 0))) 
    {
      mu_error (_("Cannot open temporary file: %s"),
		mu_strerror (rc));
      return 1;
    }

  /* Copy headers */
  mu_message_get_header (msg, &hdr);
  mu_header_get_iterator (hdr, &itr);
  for (mu_iterator_first (itr); !mu_iterator_is_done (itr);
       mu_iterator_next (itr))
    {
      const char *name, *val;
      
      mu_iterator_current_kv (itr, (const void **)&name, (void**)&val);
      if (!is_empty_string (val))
	{
	  mu_stream_printf (tmp, "%s: %s\n", name, val);
	  mu_stream_printf (strout, "%s: %s\n", name, val);
	}
      else
	{
	  int cont = 0;
	  mu_opool_t opool;
	  const char *prompt = name;
	  
	  mu_opool_create (&opool, 1);
	  do
	    {
	      size_t len;
	      char *p;
	      p = prompter_get_value (prompt);
	      if (!p)
		return 1;
	      prompt = NULL;
	      if (cont)
		{
		  mu_opool_append_char (opool, '\n');
		  if (!mu_isspace (p[0]))
		    mu_opool_append_char (opool, '\t');
		}
	      len = strlen (p);
	      if (len > 0 && p[len-1] == '\\')
		{
		  len--;
		  cont = 1;
		}
	      else
		cont = 0;
	      mu_opool_append (opool, p, len);
	      free (p);
	    }
	  while (cont);

	  mu_opool_append_char (opool, 0);
	  newval = mu_opool_finish (opool, NULL);
	  if (!is_empty_string (newval))
	    mu_stream_printf (tmp, "%s: %s\n", name, newval);
	  mu_opool_destroy (&opool);
	}
    }
  mu_iterator_destroy (&itr);
  mu_stream_printf (strout, "--------\n");
  mu_stream_write (tmp, "\n", 1, NULL);

  /* Copy body */
  
  if (prepend_option)
    {
      mu_stream_printf (strout, "\n--------%s\n\n", _("Enter initial text"));
      while ((newval = prompter_get_line ()))
	{
	  mu_stream_write (tmp, newval, strlen (newval), NULL);
	  free (newval);
	  mu_stream_write (tmp, "\n", 1, NULL);
	}
    }

  mu_message_get_body (msg, &body);
  mu_body_get_streamref (body, &bstr);

  if (!prepend_option && !rapid_option)
    {
      mu_stream_copy (strout, bstr, 0, NULL);
      mu_stream_seek (bstr, 0, MU_SEEK_SET, NULL);
    }

  mu_stream_copy (tmp, bstr, 0, NULL);
  mu_stream_unref (bstr);

  if (!prepend_option && !rapid_option)
    {
      printf ("\n--------%s\n\n", _("Enter additional text"));
      while ((newval = prompter_get_line ()))
	{
	  mu_stream_write (tmp, newval, strlen (newval), NULL);
	  free (newval);
	  mu_stream_write (tmp, "\n", 1, NULL);
	}
    }

  /* Destroy the message */
  mu_message_destroy (&msg, mu_message_get_owner (msg));

  /* Rewind the streams and copy data back to in. */
  mu_stream_seek (in, 0, MU_SEEK_SET, NULL);
  mu_stream_seek (tmp, 0, MU_SEEK_SET, NULL);
  mu_stream_copy (in, tmp, 0, &size);
  mu_stream_truncate (in, size);

  mu_stream_destroy (&in);
  mu_stream_destroy (&tmp);
  mu_stream_destroy (&strout);

  prompter_done ();
  
  return 0;
}
bool Application::is_correctly_installed()
{
    return !is_empty_string(get_root_path());
}