GNode * _gcr_subject_public_key_load (GckObject *key, GCancellable *cancellable, GError **error) { GckBuilder builder = GCK_BUILDER_INIT; GckAttributes *attributes; GNode *asn; g_return_val_if_fail (GCK_IS_OBJECT (key), NULL); g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL); lookup_attributes (key, &builder); if (!check_attributes (&builder)) { if (!load_attributes (key, &builder, cancellable, error)) { gck_builder_clear (&builder); return NULL; } } attributes = gck_builder_end (&builder); asn = _gcr_subject_public_key_for_attributes (attributes); if (asn == NULL) { g_set_error_literal (error, GCK_ERROR, CKR_TEMPLATE_INCONSISTENT, _("Couldn't build public key")); } gck_attributes_unref (attributes); return asn; }
void _gcr_subject_public_key_load_async (GckObject *key, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { GSimpleAsyncResult *res; LoadClosure *closure; g_return_if_fail (GCK_IS_OBJECT (key)); g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable)); res = g_simple_async_result_new (NULL, callback, user_data, _gcr_subject_public_key_load_async); closure = g_slice_new0 (LoadClosure); closure->object = g_object_ref (key); lookup_attributes (key, &closure->builder); g_simple_async_result_set_op_res_gpointer (res, closure, load_closure_free); if (check_attributes (&closure->builder)) { g_simple_async_result_complete_in_idle (res); g_object_unref (res); return; } g_simple_async_result_run_in_thread (res, thread_key_attributes, G_PRIORITY_DEFAULT, cancellable); g_object_unref (res); }
/* Checks to see if incoming accept limits fits the page attributes */ static int fs_can_run(http_server srv, http_request request, dynamic_page p) { page_attribute a; assert(srv != NULL); assert(request != NULL); assert(p != NULL); a = dynamic_get_attributes(p); if(NULL == a) a = http_server_get_default_attributes(srv); /* None set, run anything */ if(NULL == a) return 1; else return check_attributes(request, a); }
/* * Here we send a disk file to the client, if the file exists. * A few rules: * a) The URI must be valid, no .. * b) The documentroot will be prepended to the file. No empty * documentroots allowed. Minimum docroot is 2 characters, and * it cannot contain "..". The docroot must either be ./ or / or * something longer. */ static int send_disk_file( http_server s, connection conn, http_request req, http_response response, meta_error e) { size_t i; const char *uri, *docroot; char filename[CCH_URI_MAX + DOCUMENTROOT_MAX + 2]; struct stat st; page_attribute a; http_version v; const char* content_type; assert(s != NULL); assert(conn != NULL); assert(req != NULL); assert(response != NULL); assert(e != NULL); (void)conn; /* TODO: Sjekk hvorfor funksjonen ikke sender fila??? */ /* We need a valid uri */ if( (uri = request_get_uri(req)) == NULL || strlen(uri) == 0 || strstr(uri, "..")) return set_http_error(e, HTTP_400_BAD_REQUEST); /* We need a valid documentroot */ if( (docroot = http_server_get_documentroot(s)) == NULL) return set_http_error(e, HTTP_400_BAD_REQUEST); i = strlen(docroot); if (i < 1 || (i == 1 && *docroot != '/') || (i == 2 && strcmp(docroot, "./") != 0) || (docroot[0] == '.' && docroot[1] == '.') || strstr(docroot, "..") != NULL ) return set_http_error(e, HTTP_400_BAD_REQUEST); /* We need space for the absolute path */ i += strlen(uri) + 2; if(i >= sizeof(filename)) return set_http_error(e, HTTP_400_BAD_REQUEST); /* Create the path */ sprintf(filename, "%s/%s", docroot, uri); /* Does the file exist? */ if(stat(filename, &st)) return set_http_error(e, HTTP_404_NOT_FOUND); else if(S_ISREG(st.st_mode)) ; else if(S_ISDIR(st.st_mode)) { strcat(filename, "/index.html"); if(stat(filename, &st)) return set_http_error(e, HTTP_404_NOT_FOUND); else if(!S_ISREG(st.st_mode)) return set_http_error(e, HTTP_400_BAD_REQUEST); } else return set_http_error(e, HTTP_400_BAD_REQUEST); /* We must check page_attributes even for files loaded from disk. */ /* NOTE: Trengs dette for HTTP 1.0 ?*/ v = request_get_version(req); if( (a = http_server_get_default_attributes(s)) != NULL && !check_attributes(req, a)) { response_set_status(response, HTTP_406_NOT_ACCEPTABLE); return set_http_error(e, HTTP_406_NOT_ACCEPTABLE); } content_type = get_mime_type(filename); /* This function does not actually send the file, just stats it * and stores the path. The contents will be sent later when * response_send_entity is called. */ if(!response_send_file(response, filename, content_type, e)) return 0; else { response_set_status(response, HTTP_200_OK); return 1; } }
/** * Processes the start of element events while parsing. * * @param userData the parsing context * @param name the element name * @param atts the element attributes */ static void CP_XMLCALL start_element_handler( void *userData, const XML_Char *name, const XML_Char **atts) { static const XML_Char * const req_plugin_atts[] = { "id", NULL }; static const XML_Char * const opt_plugin_atts[] = { "name", "version", "provider-name", NULL }; static const XML_Char * const req_bwcompatibility_atts[] = { NULL }; static const XML_Char * const opt_bwcompatibility_atts[] = { "abi", "api", NULL }; static const XML_Char * const req_cpluff_atts[] = { "version", NULL }; static const XML_Char * const opt_cpluff_atts[] = { NULL }; static const XML_Char * const req_import_atts[] = { "plugin", NULL }; static const XML_Char * const opt_import_atts[] = { "version", "optional", NULL }; static const XML_Char * const req_runtime_atts[] = { "library", NULL }; static const XML_Char * const opt_runtime_atts[] = { "funcs", NULL }; static const XML_Char * const req_ext_point_atts[] = { "id", NULL }; static const XML_Char * const opt_ext_point_atts[] = { "name", "schema", NULL }; static const XML_Char * const req_extension_atts[] = { "point", NULL }; //static const XML_Char * const opt_extension_atts[] = { "id", "name", NULL }; ploader_context_t *plcontext = userData; unsigned int i; // Process element start switch (plcontext->state) { case PARSER_BEGIN: if (!strcmp(name, "plugin")) { plcontext->state = PARSER_PLUGIN; if (!check_attributes(plcontext, name, atts, req_plugin_atts, opt_plugin_atts)) { break; } for (i = 0; atts[i] != NULL; i += 2) { if (!strcmp(atts[i], "name")) { plcontext->plugin->name = parser_strdup(plcontext, atts[i+1]); } else if (!strcmp(atts[i], "id")) { plcontext->plugin->identifier = parser_strdup(plcontext, atts[i+1]); } else if (!strcmp(atts[i], "version")) { plcontext->plugin->version = parser_strdup(plcontext, atts[i+1]); } else if (!strcmp(atts[i], "provider-name")) { plcontext->plugin->provider_name = parser_strdup(plcontext, atts[i+1]); } else if(!strcmp(atts[i],"url")){ plcontext->plugin->url = parser_strdup(plcontext, atts[i+1]); } else if(!strcmp(atts[i],"resourcetype")){ plcontext->plugin->resourcetype = parser_strdup(plcontext, atts[i+1]); } } } else { unexpected_element(plcontext, name); } break; case PARSER_PLUGIN: if (!strcmp(name, "backwards-compatibility")) { if (check_attributes(plcontext, name, atts, req_bwcompatibility_atts, opt_bwcompatibility_atts)) { for (i = 0; atts[i] != NULL; i += 2) { if (!strcmp(atts[i], "abi")) { plcontext->plugin->abi_bw_compatibility = parser_strdup(plcontext, atts[i+1]); } else if (!strcmp(atts[i], "api")) { plcontext->plugin->api_bw_compatibility = parser_strdup(plcontext, atts[i+1]); } } } } else if (!strcmp(name, "requires")) { plcontext->state = PARSER_REQUIRES; } else if (!strcmp(name, "runtime")) { if (check_attributes(plcontext, name, atts, req_runtime_atts, opt_runtime_atts)) { for (i = 0; atts[i] != NULL; i += 2) { if (!strcmp(atts[i], "library")) { plcontext->plugin->runtime_lib_name = parser_strdup(plcontext, atts[i+1]); } else if (!strcmp(atts[i], "funcs")) { plcontext->plugin->runtime_funcs_symbol = parser_strdup(plcontext, atts[i+1]); } } } } else if (!strcmp(name, "extension-point")) { if (check_attributes(plcontext, name, atts, req_ext_point_atts, opt_ext_point_atts)) { cp_ext_point_t *ext_point; // Allocate space for extension points, if necessary if (plcontext->plugin->num_ext_points == plcontext->ext_points_size) { cp_ext_point_t *nep; size_t ns; if (plcontext->ext_points_size == 0) { ns = 4; } else { ns = plcontext->ext_points_size * 2; } if ((nep = realloc(plcontext->plugin->ext_points, ns * sizeof(cp_ext_point_t))) == NULL) { resource_error(plcontext); break; } plcontext->plugin->ext_points = nep; plcontext->ext_points_size = ns; } // Parse extension point specification ext_point = plcontext->plugin->ext_points + plcontext->plugin->num_ext_points; memset(ext_point, 0, sizeof(cp_ext_point_t)); ext_point->plugin = plcontext->plugin; ext_point->name = NULL; ext_point->local_id = NULL; ext_point->identifier = NULL; ext_point->schema_path = NULL; for (i = 0; atts[i] != NULL; i += 2) { if (!strcmp(atts[i], "name")) { ext_point->name = parser_strdup(plcontext, atts[i+1]); } else if (!strcmp(atts[i], "id")) { ext_point->local_id = parser_strdup(plcontext, atts[i+1]); ext_point->identifier = parser_strscat(plcontext, plcontext->plugin->identifier, ".", atts[i+1], NULL); } else if (!strcmp(atts[i], "schema")) { ext_point->schema_path = parser_strdup(plcontext, atts[i+1]); } } plcontext->plugin->num_ext_points++; } } else if (!(strcmp(name, "extension"))) { plcontext->state = PARSER_EXTENSION; plcontext->depth = 0; if (check_req_attributes( plcontext, name, atts, req_extension_atts)) { cp_extension_t *extension; // Allocate space for extensions, if necessary if (plcontext->plugin->num_extensions == plcontext->extensions_size) { cp_extension_t *ne; size_t ns; if (plcontext->extensions_size == 0) { ns = 16; } else { ns = plcontext->extensions_size * 2; } if ((ne = realloc(plcontext->plugin->extensions, ns * sizeof(cp_extension_t))) == NULL) { resource_error(plcontext); break; } plcontext->plugin->extensions = ne; plcontext->extensions_size = ns; } // Parse extension attributes extension = plcontext->plugin->extensions + plcontext->plugin->num_extensions; memset(extension, 0, sizeof(cp_extension_t)); extension->plugin = plcontext->plugin; extension->name = NULL; extension->local_id = NULL; extension->identifier = NULL; extension->ext_point_id = NULL; extension->configuration = NULL; for (i = 0; atts[i] != NULL; i += 2) { if (!strcmp(atts[i], "point")) { extension->ext_point_id = parser_strdup(plcontext, atts[i+1]); } else if (!strcmp(atts[i], "id")) { extension->local_id = parser_strdup(plcontext, atts[i+1]); extension->identifier = parser_strscat(plcontext, plcontext->plugin->identifier, ".", atts[i+1], NULL); } else if (!strcmp(atts[i], "name")) { extension->name = parser_strdup(plcontext, atts[i+1]); } } plcontext->plugin->num_extensions++; // Initialize configuration parsing if ((extension->configuration = plcontext->configuration = parser_malloc(plcontext, sizeof(cp_cfg_element_t))) != NULL) { init_cfg_element(plcontext, plcontext->configuration, name, atts, NULL); } XML_SetCharacterDataHandler(plcontext->parser, character_data_handler); } } else { unexpected_element(plcontext, name); } break; case PARSER_REQUIRES: if (!strcmp(name, "c-pluff")) { if (check_attributes(plcontext, name, atts, req_cpluff_atts, opt_cpluff_atts)) { for (i = 0; atts[i] != NULL; i += 2) { if (!strcmp(atts[i], "version")) { plcontext->plugin->req_cpluff_version = parser_strdup(plcontext, atts[i+1]); } } } } else if (!strcmp(name, "import")) { if (check_attributes(plcontext, name, atts, req_import_atts, opt_import_atts)) { cp_plugin_import_t *import = NULL; // Allocate space for imports, if necessary if (plcontext->plugin->num_imports == plcontext->imports_size) { cp_plugin_import_t *ni; size_t ns; if (plcontext->imports_size == 0) { ns = 16; } else { ns = plcontext->imports_size * 2; } if ((ni = realloc(plcontext->plugin->imports, ns * sizeof(cp_plugin_import_t))) == NULL) { resource_error(plcontext); break; } plcontext->plugin->imports = ni; plcontext->imports_size = ns; } // Parse import specification import = plcontext->plugin->imports + plcontext->plugin->num_imports; memset(import, 0, sizeof(cp_plugin_import_t)); import->plugin_id = NULL; import->version = NULL; for (i = 0; atts[i] != NULL; i += 2) { if (!strcmp(atts[i], "plugin")) { import->plugin_id = parser_strdup(plcontext, atts[i+1]); } else if (!strcmp(atts[i], "version")) { import->version = parser_strdup(plcontext, atts[i+1]); } else if (!strcmp(atts[i], "optional")) { if (!strcmp(atts[i+1], "true") || !strcmp(atts[i+1], "1")) { import->optional = 1; } else if (strcmp(atts[i+1], "false") && strcmp(atts[i+1], "0")) { descriptor_errorf(plcontext, 0, _("unknown boolean value: %s"), atts[i+1]); } } } plcontext->plugin->num_imports++; } } else { unexpected_element(plcontext, name); } break; case PARSER_EXTENSION: plcontext->depth++; if (plcontext->configuration != NULL && plcontext->skippedCEs == 0) { cp_cfg_element_t *ce; // Allocate more space for children, if necessary if (plcontext->configuration->num_children == plcontext->configuration->index) { cp_cfg_element_t *nce; size_t ns; if (plcontext->configuration->index == 0) { ns = 16; } else { ns = plcontext->configuration->index * 2; } if ((nce = realloc(plcontext->configuration->children, ns * sizeof(cp_cfg_element_t))) == NULL) { plcontext->skippedCEs++; resource_error(plcontext); break; } plcontext->configuration->children = nce; plcontext->configuration->index = ns; } // Save possible value if (plcontext->value != NULL) { plcontext->value[plcontext->value_length] = '\0'; plcontext->configuration->value = plcontext->value; } ce = plcontext->configuration->children + plcontext->configuration->num_children; init_cfg_element(plcontext, ce, name, atts, plcontext->configuration); plcontext->configuration->num_children++; plcontext->configuration = ce; } break; case PARSER_UNKNOWN: plcontext->depth++; break; default: unexpected_element(plcontext, name); break; } }