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
3ccaacdf
Commit
3ccaacdf
authored
7 years ago
by
Jakob Olsson
Browse files
Options
Downloads
Patches
Plain Diff
move some functionality to lib_commons from library
parent
b9ae2668
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib_commons.c
+55
-0
55 additions, 0 deletions
lib_commons.c
lib_commons.h
+29
-0
29 additions, 0 deletions
lib_commons.h
with
84 additions
and
0 deletions
lib_commons.c
0 → 100644
+
55
−
0
View file @
3ccaacdf
/** @file libcommons.c */
#include
"lib_commons.h"
size_t
write_func
(
void
*
buffer
,
size_t
size
,
size_t
nmemb
,
void
*
data
)
{
struct
string
*
str
=
(
struct
string
*
)
data
;
size_t
len
=
size
*
nmemb
;
size_t
new_len
=
str
->
len
+
(
len
);
char
*
tmp_ptr
=
str
->
ptr
;
str
->
ptr
=
realloc
(
str
->
ptr
,
new_len
+
1
);
if
(
!
str
->
ptr
)
{
//debug_print("not enough memory (realloc returned NULL)\n");
free
(
tmp_ptr
);
return
0
;
}
memcpy
(
str
->
ptr
+
str
->
len
,
buffer
,
len
);
str
->
ptr
[
new_len
]
=
'\0'
;
str
->
len
=
new_len
;
return
len
;
}
struct
json_object
*
get_json_string_object_by_key
(
struct
json_object
*
json_obj
,
char
*
string
,
char
*
output_key
)
//"string" should be key?
{
struct
json_object_iter
iterator
;
struct
json_object
*
string_object
=
NULL
;
struct
json_object
*
jstring
=
NULL
;
enum
json_type
type
;
type
=
json_object_get_type
(
json_obj
);
if
(
type
==
json_type_object
)
// flow could be changed
{
//search the key from the json object
json_object_object_foreachC
(
json_obj
,
iterator
)
{
printf
(
"iteratorKey is :%s
\n
"
,
iterator
.
key
);
if
(
strcmp
(
string
,
(
char
*
)
iterator
.
key
)
==
0
)
// flow could be changed
{
//debug_print("Input string value: %s\n", (char *)json_object_get_string(iterator.val));
//debug_print("Input string key: %s\n", (char *)iterator.key);
string_object
=
json_object_new_object
();
json_object_object_add
(
string_object
,
output_key
,
iterator
.
val
);
//debug_print("The json object created: %sn", json_object_to_json_string(string_object));
break
;
}
}
}
return
string_object
;
// who is responsible for not leaking memory for scope of this function?
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
lib_commons.h
0 → 100644
+
29
−
0
View file @
3ccaacdf
#ifndef LIB_COMMON_H
#define LIB_COMMON_H
#include
<stdio.h>
#include
<stdlib.h>
#include
<string.h>
#include
<json-c/json.h>
/**
* Struct used for parsing the curl response from the dongle.
*/
struct
string
{
char
*
ptr
;
/*!< String for storage */
size_t
len
;
/*!< Length of stored string */
};
/**
* The callback function from performing the curl command, response from server will be reconstructed here.
*
* @param[in] buffer: Contains chunk of response from server.
* @param[in] size: Size (byte) of type in buffer array.
* @param[in] nmemb: Number of members in buffer.
* @param[out] data: Pointer to area allocated for storing results from server.
*
* @return Number of bytes managed (size*nmemb).
*/
size_t
write_func
(
void
*
buffer
,
size_t
size
,
size_t
nmemb
,
void
*
data
);
struct
json_object
*
get_json_string_object_by_key
(
json_object
*
json_obj
,
char
*
string
,
char
*
output_key
);
#endif
\ No newline at end of file
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