#endif /* BUFFER_MAX_PLANE_NUM */
#define BUFFER_MAX_PLANE_NUM 4
-#define CAMERA_PARSE_STRING_SIZE 20
+#define CAMERA_PARSED_STRING_NUM_MAX 20
#define CAMERA_CB_TIMEOUT 5
#define CAMERA_CB_TIMEOUT_LONG 8
/* message receive thread */
GThread *msg_recv_thread;
gint msg_recv_running;
- gchar recv_msg[MUSE_CAMERA_MSG_MAX_LENGTH];
+ gchar recv_msg[MUSE_CAMERA_MSG_MAX_LENGTH * CAMERA_PARSED_STRING_NUM_MAX];
GCond api_cond[MUSE_CAMERA_API_MAX];
GMutex api_mutex[MUSE_CAMERA_API_MAX];
gint api_activating[MUSE_CAMERA_API_MAX];
int num_token = 0;
int str_pos = 0;
int prev_pos = 0;
+ int msg_length = 0;
char *error_msg = NULL;
char *recv_msg = NULL;
char **parse_str = NULL;
LOGD("start");
- parse_str = (char **)malloc(sizeof(char *) * CAMERA_PARSE_STRING_SIZE);
+ parse_str = (char **)malloc(sizeof(char *) * CAMERA_PARSED_STRING_NUM_MAX);
if (parse_str == NULL) {
LOGE("parse_str malloc failed");
return NULL;
}
- for (i = 0 ; i < CAMERA_PARSE_STRING_SIZE ; i++) {
+ for (i = 0 ; i < CAMERA_PARSED_STRING_NUM_MAX ; i++) {
parse_str[i] = (char *)malloc(sizeof(char) * MUSE_CAMERA_MSG_MAX_LENGTH);
if (parse_str[i] == NULL) {
LOGE("parse_str[%d] malloc failed", i);
/*LOGD("recvMSg : %s, length : %d", recv_msg, ret);*/
/* Need to split the combined entering msgs.
- This module supports up to 200 combined msgs. */
+ This module supports up to 20 combined msgs. */
for (str_pos = 0; str_pos < ret; str_pos++) {
if (recv_msg[str_pos] == '}') {
- strncpy(parse_str[num_token], recv_msg + prev_pos, str_pos - prev_pos + 1);
- /*LOGD("splitted msg : [%s], Index : %d", parse_str[num_token], num_token);*/
+ msg_length = str_pos - prev_pos + 1;
+
+ if (msg_length < MUSE_CAMERA_MSG_MAX_LENGTH) {
+ strncpy(parse_str[num_token], recv_msg + prev_pos, msg_length);
+ parse_str[num_token][msg_length] = '\0';
+ num_token++;
+ /*LOGD("splitted msg : [%s], Index : %d", parse_str[num_token], num_token);*/
+ } else {
+ LOGW("too long message : length %d [%s]", msg_length, recv_msg + prev_pos);
+ }
+
prev_pos = str_pos + 1;
- num_token++;
+
+ if (num_token >= CAMERA_PARSED_STRING_NUM_MAX) {
+ LOGE("There's too many tokens. Remained msg : %s", recv_msg[++str_pos]);
+ break;
+ }
}
}
/* Re-construct to the useful single msg. */
for (i = 0; i < num_token; i++) {
- if (i >= CAMERA_PARSE_STRING_SIZE) {
+ if (i >= CAMERA_PARSED_STRING_NUM_MAX) {
LOGE("invalid token index %d", i);
break;
}
CB_HANDLER_EXIT:
if (parse_str) {
- for (i = 0 ; i < CAMERA_PARSE_STRING_SIZE ; i++) {
+ for (i = 0 ; i < CAMERA_PARSED_STRING_NUM_MAX ; i++) {
if (parse_str[i]) {
free(parse_str[i]);
parse_str[i] = NULL;