Weil Tarek so gerne Patches mag ^^Direkt aus GitLab
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
--- 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
--- 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("####"); + + 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("####");
regex_t r; const char * regex_text; @@ -134,7 +132,6 @@ printf("####"); fclose(f);
string[fsize] = 0; - printf("####"); printf("%s",string);
compile_regex(& r, regex_text); @@ -148,7 +145,6 @@ printf("####");
int main (int argc, const char * argv[]) { - printf("####"); getMeshBssid();
} \ No newline at end of file -- libgit2 0.23.3
From c5bcae2f6914392fe47bac793b48f2c533c95dba Mon Sep 17 00:00:00 2001 From: Johannes Rudolph johannes.rudolph@gmx.com Date: Fri, 4 Mar 2016 13:06:48 +0100 Subject: [PATCH] fix regex
--- libwlocate/src/getbssid.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/libwlocate/src/getbssid.c b/libwlocate/src/getbssid.c index 37d0a76..a96ab62 100644 --- a/libwlocate/src/getbssid.c +++ b/libwlocate/src/getbssid.c @@ -120,7 +120,7 @@ int * getMeshBssid (){ regex_t r; const char * regex_text; const char * result; - regex_text = ".*?option bssid '(.*)'"; + regex_text = ".*option bssid '(.*)'.*";
FILE *f = fopen("/etc/config/wireless", "rb"); fseek(f, 0, SEEK_END); @@ -138,7 +138,7 @@ int * getMeshBssid (){ result = match_regex(& r, string); regfree (& r);
- pintf("\n%s\n",result); + printf("\n%s\n",result);
return bssid; } -- libgit2 0.23.3
From b94954cf0abb6ac258f96e67d1d5e7a211c45245 Mon Sep 17 00:00:00 2001 From: Johannes Rudolph johannes.rudolph@gmx.com Date: Fri, 4 Mar 2016 13:27:41 +0100 Subject: [PATCH] finish function
--- libwlocate/src/getbssid | Bin 0 -> 9412 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100755 libwlocate/src/getbssid
diff --git a/libwlocate/src/getbssid b/libwlocate/src/getbssid new file mode 100755 index 0000000..9a43648 Binary files /dev/null and b/libwlocate/src/getbssid differ -- libgit2 0.23.3
From 90cd9e0ca46b040ae800c6ad6aac6bc3f422cc3d Mon Sep 17 00:00:00 2001 From: Johannes Rudolph johannes.rudolph@gmx.com Date: Fri, 4 Mar 2016 13:27:48 +0100 Subject: [PATCH] add header
--- libwlocate/src/getbssid.h | 7 +++++++ 1 file changed, 7 insertions(+), 0 deletions(-) create mode 100644 libwlocate/src/getbssid.h
diff --git a/libwlocate/src/getbssid.h b/libwlocate/src/getbssid.h new file mode 100644 index 0000000..3348f26 --- /dev/null +++ b/libwlocate/src/getbssid.h @@ -0,0 +1,7 @@ +#ifndef GETBSSID_H +#define GETBSSID_H + +extern int * getMeshBssid (); + +#endif + -- libgit2 0.23.3
From dfaea22ade894f915babe28086aad2b6378624d4 Mon Sep 17 00:00:00 2001 From: Johannes Rudolph johannes.rudolph@gmx.com Date: Fri, 4 Mar 2016 13:28:03 +0100 Subject: [PATCH] finish function
--- libwlocate/src/getbssid.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-)
diff --git a/libwlocate/src/getbssid.c b/libwlocate/src/getbssid.c index a96ab62..6d1bd5a 100644 --- a/libwlocate/src/getbssid.c +++ b/libwlocate/src/getbssid.c @@ -1,7 +1,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <regex.h> +#include <regex.h>
/* The following is the size of a buffer to contain any error messages encountered when the regular expression is compiled. */ @@ -132,19 +132,32 @@ int * getMeshBssid (){ 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 * str = strdup(result); + + char* tok; + tok = strtok(str, ":"); + + int number = (int)strtol(tok, NULL, 16); + bssid[0] = number; + for(int i = 1 ; i < 6 ; i++){ + tok = strtok(NULL, ":"); + int number = (int)strtol(tok, NULL, 16); + bssid[i] = number; + }
return bssid; }
int main (int argc, const char * argv[]) { - getMeshBssid(); + int* bssid = getMeshBssid(); + for(int i = 0; i < 6; i++){ + printf("%02x\n", bssid[i]); + }
} \ No newline at end of file -- libgit2 0.23.3
From 1b3c77f1fcdb34fa7850436fc316a6f108efccbb Mon Sep 17 00:00:00 2001 From: Johannes Rudolph johannes.rudolph@gmx.com Date: Fri, 4 Mar 2016 13:28:12 +0100 Subject: [PATCH] Revert "finish function"
--- libwlocate/src/getbssid | Bin 9412 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100755 libwlocate/src/getbssid
diff --git a/libwlocate/src/getbssid b/libwlocate/src/getbssid deleted file mode 100755 index 9a43648..0000000 Binary files a/libwlocate/src/getbssid and /dev/null differ -- libgit2 0.23.3
From 8a801cd39c57fe422aba4021c45391e980462af1 Mon Sep 17 00:00:00 2001 From: Johannes Rudolph johannes.rudolph@gmx.com Date: Fri, 4 Mar 2016 13:31:05 +0100 Subject: [PATCH] ignore Mesh BSSID
--- libwlocate/src/libwlocate.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/libwlocate/src/libwlocate.c b/libwlocate/src/libwlocate.c index 8042213..1a27ed2 100755 --- a/libwlocate/src/libwlocate.c +++ b/libwlocate/src/libwlocate.c @@ -31,6 +31,7 @@ #include "wlan.h" #include "assert.h" #include "errno.h" +#include "getbssid.h"
WLOC_EXT_API int get_position(const char *domain,const struct wloc_req *request,double *lat,double *lon,char *quality,short *ccode) @@ -39,6 +40,9 @@ WLOC_EXT_API int get_position(const char *domain,const struct wloc_req *request, char head[500+1]; char data[500+1]; char responseOK=0; + int* ownBssid; + + ownBssid = getMeshBssid();
setlocale(LC_ALL,"C"); sock=tcp_connect_to(domain); @@ -55,12 +59,12 @@ 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) { //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){ + if( request->bssids[i][0] != ownBssid[0] + && request->bssids[i][1] != ownBssid[1] + && request->bssids[i][2] != ownBssid[2] + && request->bssids[i][3] != ownBssid[3] + && request->bssids[i][4] != ownBssid[4] + && request->bssids[i][5] != ownBssid[5]){ 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], -- libgit2 0.23.3
From 7769ddeb0d21c096fb6097da6206544046571d9e Mon Sep 17 00:00:00 2001 From: Johannes Rudolph johannes.rudolph@gmx.com Date: Fri, 4 Mar 2016 13:31:28 +0100 Subject: [PATCH] remove main
--- libwlocate/src/getbssid.c | 9 --------- 1 file changed, 0 insertions(+), 9 deletions(-)
diff --git a/libwlocate/src/getbssid.c b/libwlocate/src/getbssid.c index 6d1bd5a..dd0d366 100644 --- a/libwlocate/src/getbssid.c +++ b/libwlocate/src/getbssid.c @@ -152,12 +152,3 @@ int * getMeshBssid (){
return bssid; } - -int main (int argc, const char * argv[]) -{ - int* bssid = getMeshBssid(); - for(int i = 0; i < 6; i++){ - printf("%02x\n", bssid[i]); - } - -} \ No newline at end of file -- libgit2 0.23.3
From 45f0f6c549323597e372fc4825d7e25b18bf811d Mon Sep 17 00:00:00 2001 From: Johannes Rudolph johannes.rudolph@gmx.com Date: Fri, 4 Mar 2016 22:18:10 +0100 Subject: [PATCH] fix if else
--- libwlocate/src/libwlocate.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/libwlocate/src/libwlocate.c b/libwlocate/src/libwlocate.c index 1a27ed2..abc3a9c 100755 --- a/libwlocate/src/libwlocate.c +++ b/libwlocate/src/libwlocate.c @@ -59,12 +59,17 @@ 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) { //Skip MESH BSSID: 02:CA:FF:EE:BA:BF - if( request->bssids[i][0] != ownBssid[0] - && request->bssids[i][1] != ownBssid[1] - && request->bssids[i][2] != ownBssid[2] - && request->bssids[i][3] != ownBssid[3] - && request->bssids[i][4] != ownBssid[4] - && request->bssids[i][5] != ownBssid[5]){ + if( request->bssids[i][0] == ownBssid[0] + && request->bssids[i][1] == ownBssid[1] + && request->bssids[i][2] == ownBssid[2] + && request->bssids[i][3] == ownBssid[3] + && request->bssids[i][4] == ownBssid[4] + && request->bssids[i][5] == ownBssid[5]){ + + //SKIP + + } + else { 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], -- libgit2 0.23.3
From c85496d2ea6f6ba75c384aa13a04b528f845c184 Mon Sep 17 00:00:00 2001 From: Johannes Rudolph johannes.rudolph@gmx.com Date: Sun, 6 Mar 2016 02:19:22 +0100 Subject: [PATCH] add missing objects file
--- libwlocate/src/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libwlocate/src/Makefile b/libwlocate/src/Makefile index c52fef5..1a7e9da 100755 --- a/libwlocate/src/Makefile +++ b/libwlocate/src/Makefile @@ -8,7 +8,7 @@ EXECUTABLE=libwlocate.so
LINK=$(CC) -shared -Wl,--no-as-needed
-OBJECTS = connect.o wlan.o libwlocate.o iwlist.o +OBJECTS = connect.o wlan.o libwlocate.o iwlist.o getbssid.o
default: $(EXECUTABLE)
-- libgit2 0.23.3
From 8caa32928fc8d26c674af8a9b650bc780c7a45c3 Mon Sep 17 00:00:00 2001 From: Johannes Rudolph johannes.rudolph@gmx.com Date: Sun, 6 Mar 2016 02:36:02 +0100 Subject: [PATCH] Fix getbssid.c:147:5: error: 'for' loop initial declarations are only allowed in C99 mode
--- libwlocate/src/getbssid.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/libwlocate/src/getbssid.c b/libwlocate/src/getbssid.c index dd0d366..12e8a9f 100644 --- a/libwlocate/src/getbssid.c +++ b/libwlocate/src/getbssid.c @@ -144,7 +144,8 @@ int * getMeshBssid (){
int number = (int)strtol(tok, NULL, 16); bssid[0] = number; - for(int i = 1 ; i < 6 ; i++){ + int i; + for(i = 1 ; i < 6 ; i++){ tok = strtok(NULL, ":"); int number = (int)strtol(tok, NULL, 16); bssid[i] = number; -- libgit2 0.23.3
Hi, alle!
On 06.03.2016, at 21:06, Johannes Rudolph via Dev dev@lists.ffnw.de wrote:
Weil Tarek so gerne Patches mag ^^Direkt aus GitLab
[..]
//Skip MESH BSSID: 02:CA:FF:EE:BA:BF
[..]
&& request->bssids[i][5] != 0xBE){
Ist mir grad aufgefallen: der Kommentar und der Code widersprechen sich. Was soll denn jetzt ignoriert werden 02CAFFEEBABE oder 02CAFFEEBABF? ^ ^
Vermutlich ein kleiner Tippfehler.
Andre
Moin
das war der "erste" Schuss dort hab ich es statisch gemacht
wenn du dir
https://git.nordwest.freifunk.net/ffnw-firmware/packages/merge_requests/5
anschaust siehst du, dass es nun dynamisch ausgelesen wird, in weiser vorraussicht auf die Hoods
Gruß
Johannes
Am 07.03.2016 um 08:32 schrieb Andre Dierker via Dev:
Hi, alle!
On 06.03.2016, at 21:06, Johannes Rudolph via Dev dev@lists.ffnw.de wrote:
Weil Tarek so gerne Patches mag ^^Direkt aus GitLab
[..]
//Skip MESH BSSID: 02:CA:FF:EE:BA:BF
[..]
&& request->bssids[i][5] != 0xBE){
Ist mir grad aufgefallen: der Kommentar und der Code widersprechen sich. Was soll denn jetzt ignoriert werden 02CAFFEEBABE oder 02CAFFEEBABF? ^ ^
Vermutlich ein kleiner Tippfehler.
Andre _______________________________________________ Dev mailing list Dev@lists.ffnw.de https://lists.ffnw.de/mailman/listinfo/dev
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