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
242ece4b
Commit
242ece4b
authored
7 years ago
by
Jakob Olsson
Browse files
Options
Downloads
Patches
Plain Diff
some error handling, change on how to free after write_to_ubus, good or bad?
parent
d863f022
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
dongle_apn.c
+5
-0
5 additions, 0 deletions
dongle_apn.c
dongle_network.c
+7
-2
7 additions, 2 deletions
dongle_network.c
dongle_pin.c
+63
-30
63 additions, 30 deletions
dongle_pin.c
libmobile.c
+1
-1
1 addition, 1 deletion
libmobile.c
with
76 additions
and
33 deletions
dongle_apn.c
+
5
−
0
View file @
242ece4b
...
...
@@ -33,6 +33,7 @@ int list_apn_profiles(struct ubus_context *ctx, struct ubus_object *obj,
struct
json_object
*
apn_profiles
=
json_tokener_parse
(
response
);
write_to_ubus
(
apn_profiles
,
ctx
,
req
);
json_object_put
(
apn_profiles
);
return
0
;
}
...
...
@@ -50,6 +51,7 @@ int delete_apn_profile(struct ubus_context *ctx, struct ubus_object *obj,
struct
json_object
*
parsed_response
=
json_tokener_parse
(
response
);
write_to_ubus
(
parsed_response
,
ctx
,
req
);
json_object_put
(
parsed_response
);
free
(
response
);
return
0
;
}
...
...
@@ -68,6 +70,7 @@ int set_apn_profile(struct ubus_context *ctx, struct ubus_object *obj,
struct
json_object
*
parsed_response
=
json_tokener_parse
(
response
);
write_to_ubus
(
parsed_response
,
ctx
,
req
);
json_object_put
(
parsed_response
);
free
(
response
);
return
0
;
}
...
...
@@ -86,6 +89,7 @@ int create_apn_profile(struct ubus_context *ctx, struct ubus_object *obj,
struct
json_object
*
parsed_response
=
json_tokener_parse
(
response
);
write_to_ubus
(
parsed_response
,
ctx
,
req
);
json_object_put
(
parsed_response
);
free
(
response
);
return
0
;
...
...
@@ -100,6 +104,7 @@ int show_current_apn(struct ubus_context *ctx, struct ubus_object *obj,
struct
json_object
*
parsed_response
=
json_tokener_parse
(
wan_apn
);
write_to_ubus
(
parsed_response
,
ctx
,
req
);
json_object_put
(
parsed_response
);
free
(
wan_apn
);
return
0
;
}
...
...
This diff is collapsed.
Click to expand it.
dongle_network.c
+
7
−
2
View file @
242ece4b
...
...
@@ -25,9 +25,8 @@ int get_signal_strength(struct ubus_context *ctx, struct ubus_object *obj,
struct
json_object
*
parsed_response
=
json_tokener_parse
(
response
);
write_to_ubus
(
parsed_response
,
ctx
,
req
);
json_object_put
(
parsed_response
);
free
(
response
);
return
0
;
}
int
connect_network
(
struct
ubus_context
*
ctx
,
struct
ubus_object
*
obj
,
...
...
@@ -38,6 +37,7 @@ int connect_network(struct ubus_context *ctx, struct ubus_object *obj,
struct
json_object
*
parsed_response
=
json_tokener_parse
(
response
);
write_to_ubus
(
parsed_response
,
ctx
,
req
);
json_object_put
(
parsed_response
);
return
0
;
}
...
...
@@ -49,6 +49,7 @@ int disconnect(struct ubus_context *ctx, struct ubus_object *obj,
struct
json_object
*
parsed_response
=
json_tokener_parse
(
response
);
write_to_ubus
(
parsed_response
,
ctx
,
req
);
json_object_put
(
parsed_response
);
return
0
;
}
...
...
@@ -61,6 +62,7 @@ int modem_state(struct ubus_context *ctx, struct ubus_object *obj,
struct
json_object
*
parsed_response
=
json_tokener_parse
(
response
);
write_to_ubus
(
parsed_response
,
ctx
,
req
);
json_object_put
(
parsed_response
);
return
0
;
}
...
...
@@ -73,6 +75,7 @@ int enable_roaming(struct ubus_context *ctx, struct ubus_object *obj,
struct
json_object
*
parsed_response
=
json_tokener_parse
(
response
);
write_to_ubus
(
parsed_response
,
ctx
,
req
);
json_object_put
(
parsed_response
);
return
0
;
}
...
...
@@ -85,6 +88,7 @@ int disable_roaming(struct ubus_context *ctx, struct ubus_object *obj,
struct
json_object
*
parsed_response
=
json_tokener_parse
(
response
);
write_to_ubus
(
parsed_response
,
ctx
,
req
);
json_object_put
(
parsed_response
);
return
0
;
}
...
...
@@ -97,6 +101,7 @@ int roam_status(struct ubus_context *ctx, struct ubus_object *obj,
struct
json_object
*
parsed_response
=
json_tokener_parse
(
response
);
write_to_ubus
(
parsed_response
,
ctx
,
req
);
json_object_put
(
parsed_response
);
return
0
;
}
...
...
This diff is collapsed.
Click to expand it.
dongle_pin.c
+
63
−
30
View file @
242ece4b
...
...
@@ -70,52 +70,85 @@ int set_pin(struct ubus_context *ctx, struct ubus_object *obj,
{
struct
blob_attr
*
tb
[
__SET_PIN_MAX
];
char
new_pin
[
10
]
=
{
0
},
current_pin
[
10
]
=
{
0
};
int
rv
;
blobmsg_parse
(
set_pin_policy
,
__SET_PIN_MAX
,
tb
,
blob_data
(
msg
),
blob_len
(
msg
));
if
(
!
tb
[
NEW_PIN
]
&&
!
tb
[
CURRENT_PIN
])
{
printf
(
"Please enter both a new pin and old pin!"
);
printf
(
"Please enter both a new pin and old pin!
\n
"
);
goto
fail
;
}
strncpy
(
new_pin
,
(
char
*
)
blobmsg_data
(
tb
[
NEW_PIN
]),
9
);
strncpy
(
current_pin
,
(
char
*
)
blobmsg_data
(
tb
[
CURRENT_PIN
]),
9
);
validate_pin_format
(
new_pin
);
validate_pin_format
(
current_pin
);
printf
(
"new: %s, old: %s
\n
"
,
new_pin
,
current_pin
);
//char *response = mobile_get_request("pin_status");
rv
=
validate_pin_format
(
new_pin
);
if
(
rv
>
0
)
{
printf
(
"invalid pin
\n
"
);
goto
fail
;
}
rv
=
validate_pin_format
(
current_pin
);
if
(
rv
>
0
)
{
printf
(
"invalid pin
\n
"
);
goto
fail
;
}
char
*
response
=
mobile_get_pin_status
();
if
(
!
response
)
{
printf
(
"error getting pin_status
\n
"
);
goto
fail
;
}
struct
json_object
*
parsed_response
=
json_tokener_parse
(
response
);
struct
json_object
*
rv
;
struct
json_object
*
rv
_json
;
json_object_object_get_ex
(
parsed_response
,
"pin_status"
,
&
rv
);
if
(
!
json_object_get_int
(
rv
))
{
free
(
response
);
response
=
mobile_enable_pin
(
current_pin
);
json_object_object_get_ex
(
parsed_response
,
"pin_status"
,
&
rv_json
);
if
(
!
rv_json
)
{
printf
(
"no pin_status available
\n
"
);
goto
free_all
;
}
free
(
response
);
if
(
!
json_object_get_int
(
rv_json
))
{
json_object_put
(
parsed_response
);
response
=
mobile_enable_pin
(
current_pin
);
if
(
!
response
)
{
printf
(
"error enabling pin!
\n
"
);
goto
fail
;
}
parsed_response
=
json_tokener_parse
(
response
);
json_object_object_get_ex
(
parsed_response
,
"result"
,
&
rv
);
if
(
strncmp
(
json_object_get_string
(
rv
),
"failure"
,
strlen
(
"failure"
))
==
0
)
{
printf
(
"
Incorrect pin!
"
);
goto
print
;
json_object_object_get_ex
(
parsed_response
,
"result"
,
&
rv
_json
);
if
(
!
rv_json
)
{
printf
(
"
error getting result!
\n
"
);
goto
free_all
;
}
if
(
strncmp
(
json_object_get_string
(
rv_json
),
"failure"
,
strlen
(
"failure"
))
==
0
)
printf
(
"Incorrect pin!
\n
"
);
free
(
response
);
}
free
(
response
);
response
=
mobile_set_pin
(
current_pin
,
new_pin
);
json_object_put
(
parsed_response
);
response
=
mobile_set_pin
(
current_pin
,
new_pin
);
if
(
!
response
)
{
printf
(
"error setting pin!
\n
"
);
goto
fail
;
}
parsed_response
=
json_tokener_parse
(
response
);
json_object_object_get_ex
(
parsed_response
,
"result"
,
&
rv
);
if
(
strncmp
(
json_object_get_string
(
rv
),
"failure"
,
strlen
(
"failure"
))
==
0
)
{
printf
(
"
Incorrect
pin!"
);
goto
print
;
json_object_object_get_ex
(
parsed_response
,
"result"
,
&
rv
_json
);
if
(
!
rv_json
)
{
printf
(
"
no result available from set_
pin!"
);
goto
free_all
;
}
print:
write_to_ubus
(
parsed_response
,
ctx
,
req
);
fail:
free_all:
json_object_put
(
parsed_response
);
free
(
response
);
fail:
return
0
;
}
...
...
@@ -128,13 +161,12 @@ int disable_pin(struct ubus_context *ctx, struct ubus_object *obj,
blobmsg_parse
(
pin_policy
,
__PIN_MAX
,
tb
,
blob_data
(
msg
),
blob_len
(
msg
));
if
(
!
tb
[
PIN
])
{
printf
(
"Please enter
both a new pin and old pin!
"
);
printf
(
"Please enter
a pin!
\n
"
);
goto
fail
;
}
strncpy
(
pin
,
(
char
*
)
blobmsg_data
(
tb
[
PIN
]),
9
);
validate_pin_format
(
pin
);
//char *response = mobile_get_request("pin_status");
char
*
response
=
mobile_get_pin_status
();
struct
json_object
*
parsed_response
=
json_tokener_parse
(
response
);
struct
json_object
*
rv
;
...
...
@@ -146,7 +178,7 @@ int disable_pin(struct ubus_context *ctx, struct ubus_object *obj,
parsed_response
=
json_tokener_parse
(
response
);
json_object_object_get_ex
(
parsed_response
,
"result"
,
&
rv
);
if
(
strncmp
(
json_object_get_string
(
rv
),
"failure"
,
strlen
(
"failure"
))
==
0
)
{
printf
(
"Incorrect pin!"
);
printf
(
"Incorrect pin!
\n
"
);
goto
print
;
}
}
else
{
...
...
@@ -155,6 +187,7 @@ int disable_pin(struct ubus_context *ctx, struct ubus_object *obj,
print:
write_to_ubus
(
parsed_response
,
ctx
,
req
);
json_object_put
(
parsed_response
);
fail:
free
(
response
);
return
0
;
...
...
@@ -169,14 +202,13 @@ int enable_pin(struct ubus_context *ctx, struct ubus_object *obj,
blobmsg_parse
(
pin_policy
,
__PIN_MAX
,
tb
,
blob_data
(
msg
),
blob_len
(
msg
));
if
(
!
tb
[
PIN
])
{
printf
(
"Please enter both a new pin and old pin!"
);
printf
(
"Please enter both a new pin and old pin!
\n
"
);
goto
fail
;
}
strncpy
(
pin
,
(
char
*
)
blobmsg_data
(
tb
[
PIN
]),
9
);
validate_pin_format
(
pin
);
//char *response = mobile_get_request("pin_status");
char
*
response
=
mobile_get_pin_status
();
struct
json_object
*
parsed_response
=
json_tokener_parse
(
response
);
struct
json_object
*
rv
;
...
...
@@ -188,7 +220,7 @@ int enable_pin(struct ubus_context *ctx, struct ubus_object *obj,
parsed_response
=
json_tokener_parse
(
response
);
json_object_object_get_ex
(
parsed_response
,
"result"
,
&
rv
);
if
(
strncmp
(
json_object_get_string
(
rv
),
"failure"
,
strlen
(
"failure"
))
==
0
)
{
printf
(
"Incorrect pin!"
);
printf
(
"Incorrect pin!
\n
"
);
goto
print
;
}
}
else
{
...
...
@@ -197,6 +229,7 @@ int enable_pin(struct ubus_context *ctx, struct ubus_object *obj,
print:
write_to_ubus
(
parsed_response
,
ctx
,
req
);
json_object_put
(
parsed_response
);
fail:
free
(
response
);
return
0
;
...
...
@@ -211,7 +244,7 @@ int verify_pin(struct ubus_context *ctx, struct ubus_object *obj,
blobmsg_parse
(
pin_policy
,
__PIN_MAX
,
tb
,
blob_data
(
msg
),
blob_len
(
msg
));
if
(
!
tb
[
PIN
])
{
printf
(
"Please enter
both a new pin and old pi
n!"
);
printf
(
"Please enter
a pin
\
n
!"
);
goto
fail
;
}
strncpy
(
pin
,
(
char
*
)
blobmsg_data
(
tb
[
PIN
]),
9
);
...
...
@@ -221,6 +254,7 @@ int verify_pin(struct ubus_context *ctx, struct ubus_object *obj,
struct
json_object
*
parsed_response
=
json_tokener_parse
(
response
);
write_to_ubus
(
parsed_response
,
ctx
,
req
);
json_object_put
(
parsed_response
);
fail:
free
(
response
);
return
0
;
...
...
@@ -230,7 +264,6 @@ int remaining_tries(struct ubus_context *ctx, struct ubus_object *obj,
struct
ubus_request_data
*
req
,
const
char
*
method
,
struct
blob_attr
*
msg
)
{
//char *response = mobile_get_request("pinnumber");
char
*
response
=
mobile_get_pinnumber
();
struct
json_object
*
parsed_response
=
json_tokener_parse
(
response
);
...
...
This diff is collapsed.
Click to expand it.
libmobile.c
+
1
−
1
View file @
242ece4b
...
...
@@ -14,7 +14,7 @@ int write_to_ubus(struct json_object *parsed_response, struct ubus_context *ctx,
bb
=
json_to_blob
(
parsed_response
,
bb
);
ubus_send_reply
(
ctx
,
req
,
bb
.
head
);
blob_buf_free
(
&
bb
);
json_object_put
(
parsed_response
);
//
json_object_put(parsed_response);
return
0
;
}
...
...
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