Beispiel #1
0
struct json_object* json_object_from_file(const char *filename)
{
    struct printbuf *pb;
    struct json_object *obj;
    char buf[JSON_FILE_BUF_SIZE];
    int fd, ret;

    if((fd = open(filename, O_RDONLY)) < 0) {
        MC_ERROR("json_object_from_file: error reading file %s: %s\n",
                 filename, strerror(errno));
        return (struct json_object*)error_ptr(-1);
    }
    if(!(pb = printbuf_new())) {
        MC_ERROR("json_object_from_file: printbuf_new failed\n");
        return (struct json_object*)error_ptr(-1);
    }
    while((ret = read(fd, buf, JSON_FILE_BUF_SIZE)) > 0) {
        printbuf_memappend(pb, buf, ret);
    }
    close(fd);
    if(ret < 0) {
        MC_ABORT("json_object_from_file: error reading file %s: %s\n",
                 filename, strerror(errno));
        printbuf_free(pb);
        return (struct json_object*)error_ptr(-1);
    }
    obj = json_tokener_parse(pb->buf);
    printbuf_free(pb);
    return obj;
}
Beispiel #2
0
struct mtev_json_object* mtev_json_object_from_file(char *filename)
{
  struct mtev_json_object *obj;
  int fd;

  if((fd = open(filename, O_RDONLY)) < 0) {
    MC_ERROR("mtev_json_object_from_file: error reading file %s: %s\n",
	     filename, strerror(errno));
    return (struct mtev_json_object*)error_ptr(-1);
  }
  obj = mtev_json_object_from_fd(fd);
  close(fd);
  return obj;
}
json_object * GetJsonObject(CPLString pszFilename) 
{
    json_object * pJSONObject = NULL;
    CPLString osJSONFilename = GetJsonFilename(pszFilename);

    pJSONObject = json_object_from_file((char *)osJSONFilename.c_str());
    if (pJSONObject == (struct json_object*)error_ptr(-1) || pJSONObject == NULL) {
        CPLDebug("ARGDataset", "GetJsonObject(): "
            "Could not parse JSON file.");
        return NULL;
    }

    return pJSONObject;
}
Beispiel #4
0
struct mtev_json_object *mtev_json_object_from_fd(int fd)
{
  struct jl_printbuf *pb;
  struct mtev_json_object *obj;
  char buf[JSON_FILE_BUF_SIZE];
  int ret;

  if(!(pb = jl_printbuf_new())) {
    MC_ERROR("mtev_json_object_from_fd: jl_printbuf_new failed%s\n", "");
    return (struct mtev_json_object*)error_ptr(-1);
  }
  while((ret = read(fd, buf, JSON_FILE_BUF_SIZE)) > 0) {
    jl_printbuf_memappend(pb, buf, ret);
  }
  if(ret < 0) {
    MC_ABORT("mtev_json_object_from_fd: error reading fd %d: %s\n",
	     fd, strerror(errno));
    jl_printbuf_free(pb);
    return (struct mtev_json_object*)error_ptr(-1);
  }
  obj = mtev_json_tokener_parse(pb->buf);
  jl_printbuf_free(pb);
  return obj;
}
Beispiel #5
0
json_object *pam_multipass_read_hashes(const char *user)
{
    static const char *hashes_filename = "/.multipass/hashes.json";
    json_object *hashes = NULL;

    int home_len = 0;
    struct passwd *pw = getpwnam(user);
    if (pw != NULL && pw->pw_dir != NULL) {
	home_len = strlen(pw->pw_dir);
    }

    if (home_len == 0) {
	/* fprintf(stderr, "pam_multipass: user has no home directory:
	   %s\n", user); */
	return NULL;
    }

    char *hashes_file = malloc(home_len + strlen(hashes_filename) + 1);
    if (hashes_file == NULL) return NULL;

    memcpy(hashes_file, pw->pw_dir, home_len);
    memcpy(hashes_file + home_len, hashes_filename, strlen(hashes_filename) + 1);

    hashes = json_object_from_file((char *)hashes_file);

    if (hashes == NULL) {
	fprintf(stderr, "pam_multipass: error parsing %s\n", hashes_file);
	goto out;
    }

    if (hashes == error_ptr(-1)) { /* unable to read */
	hashes = NULL;
	goto out;
    }

    if (!json_object_is_type(hashes, json_type_object)) {
	fprintf(stderr, "pam_multipass: %s must be a JSON object like \"{}\"\n", hashes_file);
	hashes = NULL;
	goto out;
    }

 out:
    free(hashes_file);
    return hashes;
}
Beispiel #6
0
t_instruction	*instruction_new(char *data, int data_len)
{
  t_instruction	*instruction;
  int		i;

  if (data == NULL)
    return (NULL);
  if ((instruction = xmalloc(sizeof(t_instruction))) == NULL)
    return (error_ptr(NULL, ERR_MALLOC));
  instruction->data = data;
  instruction->data_len = data_len;
  instruction->argc = ARGC_UNDEF;
  i = 0;
  while (i < ARGC_UNDEF)
    {
      instruction->argv[i] = 0;
      i++;
    }
  return (instruction);
}
Beispiel #7
0
 constexpr no_trivial_result_base(no_trivial_result_base&& rhs) noexcept(std::is_nothrow_move_constructible<E>::value) : has_value(rhs.has_value), storage()
 {
     if ( ! rhs.has_value ) { ::new(error_ptr()) E(rhs.storage.error); }
 }
Beispiel #8
0
 constexpr trivial_result_base(trivial_result_base&& rhs) noexcept(std::is_nothrow_move_constructible<T>::value) : has_value(rhs.has_value), storage()
 {
     if ( rhs.has_value ) { ::new(value_ptr()) T(rhs.storage.value); }
     else                 { ::new(error_ptr()) T(rhs.storage.error); }
 }