Commit ec6d6977 authored by Bat's avatar Bat
Browse files

Merge branch 'master' into 'master'

Fixed segfaults and improved code style



See merge request !10
parents 4076cabf 271b8e9d
Pipeline #9406 passed with stage
in 4 minutes and 10 seconds
......@@ -106,11 +106,8 @@ public class UserController : Controller {
} else {
int id = int.parse (req.query_ids["id"]);
User usr = (User) db.get_id<User> (id);
print ("account created the : " + usr.register_date.to_string ());
var model = new HashMap<string, Object> ();
model ["mod"] = usr;
model ["test"] = new TestModel ("Yet another link", "https://bat41.gitlab.io");
return page ("views/user/profile.wala", model);
print ("account created the : " + usr.register_date.to_string () + "\n");
return page ("views/user/profile.wala", model ("mod", usr, "test", new TestModel ("Yet another link", "https://bat41.gitlab.io")));
}
}
......
No preview for this file type
......@@ -13,8 +13,8 @@ namespace Valse {
* @param path The path to split
* @return An array with the different parts of the path
*/
private string [] split_path (string path) {
string [] result = new string [] {};
private string[] split_path (string path) {
string[] result = new string[] {};
foreach (string part in path.split ("/")) {
if (part.length != 0) {
// we add to the result, only if it's not empty
......
......@@ -40,7 +40,7 @@ namespace Valse {
* @param tags The tags for this view
* @return A {@link Valse.Response}, ready to be sent
*/
public Response page (string file, HashMap<string, Object> obj_models = new HashMap<string, Object> (), string [] tags = {}) {
public Response page (string file, HashMap<string, Object> obj_models = new HashMap<string, Object> (), string[] tags = {}) {
return this.template (get_contents (file), obj_models, tags);
}
......@@ -52,7 +52,7 @@ namespace Valse {
* @param tags The tags for this view
* @return A {@link Valse.Response}, ready to be sent
*/
public Response template (string html, HashMap<string, Object> obj_models = new HashMap<string, Object> (), string [] tags = {}) {
public Response template (string html, HashMap<string, Object> obj_models = new HashMap<string, Object> (), string[] tags = {}) {
// on crée la vue
View view = new View ();
view.content = html;
......@@ -76,14 +76,14 @@ namespace Valse {
va_list others = va_list();
HashMap<string, Object> res = new HashMap<string, Object> ();
res[key1] = obj1;
while (true) {
string? k = others.arg<string> ();
Object? v = others.arg<Object> ();
if (k == null) {
break;
}
Object? v = others.arg<Object> ();
if (v == null) {
print ("[WARNING] Using the model method with a key (%s), but no associated value.\n", k);
break;
......@@ -182,7 +182,7 @@ namespace Valse {
* @param act The handler for this action.
* @param options The options of this action.
*/
public void add_complete_action (string name, owned CompleteActionHandler act, string [] options = {}) {
public void add_complete_action (string name, owned CompleteActionHandler act, string[] options = {}) {
actions [name] = new Action.complete ((owned) act, options);
}
......
......@@ -229,7 +229,9 @@ namespace Valse {
break;
case "GDateTime":
int year = 0, month = 0, day = 0, hour = 0, minute = 0, second = 0;
log_debug ("OK 1\n");
vals [i].scanf ("%d-%d-%d %d-%d-%d.000", ref year, ref month, ref day, ref hour, ref minute, ref second);
log_debug ("OK 2\n");
DateTime dt = new DateTime.utc (year, month, day, hour, minute, (double) second);
val.set_boxed (dt);
break;
......@@ -370,7 +372,5 @@ namespace Valse {
query += "WHERE rowid = %d;".printf (id);
execute_query (query);
}
}
}
......@@ -149,7 +149,7 @@ namespace Valse {
}
}
internal void set_options_names (string [] opts_names) {
internal void set_options_names (string[] opts_names) {
int i = 0;
foreach (string opt_name in opts_names) {
this.query_ids [opt_name] = this.options [i];
......
......@@ -30,7 +30,7 @@ namespace Valse {
/**
* The data of the request.
*/
public uint8 [] raw_data { get; set; }
public uint8[] raw_data { get; set; }
/**
* The body of the response.
......
......@@ -48,12 +48,12 @@ namespace Valse {
/**
* A list of the static files found at the launch of the server
*/
private string [] static_files { get; set; }
private string[] static_files { get; set; }
/*
* The schema to follow for routing.
*/
public string [] route_schema { get; set; default = { "{{ controller }}", "{{ action }}", "{{ id }}" }; }
public string[] route_schema { get; set; default = { "{{ controller }}", "{{ action }}", "{{ id }}" }; }
/**
* Constructor of the server. Registers some commmons mime-types.
......@@ -124,7 +124,7 @@ namespace Valse {
*/
public string get_mime (string path) {
string [] splitted_path = path.split (".");
string[] splitted_path = path.split (".");
string ext = splitted_path [splitted_path.length - 1]; // on récupère juste la dernière partie du chemin
string result = "text/plain";
......@@ -142,8 +142,8 @@ namespace Valse {
* @param arr The array where we remove elements
* @return An array without the elements
*/
private string [] strip_array (int count, string [] arr) {
string [] res = new string [] {};
private string[] strip_array (int count, string[] arr) {
string[] res = new string[] {};
for (int i = 0; i < arr.length; i++) {
if (i > count - 1) {
res += arr [i];
......@@ -200,7 +200,7 @@ namespace Valse {
if ("static/" + req.path in this.static_files) {
try {
uint8 [] file_data = "".data;
uint8[] file_data = "".data;
GLib.FileUtils.get_data ("static/" + req.path, out file_data);
res.raw_data = file_data;
res.is_data = true;
......
......@@ -10,7 +10,7 @@ namespace Valse {
/**
* The tags of the view.
*/
public string [] tags { get; set; }
public string[] tags { get; set; }
/**
* The content of the view.
......
......@@ -4,7 +4,7 @@ namespace Valse {
public class Many<G> : Object {
private G [] _arr {get; set; default = new G[] {};}
private G[] _arr {get; set; default = new G[] {};}
public Many () {
......
......@@ -3,7 +3,7 @@ namespace Valse {
/**
* The delegate representing the callback of a filter.
*/
public delegate string FilterCallback (ref string input, string [] args);
public delegate string FilterCallback (ref string input, string[] args);
/**
* Wrapper for the {@link Valse.FilterCallback} delegate.
......
......@@ -176,7 +176,7 @@ namespace Valse {
}
// Model variables
Regex var_re = new Regex ("{{ *" + model_keyword + "\\.(?<prop>[A-Za-z0-9_]*)(\\|(?<filter>[[:graph:]]*?)( (?<params>\".*?\")))? *}}");
Regex var_re = new Regex ("{{ *" + model_keyword + "\\.(?<prop>[A-Za-z0-9_]*)(\\|(?<filter>[[:graph:]]*?)( (?<params>\".*?\"))?)? *}}");
MatchInfo var_info;
bool go_var = var_re.match (result, 0, out var_info);
......@@ -187,7 +187,6 @@ namespace Valse {
string? params = var_info.fetch_named ("params");
// HTML characters escape
prop_val = prop_val.replace ("&", "&amp;");
prop_val = prop_val.replace ("\"", "&quot;");
prop_val = prop_val.replace ("'", "&#039;");
......@@ -195,19 +194,18 @@ namespace Valse {
prop_val = prop_val.replace (">", "&gt;");
// apply filters if needed
if (var_filters.length > 0) {
if (var_filters != null && var_filters.length > 0) {
foreach (string filter in var_filters.split ("|")) {
if (filters.has_key (filter)) {
//assert (filters [filter] != null);
string [] filter_args = {};
if (params.length > 0) {
if (Wala.filters.has_key (filter)) {
string[] filter_args = {};
if (params != null && params.length > 0) {
foreach (string param in params.split ("\"")) {
if (param.length > 0 && param != " ") {
filter_args += param.strip ();
}
}
}
prop_val = filters [filter].cb (ref prop_val, filter_args);
prop_val = filters[filter].cb (ref prop_val, filter_args);
} else {
print ("[ERROR] Filter %s doesn't exists.", filter);
}
......@@ -263,7 +261,6 @@ namespace Valse {
}
// we get zones in the template
Regex temp_zones_re = new Regex ("{% *zone (?P<zone>[[:graph:]]*) *%}");
MatchInfo temp_zones_info;
bool go_temp_zones = temp_zones_re.match (template, 0, out temp_zones_info);
......@@ -286,7 +283,6 @@ namespace Valse {
}
// Included files
Regex include_re = new Regex ("{% *include '(?P<file>.*)' *%}");
MatchInfo inc_info;
bool go_inc = include_re.match (result, 0, out inc_info);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment