Пример #1
0
static void on_uploaded(struct afb_req *prequest, int status)
{
    struct afb_req request = afb_req_unstore(prequest);
    struct afb_arg argfile = afb_req_get(request, "file-upload");
    char *file = renamed_filename(argfile);
    if (file != NULL)
        unlink(file);
    free(file);
    if (status)
        afb_req_fail (request, "failed", "expected file not received");
    else
        afb_req_success_f (request, NULL, "uploaded file %s", argfile.value);
   afb_req_unref(request);
}
Пример #2
0
static void upload (struct afb_req request) { /* AFB_SESSION_CHECK */

    mediaCtxHandleT *ctx = afb_req_context_get(request);
    struct afb_req *prequest;
    struct afb_arg argfile;
    char *path;

    /* check that context is initialized */
    if (ctx == NULL) {
      afb_req_fail (request, "failed", "uninitialized");
      return;
    }

    /* get the file */
    argfile = afb_req_get(request, "file-upload");
    if (!argfile.value || !argfile.path) {
        afb_req_fail (request, "failed", "expected file not received");
        return;
    }

    /* rename the file */
    path = renamed_filename(argfile);
    if (path == NULL) {
        afb_req_fail (request, "failed", "out of memory");
        return;
    }
    if (rename(argfile.path, path) != 0) {
        free(path);
        afb_req_fail (request, "failed", "system error");
        return;
    }

    /* for asynchronous processing */
    prequest = afb_req_store(request);
    if (path == NULL) {
        unlink(path);
        afb_req_fail (request, "failed", "out of memory");
    }
    else if (!_rygel_upload (ctx, path, (void*)on_uploaded, prequest)) {
        afb_req_unref(afb_req_unstore(prequest));
        unlink(path);
        afb_req_fail (request, "failed", "Error when uploading file to media server... could not complete");
    }
    free(path);
}
Пример #3
0
static void install(struct afb_req request)
{
	struct json_object *obj, *added;
	char *query;
	const char *filename;
	struct afb_arg arg;

	/* get the argument */
	arg = afb_req_get(request, "widget");
	filename = arg.path;
	if (filename == NULL) {
		afb_req_fail(request, "bad-request", "missing 'widget' file");
		return;
	}

	/* makes the query */
	if (0 >= asprintf(&query, "\"%s\"", filename)) {
		afb_req_fail(request, "server-error", "out of memory");
		return;
	}

	obj = jbus_call_sj_sync(jbus, _install_, query);
	if (afb_interface->verbosity)
		fprintf(stderr, "(afm-main-plugin) install(%s) -> %s\n", query,
			obj ? json_object_to_json_string(obj) : "NULL");
	free(query);

	/* check status */
	if (obj == NULL) {
		afb_req_fail(request, "failed", "framework daemon failure");
		return;
	}

	/* embed if needed */
	if (json_object_object_get_ex(obj, _added_, &added))
		obj = added;
	obj = json_object_get(obj);
	obj = embed(_id_, obj);
	afb_req_success(request, obj, NULL);
}