static void
gth_media_viewer_page_finalize (GObject *obj)
{
	GthMediaViewerPage *self;

	self = GTH_MEDIA_VIEWER_PAGE (obj);

        if (self->priv->update_progress_id != 0) {
                g_source_remove (self->priv->update_progress_id);
                self->priv->update_progress_id = 0;
        }

        if (self->priv->update_volume_id != 0) {
                g_source_remove (self->priv->update_volume_id);
                self->priv->update_volume_id = 0;
        }

	if (self->priv->playbin != NULL) {
		save_volume (self);
		gst_element_set_state (self->priv->playbin, GST_STATE_NULL);
		gst_object_unref (GST_OBJECT (self->priv->playbin));
		self->priv->playbin = NULL;
	}
	_g_object_unref (self->priv->icon);
	_g_object_unref (self->priv->file_data);
	if (self->priv->screensaver != NULL) {
		gth_screensaver_uninhibit (self->priv->screensaver);
		g_object_unref (self->priv->screensaver);
	}

	G_OBJECT_CLASS (gth_media_viewer_page_parent_class)->finalize (obj);
}
Beispiel #2
0
 void save_volumes(strings& s,volumes& vols,const char *like,const std::string & append_history)
 {
   for(int i=0;i<s.size();i++)
   {
     save_volume(vols[i],s[i].c_str(),like,append_history);
   }
 }
