-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deepstream 5.0 Subscription Implementation #1
base: master
Are you sure you want to change the base?
Changes from 6 commits
2e29abb
2a7a3d6
9a5bc7a
b2c6940
bf90453
67dffec
5ca5006
4821a94
adc30df
f8f0099
7aa84e7
9a8ff42
bd3310d
7e4b8d9
f2cd2b9
3707004
2fd20b1
072dfbb
93deacc
9c1449a
fa94cc3
525ee45
579d7b4
d330130
819cdc0
0bac762
ef454fb
9c61435
d9fa5a6
54fff91
c99d2de
0c7895e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,10 +33,12 @@ | |
#include "aws_config_parser.h" | ||
#include "nvds_msgapi.h" | ||
#include "aws_nvmsgbroker.h" | ||
#include <openssl/sha.h> | ||
|
||
NvDsMsgApiHandle (*nvds_msgapi_connect_ptr)(char *connection_str, nvds_msgapi_connect_cb_t connect_cb, char *config_path); | ||
NvDsMsgApiErrorType (*nvds_msgapi_send_ptr)(NvDsMsgApiHandle conn, char *topic, const uint8_t *payload, size_t nbuf); | ||
NvDsMsgApiErrorType (*nvds_msgapi_disconnect_ptr)(NvDsMsgApiHandle h_ptr); | ||
NvDsMsgApiErrorType (*nvds_msgapi_connection_signature_ptr)(char *connection_str, char *config_path, char *output_str, int max_len); | ||
static GMutex thread_mutex; | ||
static GQueue *work_queue; | ||
static struct timespec last_send_time_stamp; // this is to make sure we send or yield frequent enough so we do not get disconnected. | ||
|
@@ -353,3 +355,80 @@ void nvds_msgapi_do_work(NvDsMsgApiHandle h_ptr) | |
last_send_time_stamp = current_time_stamp; | ||
return; | ||
} | ||
|
||
char *nvds_msgapi_getversion() | ||
{ | ||
return (char *)NVDS_MSGAPI_VERSION; | ||
} | ||
|
||
char *nvds_msgapi_get_protocol_name() | ||
{ | ||
return (char *)NVDS_MSGAPI_PROTOCOL; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You shouldn't need to cast this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just clarifying on this, what should I return instead of this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's what you should return, you just don't need to add the explicit cast. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does that go for the get_version method as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes |
||
} | ||
|
||
bool is_valid_connection_str(char *connection_str, char *&burl, char *&bport) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What are these types? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are you providing |
||
{ | ||
if (connection_str == NULL) | ||
{ | ||
IOT_ERROR("connection string cant be NULL"); | ||
return false; | ||
} | ||
|
||
char conn_str[] = connection_str; | ||
int i = 0; | ||
|
||
char *token = strtok(conn_str, ";"); | ||
char *data[2]; | ||
|
||
while (token) | ||
{ | ||
data[i++] = token; | ||
token = strtok(NULL, ";"); | ||
} | ||
Comment on lines
+383
to
+390
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't think this will work properly. The second call to int i = 0;
char *data[2];
for (i = 0; i < 2; i++) {
data[i] = strtok(conn_str, ";");
} |
||
for (i = 0; i < 2; i++) | ||
{ | ||
printf("%s\n", data[i]); | ||
} | ||
char *burl = data[0]; | ||
char *bport = data[1]; | ||
|
||
if (burl == "" || bport == "") | ||
{ | ||
IOT_ERROR("connection string is invalid. hostname or port is empty\n"); | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
char *generate_sha256_hash(char *str) | ||
{ | ||
unsigned char hashval[SHA256_DIGEST_LENGTH]; | ||
int len = SHA256_DIGEST_LENGTH * 2 + 1; | ||
char res[len]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To remedy the problem, you should supply the output string as an argument to the function. Note: it will need to have space for at least 65 characters (which you'll need to add a check for). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The max_len is actually the length of the output_str and I have added a check in the connection signature to check if has at least 65 characters There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good, but you still need to resolve the issue of returning a statically allocated variable. res is created on the stack, not the heap, so its lifetime is only that of the enclosing scope. The value of res will be invalidated once this function returns. |
||
SHA256_CTX sha256; | ||
SHA256_Init(&sha256); | ||
SHA256_Update(&sha256, str, strlen(str)); | ||
SHA256_Final(hashval, &sha256); | ||
for (int i = 0; i < SHA256_DIGEST_LENGTH; i++) | ||
{ | ||
res + (i * 2), "%02x", hashval[i]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was this supposed to be a function call? |
||
} | ||
return res; | ||
} | ||
|
||
NvDsMsgApiErrorType nvds_msgapi_connection_signature(char *broker_str, char *cfg, char *output_str, int max_len) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
{ | ||
strcpy(output_str, ""); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As per the documentation, the output_str would give the required hash code if successful or return empty string if unsuccessful so just initializing it as empty string and then updating it with code if successful, please let me know if you require any changes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Shubhamturakhia Got it. Add a comment to explain this line but the code is good. |
||
if (broker_str == NULL || cfg == NULL) | ||
{ | ||
IOT_ERROR("nvds_msgapi_connection_signature: broker_str or cfg path cant be NULL\n"); | ||
return NVDS_MSGAPI_ERR; | ||
} | ||
char *burl = "", *bport = ""; | ||
if (!is_valid_connection_str(broker_str, burl, bport)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Always enclose conditional blocks with curly braces |
||
return NVDS_MSGAPI_ERR; | ||
|
||
char *aws_connection_signature = generate_sha256_hash(burl + bport); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you need to split the connection string in the first place? Couldn't you just supply the connection string on its own? Also, this is not how you concatenate strings in c. |
||
strcpy(output_str, aws_connection_signature); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why call |
||
return NVDS_MSGAPI_OK; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NVDS_MSGAPI_VERSION
is not a string literal, it's a float.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the documentation, this function returns a string that identifies the nvds_msgapi version, so I implemented according to that, please let me know if you need any changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's all fine—the issue was that the macro was of the incorrect type. I see it's now fixed.