You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by nw...@apache.org on 2015/08/06 18:19:56 UTC
[19/20] lucy-clownfish git commit: Warn about non-public resources in
Clownfish URIs
Warn about non-public resources in Clownfish URIs
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/04a18321
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/04a18321
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/04a18321
Branch: refs/heads/master
Commit: 04a18321eee563d6dcb85b0fe6300a5054a74675
Parents: 1a6ff50
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Sun Jul 26 23:13:14 2015 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Thu Aug 6 18:19:19 2015 +0200
----------------------------------------------------------------------
compiler/src/CFCCHtml.c | 41 ++++++++++++++++++++---------------------
compiler/src/CFCUri.c | 23 +++++++++++++++++++++--
2 files changed, 41 insertions(+), 23 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/04a18321/compiler/src/CFCCHtml.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCCHtml.c b/compiler/src/CFCCHtml.c
index c51da80..e36cb10 100644
--- a/compiler/src/CFCCHtml.c
+++ b/compiler/src/CFCCHtml.c
@@ -174,9 +174,6 @@ static char*
S_cfc_uri_to_url(CFCUri *uri_obj, CFCClass *base, int dir_level);
static char*
-S_struct_sym_to_url(const char *struct_sym, CFCClass *base, int dir_level);
-
-static char*
S_class_to_url(CFCClass *klass, CFCClass *base, int dir_level);
static char*
@@ -1058,26 +1055,40 @@ S_transform_link(cmark_node *link, CFCClass *doc_class, int dir_level) {
}
static char*
-S_type_to_html(CFCClass *klass, CFCType *type) {
+S_type_to_html(CFCClass *doc_class, CFCType *type) {
const char *type_c = CFCType_to_c(type);
if (CFCType_is_object(type)) {
- const char *struct_sym = CFCClass_full_struct_sym(klass);
- const char *specifier = CFCType_get_specifier(type);
const char *underscore = strchr(type_c, '_');
if (underscore) {
+ const char *doc_struct_sym = CFCClass_full_struct_sym(doc_class);
+ const char *specifier = CFCType_get_specifier(type);
+ CFCClass *klass = NULL;
+
+ // Don't link to doc class.
+ if (strcmp(specifier, doc_struct_sym) != 0) {
+ klass = CFCClass_fetch_by_struct_sym(specifier);
+ if (!klass) {
+ CFCUtil_warn("Class '%s' not found", specifier);
+ }
+ else if (!CFCClass_public(klass)) {
+ CFCUtil_warn("Non-public class '%s' used in public method",
+ specifier);
+ klass = NULL;
+ }
+ }
+
size_t offset = underscore + 1 - type_c;
char *prefix = CFCUtil_strndup(specifier, offset);
char *retval;
- if (strcmp(specifier, struct_sym) == 0) {
- // Don't link types of the same class.
+ if (!klass) {
retval = CFCUtil_sprintf("<span class=\"prefix\">%s</span>%s",
prefix, type_c + offset);
}
else {
- char *url = S_struct_sym_to_url(specifier, klass, 0);
+ char *url = S_class_to_url(klass, doc_class, 0);
const char *pattern =
"<span class=\"prefix\">%s</span>"
"<a href=\"%s\">%s</a>";
@@ -1130,21 +1141,9 @@ S_cfc_uri_to_url(CFCUri *uri_obj, CFCClass *doc_class, int dir_level) {
return url;
}
-// Return a relative URL to the class with full struct sym `struct_sym`.
-static char*
-S_struct_sym_to_url(const char *struct_sym, CFCClass *base, int dir_level) {
- if (!struct_sym) { return CFCUtil_strdup("not_found.html"); }
-
- CFCClass *klass = CFCClass_fetch_by_struct_sym(struct_sym);
-
- return S_class_to_url(klass, base, dir_level);
-}
-
// Return a relative URL to a class.
static char*
S_class_to_url(CFCClass *klass, CFCClass *base, int dir_level) {
- if (!klass) { return CFCUtil_strdup("not_found.html"); }
-
const char *class_name = CFCClass_get_name(klass);
char *path = CFCUtil_global_replace(class_name, "::", CHY_DIR_SEP);
char *url = CFCUtil_sprintf("%s.html", path);
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/04a18321/compiler/src/CFCUri.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCUri.c b/compiler/src/CFCUri.c
index 2a7cd5d..7ac8a7e 100644
--- a/compiler/src/CFCUri.c
+++ b/compiler/src/CFCUri.c
@@ -23,6 +23,8 @@
#include "CFCUri.h"
#include "CFCClass.h"
#include "CFCDocument.h"
+#include "CFCFunction.h"
+#include "CFCMethod.h"
#include "CFCUtil.h"
struct CFCUri {
@@ -167,25 +169,42 @@ S_resolve(CFCUri *self, const char *parcel, const char *struct_sym,
}
if (klass) {
+ if (!CFCClass_public(klass)) {
+ CFCUtil_warn("Non-public class '%s' in Clownfish URI: %s",
+ CFCClass_get_struct_sym(klass), self->string);
+ }
+
self->type = CFC_URI_CLASS;
self->klass = klass;
CFCBase_incref((CFCBase*)klass);
if (callable) {
if (islower(callable[0])) {
- if (!CFCClass_function(klass, callable)) {
+ CFCFunction *function = CFCClass_function(klass, callable);
+
+ if (!function) {
CFCUtil_warn("Unknown function '%s' in Clownfish URI: %s",
callable, self->string);
}
+ else if (!CFCFunction_public(function)) {
+ CFCUtil_warn("Non-public function '%s' in Clownfish URI:"
+ " %s", callable, self->string);
+ }
self->type = CFC_URI_FUNCTION;
self->callable = CFCUtil_strdup(callable);
}
else {
- if (!CFCClass_method(klass, callable)) {
+ CFCMethod *method = CFCClass_method(klass, callable);
+
+ if (!method) {
CFCUtil_warn("Unknown method '%s' in Clownfish URI: %s",
callable, self->string);
}
+ else if (!CFCMethod_public(method)) {
+ CFCUtil_warn("Non-public method '%s' in Clownfish URI:"
+ " %s", callable, self->string);
+ }
self->type = CFC_URI_METHOD;
self->callable = CFCUtil_strdup(callable);