static void
gth_media_viewer_page_real_deactivate (GthViewerPage *base)
{
	GthMediaViewerPage *self;

	self = (GthMediaViewerPage*) base;

	gth_browser_unregister_viewer_control (self->priv->browser, self->priv->mediabar);

	if (self->priv->builder != NULL) {
		g_object_unref (self->priv->builder);
		self->priv->builder = NULL;
	}

        if (self->priv->update_progress_id != 0) {
                g_source_remove (self->priv->update_progress_id);
                self->priv->update_progress_id = 0;
        }

        if (self->priv->update_volume_id != 0) {
                g_source_remove (self->priv->update_volume_id);
                self->priv->update_volume_id = 0;
        }

	if (self->priv->playbin != NULL) {
		save_volume (self);
		gst_element_set_state (self->priv->playbin, GST_STATE_NULL);
		gst_object_unref (GST_OBJECT (self->priv->playbin));
		self->priv->playbin = NULL;
	}

	gtk_widget_destroy (self->priv->screenshot_button);
	self->priv->screenshot_button = NULL;

	gth_browser_set_viewer_widget (self->priv->browser, NULL);
}
Beispiel #4
0
int main (int argc, char **argv) 
{
    printf ("=====> testing misc.c\n");

    test_command("date");
    test_command("ls / -l | sort");
    test_command("/foo");
    {
        char c = 0;
        long l = 0;
        int i = 0;
        long long ll = 0;

        sscanf_lines  ("a1\na\na2\n", "a%d", &i);
        assert (i==1);
        sscanf_lines  ("a\nab3\na   4\na5", "a %d", &i);
        assert (i==4);
        sscanf_lines  ("", "%d", &i);
        sscanf_lines  ("\n\n\n", "%d", &i);
        sscanf_lines  ("abcdefg6", "g%d", &i);
        assert (i!=6);
        sscanf_lines  ("abcdefg", "ab%cdefg", &c);
        assert (c=='c');
        sscanf_lines  ("a\na    7\na\n", "a %ld", &l);
        assert (l==7L);
        sscanf_lines  ("a\n8a\na9\n", "a %lld", &ll);
        assert (ll==9L);
    }

    printf ("=====> testing data.c\n");
    {
#define INSTS 50
        bunchOfInstances * bag = NULL;
        ncInstance * inst = NULL;
        ncInstance * Insts[INSTS];
        int i, n;
        
        printf ("========> testing instance struct management\n");
        free_instance (NULL);
        free_instance (&inst);
        inst = allocate_instance ("the-uuid", "i1", NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, 0);
        assert(inst!=NULL);
        free_instance (&inst);
        assert(inst==NULL);
        
        n = total_instances (&bag);
        assert(n==0);
        bag=NULL;
        
        inst = find_instance(&bag, "foo");
        assert(inst==NULL);
        bag=NULL;
        
        n = remove_instance(&bag, NULL);
        assert(n!=0);
        bag=NULL;
        
        for (i=0; i<INSTS; i++) {
            char id[10];
            sprintf(id, "i-%d", i);
            inst = Insts[i] = allocate_instance ("the-uuid", id, NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, 0);
            assert (inst!=NULL);
            n = add_instance(&bag, inst);
            assert (n==0);
        }
        n = total_instances (&bag);
        assert (n==INSTS);
        n = remove_instance(&bag, Insts[0]);
        assert (n==0);
        n = remove_instance(&bag, Insts[INSTS-1]);
        assert (n==0);
        n = total_instances (&bag);
        assert (n==INSTS-2);

        printf ("========> testing volume struct management\n");
        ncVolume * v;
        inst = allocate_instance ("the-uuid", "i2", NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, 0);
        assert(inst!=NULL);
        for (i=0; i<EUCA_MAX_VOLUMES; i++) {
            char id[10];
            sprintf (id, "v-%d", i);
            v = save_volume (inst, id, "rd", "ld", "ldr", VOL_STATE_ATTACHED);
            assert (v!=NULL);
        }
        assert (is_volume_used (v));
        assert (save_volume (inst, "too-much", "rd", "ld", "ldr", VOL_STATE_ATTACHED)==NULL);
        assert (save_volume (inst, v->volumeId, NULL, NULL, NULL, NULL)!=NULL);
        assert (save_volume (inst, v->volumeId, "RD", NULL, NULL, NULL)!=NULL);
        assert (save_volume (inst, v->volumeId, NULL, "LD", NULL, NULL)!=NULL);
        assert (save_volume (inst, v->volumeId, NULL, NULL, "LDR", NULL)!=NULL);
        assert (save_volume (inst, v->volumeId, NULL, NULL, NULL, VOL_STATE_DETACHED)!=NULL);
        assert (strcmp (v->remoteDev, "RD") == 0);
        assert (save_volume (inst, "v-x1", NULL, NULL, NULL, VOL_STATE_ATTACHING)!=NULL);
        assert (save_volume (inst, "v-x2", NULL, NULL, NULL, VOL_STATE_ATTACHING)==NULL);
        assert (save_volume (inst, "v-x1", NULL, NULL, NULL, VOL_STATE_DETACHING)!=NULL);
        assert (save_volume (inst, "v-x2", NULL, NULL, NULL, VOL_STATE_ATTACHING)==NULL);
        assert (save_volume (inst, "v-x1", NULL, NULL, NULL, VOL_STATE_DETACHING_FAILED)!=NULL);
        assert (save_volume (inst, "v-x2", NULL, NULL, NULL, VOL_STATE_ATTACHING)==NULL);
        assert (free_volume (inst, "v-x1")!=NULL);
        for (i=0; i<EUCA_MAX_VOLUMES-1; i++) {
            char id[10];
            sprintf (id, "v-%d", i);
            v = free_volume (inst, id);
            assert (v!=NULL);
        }
        free_instance (&inst);
        assert(inst==NULL);        
    }

    printf ("OK\n");
    return 0;
}
Beispiel #5
0
//!
//! Implement the backing store for a given instance
//!
//! @param[in] instance pointer to the instance
//! @param[in] is_migration_dest
//!
//! @return EUCA_OK on success or EUCA_ERROR on failure
//!
//! @pre The instance parameter must not be NULL.
//!
//! @post
//!
int create_instance_backing(ncInstance * instance, boolean is_migration_dest)
{
    int rc = 0;
    int ret = EUCA_ERROR;
    virtualMachine *vm = &(instance->params);
    artifact *sentinel = NULL;
    char work_prefix[1024] = { 0 };    // {userId}/{instanceId}
    char base_path[EUCA_MAX_PATH];
    char user_dir_path[EUCA_MAX_PATH];

    // set various instance-directory-relative paths in the instance struct
    set_instance_paths(instance);

    set_path(base_path, sizeof(base_path), NULL, NULL);
    snprintf(user_dir_path, sizeof(user_dir_path), "%s/%s", base_path, instance->userId);
    // create backing directory
    if ((check_path(user_dir_path) == 1) && (mkdir(user_dir_path, INSTANCE_DIRECTORY_PERM) == -1)) {
        LOGERROR("[%s] could not create backing directory %s\n", instance->instanceId, user_dir_path);
        goto out;
    }
    if (mkdir(instance->instancePath, INSTANCE_DIRECTORY_PERM) == -1) {
        LOGERROR("[%s] could not create backing directory %s\n", instance->instanceId, instance->instancePath);
        goto out;
    }

    if (strstr(instance->platform, "windows")) {
        // generate the floppy file for windows instances
        if (makeWindowsFloppy(nc_state.home, instance->instancePath, instance->keyName, instance->instanceId)) {
            LOGERROR("[%s] could not create windows bootup script floppy\n", instance->instanceId);
            goto out;
        } else {
            set_path(instance->floppyFilePath, sizeof(instance->floppyFilePath), instance, "floppy");
            instance->hasFloppy = TRUE;
        }
    } else if (instance->credential && strlen(instance->credential)) {
        LOGDEBUG("[%s] creating floppy for instance credential\n", instance->instanceId);
        if (make_credential_floppy(nc_state.home, instance->instancePath, instance->credential)) {
            LOGERROR("[%s] could not create credential floppy\n", instance->instanceId);
            goto out;
        } else {
            set_path(instance->floppyFilePath, sizeof(instance->floppyFilePath), instance, "floppy");
            instance->hasFloppy = TRUE;
        }
    } else if(instance->hasFloppy && is_migration_dest) {
        LOGDEBUG("[%s] creating blank instance credential floppy\n", instance->instanceId);
        char dest_path[1024] = "";
        int fd = 0;
        snprintf(dest_path, 1024, "%s/floppy", instance->instancePath);
        if ((fd = open(dest_path, O_CREAT | O_TRUNC | O_RDWR, 0700)) < 0) {
           LOGERROR("[%s] failed to create fake floppy\n", instance->instanceId);
           goto out;
        } else {
           lseek(fd, 1024*2048-1, SEEK_SET);
           write(fd, "\n", 1);
        }
        close(fd);
    } else {
        instance->hasFloppy = FALSE;
    }

    set_id(instance, NULL, work_prefix, sizeof(work_prefix));

    // compute tree of dependencies
    sentinel = vbr_alloc_tree(vm,      // the struct containing the VBR
                              TRUE,    // make working copy of runtime-modifiable files
                              is_migration_dest,    // tree of an instance on the migration destination
                              (instance->do_inject_key) ? (instance->keyName) : (NULL), // the SSH key
                              &(instance->bail_flag),   // flag indicating that provisioning should bail
                              instance->instanceId);    // ID is for logging
    if (sentinel == NULL) {
        LOGERROR("[%s] failed to prepare extended backing for instance\n", instance->instanceId);
        goto out;
    }

    sem_p(disk_sem);
    {
        // download/create/combine the dependencies
        rc = art_implement_tree(sentinel, work_bs, cache_bs, work_prefix, INSTANCE_PREP_TIMEOUT_USEC);
    }
    sem_v(disk_sem);

    if (rc != EUCA_OK) {
        LOGERROR("[%s] failed to implement backing for instance\n", instance->instanceId);
        goto out;
    }
    // copy EBS entries from VBR[] to volumes[]
    for (int i = 0; ((i < EUCA_MAX_VBRS) && (i < instance->params.virtualBootRecordLen)); i++) {
        virtualBootRecord *vbr = &(instance->params.virtualBootRecord[i]);
        if (vbr->locationType == NC_LOCATION_SC) {
            char *volumeId = vbr->id;  // id is 'emi-XXXX', replace it with 'vol-XXXX'
            ebs_volume_data *vol_data = NULL;
            if (deserialize_volume(vbr->resourceLocation, &vol_data) == 0) {
                volumeId = vol_data->volumeId;
            }
            if (save_volume(instance, volumeId, vbr->resourceLocation,  // attachmentToken
                            vbr->preparedResourceLocation,  // connect_string
                            vbr->guestDeviceName, VOL_STATE_ATTACHED, vbr->backingPath) == NULL) {  // the XML
                LOGERROR("[%s] failed to add record for volume %s\n", instance->instanceId, volumeId);
            }
            EUCA_FREE(vol_data);
        }
    }

    if (save_instance_struct(instance)) // update instance checkpoint now that the struct got updated
        goto out;

    ret = EUCA_OK;

out:
    if (sentinel)
        art_free(sentinel);
    return (ret);
}
Beispiel #6
0
//!
//! Main entry point of the application
//!
//! @param[in] argc the number of parameter passed on the command line
//! @param[in] argv the list of arguments
//!
//! @return Always return 0
//!
int main(int argc, char **argv)
{
    printf("=====> testing misc.c\n");

    test_command("date");
    test_command("ls / -l | sort");
    test_command("/foo");
    {
        char c = 0;
        long l = 0;
        int i = 0;
        long long ll = 0;

        euca_lscanf("a1\na\na2\n", "a%d", &i);
        assert(i == 1);
        euca_lscanf("a\nab3\na   4\na5", "a %d", &i);
        assert(i == 4);
        euca_lscanf("", "%d", &i);
        euca_lscanf("\n\n\n", "%d", &i);
        euca_lscanf("abcdefg6", "g%d", &i);
        assert(i != 6);
        euca_lscanf("abcdefg", "ab%cdefg", &c);
        assert(c == 'c');
        euca_lscanf("a\na    7\na\n", "a %ld", &l);
        assert(l == 7L);
        euca_lscanf("a\n8a\na9\n", "a %lld", &ll);
        assert(ll == 9L);
    }

    printf("=====> testing auth.c\n");
    {
//int decrypt_string_with_node_and_symmetric_key(char *in_buffer, char *key_buffer, char**out_buffer)
        euca_init_cert();
        char *encrypted_symm_key =
            "YCvEugV7FynwQnyDbNX8hVFstseIpzhBCi6nxWZOUhVbivEf9Frkk7evxvQeSn9GUIvyNSE15Stts/CQmIGNsAKpAmjUoDzkkB/8EUCO9bgVi6IQl6SOzZCqX1hGCMZT1Ir32HXcwZcEbtDl0WpfLahjT9pZQAtDnnRT7H8+qysxUbEoL9Z2Yw5GneF5hRDWcA9Kce617oNbPFiZjLnnQr2iNsxyWb8LVj7KnBweJ8UJumgcWp26VsWoBUUCK/3adPAvOk/kalgrXZAk6fo/TqGUqdokjj1tz3rG7dcvTRuB0qwY1P8KfgRg3HABQcHjriKNvBYTVD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ZwXh7dsR4Efn91YFcqEsVtO284CxWASh5Mid+pJD6FxVU8/pbX/EEi963fQgw42SiQxVXCaMySVB/9zlBfPg0dwP8yxwD+SiJz5In+oTDmr+OhpY0vQzkt/UnhORFpvJM7i1scY/rjAz2j6LjsHca4bt/x0JYkM+Vr+tZ90iiS01+fQX/fgFih6l9RoLWsbnilTx39dtwI8pOPitO90glIQ3EvLLmvZN9nvx9JfWTuinAkpOqrlkbc9ccKsAWa1zvvfCzGgqONoJ499rGFsY6H81jXR4h8K2o9n/Xs/8Sp8I8IqWfmS/JKH21JquJi4gLpmmZ38Kv6V4R7j5YcB9YwnIfav/uAJTN9VD9NKOyFwfhDA2YT4ErzMk5UL3sfQIX6UCzaKCiOeH3nKHzM7X4aHSqtSbvVNVxQ0tMYvm2oVEojmaXWGHmWyoylXJ1v0eaK38SDzwdpef6UKXESPEMpnR0krqH8bC7lZyMx2OyKpse9hJbjhzOvgv91lkUG3kidPxKraTUwXUmxVlUgxfcCgknO93U+kopjiffJDe/xILawvpEq0KWBFfbFN679znyz+8AEud2WSYdz7KnYuoX3RmViid/Oj0w==";
        char *decrypted = NULL;
        int out_len = -1;
        if (decrypt_string_with_node_and_symmetric_key(encrypted_string, encrypted_symm_key, &decrypted, &out_len) != EUCA_OK) {
            printf("failed to decrypt using symmetric key\n");
        } else {
            printf("decrypted length: %d\n", out_len);
        }

    }

    printf("=====> testing data.c\n");
    {
#define INSTS 50
        bunchOfInstances *bag = NULL;
        ncInstance *inst = NULL;
        ncInstance *Insts[INSTS];
        int i, n;

        printf("========> testing instance struct management\n");
        free_instance(NULL);
        free_instance(&inst);
        inst = allocate_instance("the-uuid", "i1", NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, 0);
        assert(inst != NULL);
        free_instance(&inst);
        assert(inst == NULL);

        n = total_instances(&bag);
        assert(n == 0);
        bag = NULL;

        inst = find_instance(&bag, "foo");
        assert(inst == NULL);
        bag = NULL;

        n = remove_instance(&bag, NULL);
        assert(n != EUCA_OK);
        bag = NULL;

        for (i = 0; i < INSTS; i++) {
            char id[10];
            sprintf(id, "i-%d", i);
            inst = Insts[i] = allocate_instance("the-uuid", id, NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, 0);
            assert(inst != NULL);
            n = add_instance(&bag, inst);
            assert(n == EUCA_OK);
        }
        n = total_instances(&bag);
        assert(n == INSTS);
        n = remove_instance(&bag, Insts[0]);
        assert(n == EUCA_OK);
        n = remove_instance(&bag, Insts[INSTS - 1]);
        assert(n == EUCA_OK);
        n = total_instances(&bag);
        assert(n == INSTS - 2);

        printf("========> testing volume struct management\n");
        ncVolume *v;
        inst = allocate_instance("the-uuid", "i2", NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, 0);
        assert(inst != NULL);
        for (i = 0; i < EUCA_MAX_VOLUMES; i++) {
            char id[10];
            sprintf(id, "v-%d", i);
            v = save_volume(inst, id, "tok", "rd", "ld", "ldr", VOL_STATE_ATTACHED);
            assert(v != NULL);
        }
        assert(is_volume_used(v));
        assert(save_volume(inst, "too-much", "tok", "rd", "ld", "ldr", VOL_STATE_ATTACHED) == NULL);
        assert(save_volume(inst, v->volumeId, NULL, NULL, NULL, NULL, NULL) != NULL);
        assert(save_volume(inst, v->volumeId, NULL, "RD", NULL, NULL, NULL) != NULL);
        assert(save_volume(inst, v->volumeId, NULL, NULL, "LD", NULL, NULL) != NULL);
        assert(save_volume(inst, v->volumeId, NULL, NULL, NULL, "LDR", NULL) != NULL);
        assert(save_volume(inst, v->volumeId, NULL, NULL, NULL, NULL, VOL_STATE_DETACHED) != NULL);
        assert(strcmp(v->attachmentToken, "RD") == 0);
        assert(save_volume(inst, "v-x1", NULL, NULL, NULL, NULL, VOL_STATE_ATTACHING) != NULL);
        assert(save_volume(inst, "v-x2", NULL, NULL, NULL, NULL, VOL_STATE_ATTACHING) == NULL);
        assert(save_volume(inst, "v-x1", NULL, NULL, NULL, NULL, VOL_STATE_DETACHING) != NULL);
        assert(save_volume(inst, "v-x2", NULL, NULL, NULL, NULL, VOL_STATE_ATTACHING) == NULL);
        assert(save_volume(inst, "v-x1", NULL, NULL, NULL, NULL, VOL_STATE_DETACHING_FAILED) != NULL);
        assert(save_volume(inst, "v-x2", NULL, NULL, NULL, NULL, VOL_STATE_ATTACHING) == NULL);
        assert(free_volume(inst, "v-x1") != NULL);
        for (i = 0; i < EUCA_MAX_VOLUMES - 1; i++) {
            char id[10];
            sprintf(id, "v-%d", i);
            v = free_volume(inst, id);
            assert(v != NULL);
        }
        free_instance(&inst);
        assert(inst == NULL);
    }

    printf("OK\n");
    return 0;
}