Beispiel #1
0
void copy_properties(ListBase *lbn, ListBase *lbo)
{
	bProperty *prop, *propn;
	free_properties(lbn); /* in case we are copying to an object with props */
	prop = lbo->first;
	while (prop) {
		propn = copy_property(prop);
		BLI_addtail(lbn, propn);
		prop = prop->next;
	}
	
	
}
Beispiel #2
0
static int delete_pkgdb(struct pkgdb *db) {
  struct pkg *pkg = db->head;
  while (pkg) {
    struct pkg *next = pkg->next;
    free(pkg->name);
    free(pkg->inffile);
    free(pkg->description);
    free_properties(pkg->manifest);
    free(pkg);
    pkg = next;
  }
  db->head = db->tail = NULL;
  return 0;
}
Beispiel #3
0
static void free_classes(lily_symtab *symtab, lily_class *class_iter)
{
    while (class_iter) {
        lily_free(class_iter->name);

        if (class_iter->flags & CLS_IS_VARIANT) {
            lily_class *class_next = class_iter->next;
            lily_free(class_iter);
            class_iter = class_next;
            continue;
        }

        if (class_iter->properties != NULL)
            free_properties(symtab, class_iter);

        if (class_iter->call_chain != NULL)
            free_vars(symtab, class_iter->call_chain);

        lily_type *type_iter = class_iter->all_subtypes;
        lily_type *type_next;
        while (type_iter) {
            type_next = type_iter->next;
            lily_free(type_iter->subtypes);
            lily_free(type_iter);
            type_iter = type_next;
        }

        if (class_iter->flags & CLS_ENUM_IS_SCOPED) {
            /* Scoped enums pull their variants from the symtab's class chain so
               that parser won't find them. */
            int i;
            for (i = 0;i < class_iter->variant_size;i++) {
                lily_free(class_iter->variant_members[i]->name);
                lily_free(class_iter->variant_members[i]);
            }
        }

        lily_free(class_iter->variant_members);

        lily_class *class_next = class_iter->next;
        lily_free(class_iter);
        class_iter = class_next;
    }
}
Beispiel #4
0
static int install_package(char *pkgname, struct pkgdb *db, int options) {
  char url[STRLEN];
  FILE *f;
  int rc;
  char inffile[STRLEN];
  struct section *manifest;
  struct section *dep;
  struct section *build;
  struct pkg *pkg;
  char *description;
  int time;

  // Check if package is already installed
  if (!(options & FROM_FILE)) {
    pkg = find_package(db, pkgname);
    if (pkg) {
      if (options & UPGRADE) {
        if (pkg->time == pkg->avail) return 0;
      } else if (options & DEPENDENCY) {
        return 0;
      } else if (options & UPDATE) {
        if (options & VERBOSE) printf("updating package %s\n", pkgname);
      } else {
        printf("package %s is already installed\n", pkgname);
        return 0;
      }
    }
  }

  // Open package file
  printf("Fetching %s\n", pkgname);
  if (options & FROM_FILE) {
    snprintf(url, sizeof(url), "file:///%s", pkgname);
  } else {
    snprintf(url, sizeof(url), "%s/%s.pkg", db->repo, pkgname);
  }
  if (options & VERBOSE) printf("fetching package %s from %s\n", pkgname, url);
  f = open_url(url, "pkg");
  if (!f) return 1;

  // Extract file from package file
  time = 0;
  rc = extract_files(url, f, inffile, options & VERBOSE, &time);
  fclose(f);
  if (rc != 0) return rc;

  // Read manifest
  if (options & VERBOSE) printf("reading manifest from %s\n", inffile);
  manifest = read_properties(inffile);
  if (!manifest) {
    fprintf(stderr, "%s: unable to read manifest\n", inffile);
    return 1;
  }

  // Add package to package database
  pkgname = get_property(manifest, "package", "name", pkgname);
  description = get_property(manifest, "package", "description", NULL);
  pkg = find_package(db, pkgname);
  if (pkg) {
    if (options & VERBOSE) printf("updating package %s in database\n", pkgname);
    if (description) {
      free(pkg->description);
      pkg->description = strdup(description);
      db->dirty = 1;
    }
    if (pkg->manifest) free_properties(pkg->manifest);
    free(pkg->inffile);
  } else {
    if (options & VERBOSE) printf("adding package %s to database\n", pkgname);
    pkg = add_package(db, pkgname, description);
  }
  pkg->inffile = strdup(inffile);
  pkg->manifest = manifest;
  if (time != pkg->time) {
    pkg->time = time;
    db->dirty = 1;
  }

  // Install package dependencies
  dep = find_section(manifest, "dependencies");
  if (dep) {
    struct property *p;
    for (p = dep->properties; p; p = p->next) {
      if (options & VERBOSE) printf("package %s depends on %s\n", pkgname, p->name);
      rc = install_package(p->name, db, options | DEPENDENCY);
      if (rc != 0) return rc;
    }
  }
  if ((options & ONLY_FETCH) && !(options & DEPENDENCY)) return 0;

  // Run package build/installation commands
  if (!(options & ONLY_FETCH) || (options & DEPENDENCY)) {
    build = find_section(manifest, (options & ONLY_BUILD) && !(options & DEPENDENCY) ? "build" : "install");
    if (build) {
      struct property *p;
      printf((options & ONLY_BUILD) && !(options & DEPENDENCY) ? "Building %s\n" : "Installing %s\n", pkgname);
      for (p = build->properties; p; p = p->next) {
        if (options & VERBOSE) printf("%s\n", p->name);
        rc = system(p->name);
        if (rc != 0) {
          fprintf(stderr, "%s: build failed\n", pkgname);
          return rc;
        }
      }
    }
  }

  return 0;
}
lzma_block_header_decode(lzma_block *block,
		lzma_allocator *allocator, const uint8_t *in)
{
	const size_t filter_count = (in[1] & 3) + 1;
	size_t in_size;
	size_t i;

	// Start after the Block Header Size and Block Flags fields.
	size_t in_pos = 2;

	// NOTE: We consider the header to be corrupt not only when the
	// CRC32 doesn't match, but also when variable-length integers
	// are invalid or over 63 bits, or if the header is too small
	// to contain the claimed information.

	// Initialize the filter options array. This way the caller can
	// safely free() the options even if an error occurs in this function.
	for (i = 0; i <= LZMA_FILTERS_MAX; ++i) {
		block->filters[i].id = LZMA_VLI_UNKNOWN;
		block->filters[i].options = NULL;
	}

	// Always zero for now.
	block->version = 0;

	// Validate Block Header Size and Check type. The caller must have
	// already set these, so it is a programming error if this test fails.
	if (lzma_block_header_size_decode(in[0]) != block->header_size
			|| (unsigned int)(block->check) > LZMA_CHECK_ID_MAX)
		return LZMA_PROG_ERROR;

	// Exclude the CRC32 field.
	in_size = block->header_size - 4;

	// Verify CRC32
	if (lzma_crc32(in, in_size, 0) != unaligned_read32le(in + in_size))
		return LZMA_DATA_ERROR;

	// Check for unsupported flags.
	if (in[1] & 0x3C)
		return LZMA_OPTIONS_ERROR;

	// Compressed Size
	if (in[1] & 0x40) {
		return_if_error(lzma_vli_decode(&block->compressed_size,
				NULL, in, &in_pos, in_size));

		// Validate Compressed Size. This checks that it isn't zero
		// and that the total size of the Block is a valid VLI.
		if (lzma_block_unpadded_size(block) == 0)
			return LZMA_DATA_ERROR;
	} else {
		block->compressed_size = LZMA_VLI_UNKNOWN;
	}

	// Uncompressed Size
	if (in[1] & 0x80)
		return_if_error(lzma_vli_decode(&block->uncompressed_size,
				NULL, in, &in_pos, in_size));
	else
		block->uncompressed_size = LZMA_VLI_UNKNOWN;

	// Filter Flags
	for (i = 0; i < filter_count; ++i) {
		const lzma_ret ret = lzma_filter_flags_decode(
				&block->filters[i], allocator,
				in, &in_pos, in_size);
		if (ret != LZMA_OK) {
			free_properties(block, allocator);
			return ret;
		}
	}

	// Padding
	while (in_pos < in_size) {
		if (in[in_pos++] != 0x00) {
			free_properties(block, allocator);

			// Possibly some new field present so use
			// LZMA_OPTIONS_ERROR instead of LZMA_DATA_ERROR.
			return LZMA_OPTIONS_ERROR;
		}
	}

	return LZMA_OK;
}
Beispiel #6
0
int add_udi(LibHalContext *hal_ctx, char *arg)
{
	DBusError error;
	dbus_bool_t dev_exists = FALSE;
	char *udi = NULL, buf[1024];
	lh_prop_t *prop;
	int err;

	if (!arg)
		return 21;

	if (*arg == '/') {
		udi = arg;
	} else {
#ifdef HAVE_ASPRINTF
		asprintf(&udi, "/org/freedesktop/Hal/devices/%s", arg);
#else
		udi = calloc(1, sizeof ("/org/freedesktop/Hal/devices/%s") + strlen(arg));
		sprintf(udi, "/org/freedesktop/Hal/devices/%s", arg);
#endif
	}

	if (udi)
		new_dev.udi = strdup(udi);

	dbus_error_init(&error);

	if (udi)
		dev_exists = libhal_device_exists(hal_ctx, udi, &error);

	if (dev_exists) {
		new_dev.real_udi = strdup(new_dev.udi);
	} else {
		new_dev.real_udi = libhal_new_device(hal_ctx, &error);

		if (!new_dev.real_udi) {
			fprintf(stderr, "%s: %s\n", error.name, error.message);
			LIBHAL_FREE_DBUS_ERROR (&error);
			free(new_dev.real_udi);

			return 22;
		}

		printf("tmp udi: %s\n", new_dev.real_udi);
	}

	prop = NULL;

	while (fgets(buf, sizeof buf, stdin)) {
		process_property(hal_ctx, buf, &prop);
	}

	err = add_properties(hal_ctx, &new_dev, prop);

	prop = free_properties(prop);

	if (!dev_exists) {
		if (!libhal_device_commit_to_gdl(hal_ctx, new_dev.real_udi, new_dev.udi, &error)) {
			fprintf(stderr, "%s: %s\n", error.name, error.message);
			LIBHAL_FREE_DBUS_ERROR (&error);
			free(new_dev.real_udi);

			err = err ? err : 23;
		}
	}

	printf("%s: %s\n", dev_exists ? "merged": "created", new_dev.udi);

	return err;
}
Beispiel #7
0
static jboolean process_audio (GstElement *source, JNIEnv *env, jobject header)
{
  /* will contain the properties we need to put into the given GstHeader */
  AudioProperties *properties = NULL;
  
  /* GStreamer elements */
  GstElement *pipeline = NULL;
  GstElement *decoder = NULL;
  
  GstElement *typefind = NULL;
  
  GstStateChangeReturn res;

  jboolean result = JNI_FALSE;
  
  properties = (AudioProperties *) g_malloc0 (sizeof (AudioProperties));
  if (properties == NULL)
    {
      return result;
    }
  reset_properties(properties);

  /* 
   * create the decoder element, this will decode the stream and retrieve
   * its properties.
   * We connect a signal to this element, to be informed when it is done
   * in decoding the stream and to get the needed informations about the
   * audio file.
   */
  decoder = gst_element_factory_make ("decodebin", "decoder");
  if (decoder == NULL)
    {
      free_properties(properties);
      return result;
    }
  
  /* now, we create a pipeline and fill it with the other elements */
  pipeline = gst_pipeline_new ("pipeline");
  if (pipeline == NULL)
    {
      gst_object_unref (GST_OBJECT (decoder));
      free_properties(properties);   
      return result;
    }
 
  g_signal_connect (decoder, "new-decoded-pad", G_CALLBACK (new_decoded_pad),
                    pipeline);
  g_signal_connect (G_OBJECT (decoder), "element-added",
                    G_CALLBACK (element_added), properties);
  
  /*
   * we get the typefind from the decodebin to catch the additional properties
   * that the decodebin does not expose to us
   */
  typefind = gst_bin_get_by_name (GST_BIN (decoder), "typefind");
  if (typefind != NULL)
    {
      /* 
       * NOTE: the above is not a typo, we can live without the typefind,
       * just, our stream detection will not be as accurate as we would.
       * Anyway, if this fails, there is some problem, probabily a memory
       * error.
       */
       g_signal_connect (G_OBJECT (typefind), "have-type",
                         G_CALLBACK (typefind_callback), properties);
    }
  
  gst_bin_add_many (GST_BIN (pipeline), source, decoder, NULL);
  gst_element_link (source, decoder);
  
  /* 
   * now, we set the pipeline playing state to pause and traverse it
   * to get the info we need.
   */
   
  res = gst_element_set_state (pipeline, GST_STATE_PAUSED);
  if (res == GST_STATE_CHANGE_FAILURE)
    {
      gst_element_set_state (pipeline, GST_STATE_NULL);
      gst_object_unref (GST_OBJECT (pipeline));
      
      free_properties(properties);
      
      return result;
    }
  
  res = gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE);
  if (res != GST_STATE_CHANGE_SUCCESS)
    {
      gst_element_set_state (pipeline, GST_STATE_NULL);
      gst_object_unref (GST_OBJECT (pipeline));
      
      free_properties(properties);
      
      return result;
    }
  
  if (fill_info (decoder, properties))
    {
      result = set_strings (env, properties, header);
    }
 
  /* free stuff */
  gst_element_set_state (pipeline, GST_STATE_NULL);
   
  free_properties (properties);
  
  gst_object_unref (GST_OBJECT (pipeline));
 
  return result;
}