Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mdmngr
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
IOPSYS
mdmngr
Commits
a928df73
Commit
a928df73
authored
7 years ago
by
Jakob Olsson
Browse files
Options
Downloads
Patches
Plain Diff
internal calls static, add wrapper to prepare query
parent
2bf9c877
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
libmobile.c
+43
-17
43 additions, 17 deletions
libmobile.c
with
43 additions
and
17 deletions
libmobile.c
+
43
−
17
View file @
a928df73
...
@@ -3,10 +3,8 @@
...
@@ -3,10 +3,8 @@
* 1. Add parsing for displaying APN profiles available to make sense of them
* 1. Add parsing for displaying APN profiles available to make sense of them
* 2. Add more input options when creating APN profile
* 2. Add more input options when creating APN profile
* 3. Seperate "set default" and "apply" APN profiles (what is the difference anyway?)
* 3. Seperate "set default" and "apply" APN profiles (what is the difference anyway?)
* 4.
Make the APN parsed fields more dynamic
* 4.
Change way to seperate profile configurations? (i.e. currently 0: .., 1: .., n: ...)
*/
*/
#include
"libmobile.h"
#include
"libmobile.h"
struct
string
{
struct
string
{
...
@@ -14,11 +12,12 @@ struct string {
...
@@ -14,11 +12,12 @@ struct string {
size_t
len
;
size_t
len
;
};
};
void
curl_cleaner
(
CURLcode
*
curl
);
static
void
curl_cleaner
(
CURLcode
*
curl
);
size_t
write_func
(
void
*
buffer
,
size_t
size
,
size_t
nmemb
,
void
*
userp
);
static
size_t
write_func
(
void
*
buffer
,
size_t
size
,
size_t
nmemb
,
void
*
userp
);
int
apn_profile_idx
(
struct
json_object
*
apn_profiles
,
char
*
name
);
static
int
apn_profile_idx
(
struct
json_object
*
apn_profiles
,
char
*
name
);
int
get_apn_profiles_len
(
void
);
static
int
get_apn_profiles_len
(
void
);
char
*
lexer
(
char
**
input
,
char
*
delimiter
);
static
char
*
lexer
(
char
**
input
,
char
*
delimiter
);
static
char
*
get_query_wrapper
(
char
*
vars
);
/**
/**
* Function: curl_cleaner
* Function: curl_cleaner
...
@@ -28,7 +27,7 @@ char *lexer(char **input, char *delimiter);
...
@@ -28,7 +27,7 @@ char *lexer(char **input, char *delimiter);
* Parameters:
* Parameters:
* curl - The curl easy handle variable.
* curl - The curl easy handle variable.
*/
*/
void
curl_cleaner
(
CURLcode
*
curl
)
static
void
curl_cleaner
(
CURLcode
*
curl
)
{
{
curl_easy_cleanup
(
curl
);
curl_easy_cleanup
(
curl
);
curl_global_cleanup
();
curl_global_cleanup
();
...
@@ -48,7 +47,7 @@ void curl_cleaner(CURLcode *curl)
...
@@ -48,7 +47,7 @@ void curl_cleaner(CURLcode *curl)
* Returns:
* Returns:
* Number of bytes managed (size*nmemb).
* Number of bytes managed (size*nmemb).
*/
*/
size_t
write_func
(
void
*
buffer
,
size_t
size
,
size_t
nmemb
,
void
*
userp
)
static
size_t
write_func
(
void
*
buffer
,
size_t
size
,
size_t
nmemb
,
void
*
userp
)
{
{
struct
string
*
str
=
(
struct
string
*
)
userp
;
struct
string
*
str
=
(
struct
string
*
)
userp
;
size_t
new_len
=
str
->
len
+
(
size
*
nmemb
);
size_t
new_len
=
str
->
len
+
(
size
*
nmemb
);
...
@@ -78,7 +77,7 @@ size_t write_func(void *buffer, size_t size, size_t nmemb, void *userp)
...
@@ -78,7 +77,7 @@ size_t write_func(void *buffer, size_t size, size_t nmemb, void *userp)
* Index of the APN on success.
* Index of the APN on success.
* -1 on failure.
* -1 on failure.
*/
*/
int
apn_profile_idx
(
struct
json_object
*
apn_profiles
,
char
*
name
)
static
int
apn_profile_idx
(
struct
json_object
*
apn_profiles
,
char
*
name
)
{
{
int
idx
=
0
;
int
idx
=
0
;
json_object_object_foreach
(
apn_profiles
,
key
,
val
)
{
json_object_object_foreach
(
apn_profiles
,
key
,
val
)
{
...
@@ -105,7 +104,7 @@ int apn_profile_idx(struct json_object *apn_profiles, char *name)
...
@@ -105,7 +104,7 @@ int apn_profile_idx(struct json_object *apn_profiles, char *name)
* Number of APN profiles available on success.
* Number of APN profiles available on success.
* -1 on failure.
* -1 on failure.
*/
*/
int
get_apn_profiles_len
(
void
)
static
int
get_apn_profiles_len
(
void
)
{
{
char
*
response
=
mobile_get_apn_profiles
();
char
*
response
=
mobile_get_apn_profiles
();
...
@@ -157,7 +156,7 @@ success:
...
@@ -157,7 +156,7 @@ success:
* Will alter the input string and allocate memory for the return value!
* Will alter the input string and allocate memory for the return value!
* The caller is responsible for freeing the return value.
* The caller is responsible for freeing the return value.
*/
*/
char
*
lexer
(
char
**
input
,
char
*
delimiter
)
{
static
char
*
lexer
(
char
**
input
,
char
*
delimiter
)
{
if
(
strlen
(
*
input
)
==
0
)
{
if
(
strlen
(
*
input
)
==
0
)
{
printf
(
"empty input!
\n
"
);
printf
(
"empty input!
\n
"
);
return
NULL
;
return
NULL
;
...
@@ -440,17 +439,43 @@ fail:
...
@@ -440,17 +439,43 @@ fail:
return
NULL
;
return
NULL
;
}
}
char
*
mobile_get_request
(
char
*
vars
)
/**
* Function: get_query_wrapper
* Wraps the input comma-separated values to the appropriate address format for a GET request.
*
* Parameters:
* vars - Char pointer pointing to comma-separated values to retreive.
*
* Returns:
* The entire query on success.
* NULL on failure.
*/
char
*
get_query_wrapper
(
char
*
vars
)
{
{
CURL
*
curl
;
if
(
strlen
(
vars
)
==
0
)
{
CURLcode
res
;
printf
(
"No GET input provided!
\n
"
);
struct
string
str
;
return
NULL
;
}
char
query
[
1024
]
=
{
0
};
char
query
[
1024
]
=
{
0
};
strncpy
(
query
,
"http://192.168.0.1/goform/goform_get_cmd_process?isTest=false&cmd="
,
1023
);
strncpy
(
query
,
"http://192.168.0.1/goform/goform_get_cmd_process?isTest=false&cmd="
,
1023
);
strncat
(
query
+
strlen
(
query
),
vars
,
1023
);
strncat
(
query
+
strlen
(
query
),
vars
,
1023
);
strncat
(
query
+
strlen
(
query
),
"&multi_data=1"
,
1023
);
strncat
(
query
+
strlen
(
query
),
"&multi_data=1"
,
1023
);
return
strdup
(
query
);
}
char
*
mobile_get_request
(
char
*
vars
)
{
CURL
*
curl
;
CURLcode
res
;
struct
string
str
;
char
*
query
=
get_query_wrapper
(
vars
);
if
(
!
query
)
goto
fail
;
str
.
ptr
=
calloc
(
1
,
1
);
str
.
ptr
=
calloc
(
1
,
1
);
str
.
len
=
0
;
str
.
len
=
0
;
curl
=
curl_easy_init
();
curl
=
curl_easy_init
();
...
@@ -466,6 +491,7 @@ char *mobile_get_request(char *vars)
...
@@ -466,6 +491,7 @@ char *mobile_get_request(char *vars)
}
}
}
}
free
(
query
);
curl_cleaner
(
curl
);
curl_cleaner
(
curl
);
return
str
.
ptr
;
return
str
.
ptr
;
fail:
fail:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment