On 03/06/16 21:06, Johannes Rudolph via Dev wrote:
Weil Tarek so gerne Patches mag ^^Direkt aus GitLab
Danke dir.
https://git.nordwest.freifunk.net/ffnw-firmware/packages/merge_requests/5.pa...
From 49eb9130b98adf459660391d719d41ec172252a9 Mon Sep 17 00:00:00 2001 From: Johannes Rudolph johannes.rudolph@gmx.com Date: Sun, 28 Feb 2016 17:30:04 +0100 Subject: [PATCH] Skip MESH BSSID: 02:CA:FF:EE:BA:BF
libwlocate/src/libwlocate.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/libwlocate/src/libwlocate.c b/libwlocate/src/libwlocate.c index 05ababc..8042213 100755 --- a/libwlocate/src/libwlocate.c +++ b/libwlocate/src/libwlocate.c @@ -54,10 +54,18 @@ WLOC_EXT_API int get_position(const char *domain,const struct wloc_req *request, { if (request->bssids[i][0]+request->bssids[i][1]+request->bssids[i][2]+request->bssids[i][3]+request->bssids[i][4]+request->bssids[i][5]>0) {
snprintf(data + strlen(data), 500 - strlen(data),
"%02X%02X%02X%02X%02X%02X\r\n",
request->bssids[i][0],request->bssids[i][1],request->bssids[i][2],
request->bssids[i][3],request->bssids[i][4],request->bssids[i][5]);
//Skip MESH BSSID: 02:CA:FF:EE:BA:BF
if( request->bssids[i][0] != 0x02
&& request->bssids[i][1] != 0xCA
&& request->bssids[i][2] != 0xFF
&& request->bssids[i][3] != 0xEE
&& request->bssids[i][4] != 0xBA
&& request->bssids[i][5] != 0xBE){
snprintf(data + strlen(data), 500 - strlen(data),
"%02X%02X%02X%02X%02X%02X\r\n",
request->bssids[i][0],request->bssids[i][1],request->bssids[i][2],
request->bssids[i][3],request->bssids[i][4],request->bssids[i][5]);
} snprintf(head,500,} }
-- libgit2 0.23.3
From ed3a77c0dc6763b0729bc409a94b218ab6dcee13 Mon Sep 17 00:00:00 2001 From: Johannes Rudolph johannes.rudolph@gmx.com Date: Wed, 2 Mar 2016 17:22:04 +0100 Subject: [PATCH] add get bssid
Weiter unten Wirde dieser code wieder entfernt.
libwlocate/src/getbssid.c | 166 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 166 insertions(+), 0 deletions(-) create mode 100644 libwlocate/src/getbssid.c
diff --git a/libwlocate/src/getbssid.c b/libwlocate/src/getbssid.c new file mode 100644 index 0000000..79d4aea --- /dev/null +++ b/libwlocate/src/getbssid.c @@ -0,0 +1,166 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <regex.h>
+/* The following is the size of a buffer to contain any error messages
- encountered when the regular expression is compiled. */
+#define MAX_ERROR_MSG 0x1000
+char* substr (const char* string, int pos, int len, const char* replace) +{
- char* substring;
- int i;
- int length;
- if (string == NULL)
return NULL;
- length = strlen(string);
- if (pos < 0) {
pos = length + pos;
if (pos < 0) pos = 0;
- }
- else if (pos > length) pos = length;
- if (len <= 0) {
len = length - pos + len;
if (len < 0) len = length - pos;
- }
- if (pos + len > length) len = length - pos;
- if (replace != NULL) {
if ((substring = malloc(sizeof(*substring)*(length-len+strlen(replace)+1))) == NULL)
return NULL;
for (i = 0; i != pos; i++) substring[i] = string[i];
pos = pos + len;
for (len = 0; replace[len]; i++, len++) substring[i] = replace[len];
for (; string[pos]; pos++, i++) substring[i] = string[pos];
substring[i] = '\0';
- }
- else {
if ((substring = malloc(sizeof(*substring)*(len+1))) == NULL)
return NULL;
len += pos;
for (i = 0; pos != len; i++, pos++)
substring[i] = string[pos];
substring[i] = '\0';
- }
- return substring;
+}
+/* Compile the regular expression described by "regex_text" into
- "r". */
+static int compile_regex (regex_t * r, const char * regex_text) +{
- int status = regcomp (r, regex_text, REG_EXTENDED|REG_NEWLINE);
- if (status != 0) {
- char error_message[MAX_ERROR_MSG];
- regerror (status, r, error_message, MAX_ERROR_MSG);
printf ("Regex error compiling '%s': %s\n",
regex_text, error_message);
return 1;
- }
- return 0;
+}
+/*
- Match the string in "to_match" against the compiled regular
- expression in "r".
- */
+static const char * match_regex (regex_t * r, const char * to_match) +{
- /* "P" is a pointer into the string which points to the end of the
previous match. */
- const char * p = to_match;
- char * dest;
- /* "N_matches" is the maximum number of matches allowed. */
- const int n_matches = 10;
- /* "M" contains the matches found. */
- regmatch_t m[n_matches];
- while (1) {
int i = 0;
int nomatch = regexec (r, p, n_matches, m, 0);
if (nomatch) {
printf ("No more matches.\n");
return "";
}
for (i = 0; i < n_matches; i++) {
int start;
int finish;
if (m[i].rm_so == -1) {
break;
}
start = m[i].rm_so + (p - to_match);
finish = m[i].rm_eo + (p - to_match);
if (i == 0) {
//printf ("$& is ");
//printf ("'%.*s' (bytes %d:%d)\n", (finish - start), to_match + start, start, finish);
}
else {
//printf ("$%d is ", i);
//printf ("'%.*s' (bytes %d:%d)\n", (finish - start), to_match + start, start, finish);
return substr(to_match, start, (finish - start), NULL);
}
}
p += m[0].rm_eo;
- }
- return "";
+}
+int main (int argc, const char * argv[]) +{
- regex_t r;
- const char * regex_text;
- const char * result;
- regex_text = ".*?option bssid '(.*)'";
- FILE *f = fopen("/etc/config/wireless", "rb");
- fseek(f, 0, SEEK_END);
- long fsize = ftell(f);
- fseek(f, 0, SEEK_SET);
- char *string = malloc(fsize + 1);
- fread(string, fsize, 1, f);
- fclose(f);
- string[fsize] = 0;
- //printf("%s",string);
- compile_regex(& r, regex_text);
- result = match_regex(& r, string);
- regfree (& r);
- printf("\n%s\n",result);
- /*char ch, file_name[25];
- char msgbuf[1000];
- FILE *fp;
- printf("Read file\n");
- fp = fopen("/etc/config/wireless","r"); // read mode
- if( fp == NULL )
- {
perror("Error while opening the file.\n");
exit(EXIT_FAILURE);
- }
- while( ( ch = fgetc(fp) ) != EOF )
printf("%c",ch);
- fclose(fp);
- return 0;*/
+} \ No newline at end of file -- libgit2 0.23.3
From 5ebf5c6265a12bdfc2e4df5497669996382e08fb Mon Sep 17 00:00:00 2001 From: Johannes Rudolph johannes.rudolph@gmx.com Date: Fri, 4 Mar 2016 13:02:50 +0100 Subject: [PATCH] make new function getBssid
So eine datei läst sich sehrgut in einen eigenen patch aus lagern. :) Das beschleuinigt den review prozesse stark.
libwlocate/src/getbssid.c | 80 ++++++++++++++++++++++++++++++++++---------------------------------------------- 1 file changed, 34 insertions(+), 46 deletions(-)
diff --git a/libwlocate/src/getbssid.c b/libwlocate/src/getbssid.c index 79d4aea..aee5bb2 100644 --- a/libwlocate/src/getbssid.c +++ b/libwlocate/src/getbssid.c @@ -113,54 +113,42 @@ static const char * match_regex (regex_t * r, const char * to_match) } return ""; }
-int main (int argc, const char * argv[]) -{
- regex_t r;
- const char * regex_text;
- const char * result;
- regex_text = ".*?option bssid '(.*)'";
- FILE *f = fopen("/etc/config/wireless", "rb");
- fseek(f, 0, SEEK_END);
- long fsize = ftell(f);
- fseek(f, 0, SEEK_SET);
- char *string = malloc(fsize + 1);
- fread(string, fsize, 1, f);
- fclose(f);
- string[fsize] = 0;
- //printf("%s",string);
- compile_regex(& r, regex_text);
+int * getMeshBssid (){ +printf("####");
- static int bssid[8];
- printf("####");
Wozu genau diehnen die 4 hasches in der Ausgaben ?
- regex_t r;
- const char * regex_text;
- const char * result;
- regex_text = ".*?option bssid '(.*)'";
- FILE *f = fopen("/etc/config/wireless", "rb");
- fseek(f, 0, SEEK_END);
- long fsize = ftell(f);
- fseek(f, 0, SEEK_SET);
- char *string = malloc(fsize + 1);
- fread(string, fsize, 1, f);
- fclose(f);
- string[fsize] = 0;
- printf("####");
- printf("%s",string);
- compile_regex(& r, regex_text); result = match_regex(& r, string); regfree (& r);
- printf("\n%s\n",result);
- /*char ch, file_name[25];
- char msgbuf[1000];
- FILE *fp;
- printf("Read file\n");
- fp = fopen("/etc/config/wireless","r"); // read mode
- if( fp == NULL )
- {
perror("Error while opening the file.\n");
exit(EXIT_FAILURE);
- }
- pintf("\n%s\n",result);
- return bssid;
+}
- while( ( ch = fgetc(fp) ) != EOF )
printf("%c",ch);
- fclose(fp);
- return 0;*/
+int main (int argc, const char * argv[]) +{
- printf("####");
- getMeshBssid();
} \ No newline at end of file -- libgit2 0.23.3
From 08ec56fb1302b3acfa39cc5a7f64efa62076e7ff Mon Sep 17 00:00:00 2001 From: Johannes Rudolph johannes.rudolph@gmx.com Date: Fri, 4 Mar 2016 13:03:16 +0100 Subject: [PATCH] remove debug
libwlocate/src/getbssid.c | 4 ---- 1 file changed, 0 insertions(+), 4 deletions(-)
diff --git a/libwlocate/src/getbssid.c b/libwlocate/src/getbssid.c index aee5bb2..37d0a76 100644 --- a/libwlocate/src/getbssid.c +++ b/libwlocate/src/getbssid.c @@ -115,9 +115,7 @@ static const char * match_regex (regex_t * r, const char * to_match) } int * getMeshBssid (){ -printf("####"); static int bssid[8];
- printf("####");
Ah hier werden die vier Hashes wieder entfernt. Das scheint wohl debug code zu sein.
Ich denke ich unterbreche an diese stelle mal.
Das was ich gelesen hab sah auf jeden fall schon mal gut aus allerdings. Ist den empfehlenswert einen Patch entsprechend zu reinigen so das letzlich nur der effektiv code über die liste geht. Das hat den Vorteil das der code entsprechend übersichtlicher und sauberer ist.
Das ist aus dem Merge request richtig?
Um einen guten patch zu erstellen kann ich dir git format-patch sehr empfehlen.
Falls interresse besteht. Hier sind ein paar gute anleitungen um patches zu erstellen:
https://www.kernel.org/doc/Documentation/SubmittingPatches
https://www.kernel.org/pub/software/scm/git/docs/git-format-patch.html
Um patches an die ML zu seinen kann man git send-mail nutzen. Dazu findest du u.a. hier was:
http://kernelnewbies.org/FirstKernelPatch
Schönen Gruß Tarek