From 279c7eafe70c5aa6d9621ff772482e66fe1eaece Mon Sep 17 00:00:00 2001 From: Sung-jae Park Date: Wed, 9 Sep 2015 18:27:06 +0900 Subject: [PATCH] Revise the some codes. Every DB management codes should be updated. Static functions in tg_common.h should be removed. Those functions should be relocated to corresponding implementations files. Change-Id: I0f89162935a162514a632ffdd1ccb7d1d8885c74 --- TelegramTizen/.sdk_delta.info | Bin 7141 -> 0 bytes TelegramTizen/db_manager/tg_db_manager.c | 517 ++++++++++++++++++++++---- TelegramTizen/db_manager/tg_db_manager.h | 6 +- TelegramTizen/inc/contact_selection_view.h | 1 - TelegramTizen/src/contact_selection_view.c | 12 +- TelegramTizen/src/group_chat_entry_view.c | 10 + TelegramTizen/src/telegramtizen.c | 6 - TelegramTizen/src/tg_buddy_list.c | 13 +- TelegramTizen/src/tg_chat_conv_view.c | 4 +- TelegramTizen/src/tg_db_wrapper.c | 20 +- TelegramTizen/src/tg_init_screen.c | 11 + TelegramTizen/src/tg_messaging_view.c | 31 +- TelegramTizen/src/tg_start_messaging_view.c | 23 +- TelegramTizen/src/tg_user_main_view.c | 23 +- TelegramTizen/tg_utils/tg_common.h | 250 ++++++------- tg-engine-service/.sdk_delta.info | Bin 5827 -> 0 bytes tg-engine-service/db_manager/tg_db_manager.c | 6 +- tg-engine-service/res/res.xml | 2 + tg-engine-service/src/server_response.c | 4 +- tg-engine-service/src/tg_db_wrapper.c | 287 +++++++------- tg-engine-service/tg_engine/tg_engine.c | 28 +- tg-engine-service/tg_engine_utils/tg_common.h | 4 +- 22 files changed, 835 insertions(+), 423 deletions(-) delete mode 100644 TelegramTizen/.sdk_delta.info delete mode 100644 tg-engine-service/.sdk_delta.info create mode 100644 tg-engine-service/res/res.xml diff --git a/TelegramTizen/.sdk_delta.info b/TelegramTizen/.sdk_delta.info deleted file mode 100644 index 0e352a113c8602e8813ac7260f704316634b5419..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 7141 zcmai3Yj9Op72fv-aEAmENO-n9l!rjc5ei~jtdv+{K!RLIYc1;OeVp8!a9^Br!XwkM z>5SA&nW+pq3|Lgg@dxGAS~@LQD5+6PQDQA4eTd3v2hkZFDs5~1T=LX6ed;Xl?jz4GLGARv4)9+mzp z#yVDM#B)xz(~5gQj|hbY`sJT)I7bM68^#6ly_vDmhP6GHb-dPS4)8F+n@%6xCn57O zLa7pN6wR$!G6k^F1m&~E+)lzZ6IRNLVvbsx`{vY0jv#fLFtuDn{ZYnh3^%cv;D()P z&z9nF;40oDe)W$S8)>+9(sxVPUue^7om?7lj7IU~$1B(vBOT4y?Uw5qURtcR$R2(i z_I#6AqsPF}(Jrqe>of=rQLoFfjP2=^PHgSBH4!u7^V3WC&E(#Z)a=~JJLZd)6J6-JV2v(PWTf!uG)b0sLXWcS!g@`ms^O{JO?`9UB(UX1r+JbImT#PKmWh$F>jdl#Y#@AVuOCd49w# zjf*^wU^qpbwhUu+N<~8=*5GR~v;e=5xZFw6UO1RLLKl+Oz(;8B?>kZ3<%L3+Q z#wGjGR>}89#^w$`lf9&IS>aTtKKjXZqVu0&q}^d05mDh-TC_Cf)9`DA z7f=2W%CME_v@}oVfe&fGO`~q@Nz}|B=8;mh$`@udmouOx?|>ktShuM6(&}zFV`4yx zcSJp;OJ-{!HOR5h&))}itZ!rJr3%I-2UOqrCQ{kX6p}T)!tqM4q3b2GV1$c=k;He+tJt!;&YKeyJOKh*cjKv}5oS6I5rW52FtGdk-+ zD#+kJgGIg$ZMnkOl!Ud_j*D6-E1OJbojuSS=!70Ap}t?Eb|jr_SI+dq!^(Khj^XSD zKH$CzdtJ-fYB{E3ZRx^k>z2_7WWYj=traZa;FJxGI!RmPUqMled{@*Fy%Ol0;1CM0 zI;-@s@TxwlJ+ZDtVuvXTs?O2eA&b7y*7q8UH|kZ8D#N(~SSg{t^Ff{4<{&vOr;IM( z0?u#XdgyAm9oK^cld#Zb&{4BBxCV$j@BzEZEqm^3pN+q9;B~q7{aSw zRvNIi*yhTOE6oj-=w?eM@dE*xaU^t!L!Wxc_QBiN6Et!(Pl+5GRq7BI^N#vQb zZG*2>+I#a~^Q6}2FsgOFSe9E_FLWu1z+XdJ4%yDXdV>>)Q>Wtp;QPZvTL{f5{ii!~ zlJf(MBjx*Ff^<}sP&2Fl#oKBnZa>Bm@*U|_VQ0kLOxlzGFq%df@#NEM%9eOdi8INO zoIMs^aH1EcujNn2Opm# z?h#REq`gP}h6SU@pfxlExSkZvU-R4|0&{T)OW~g>aUS?A3Z;SY8L2`b)mLog^y2eC zBP~cRZ=w0QR4IP(#YN|Vww9*z*AGd~T#RxpLaFFQwevvJ^Ifz3Ey=;$D$Y5|NQv`6 z;|+ZK#J$9;6nq(gl^+KIsLlhQL+(4(v2;6e_?;Lh$oEIeo(J06Vhg&j5We|a80FfU zpVZF-&AcU>X6}>IFQHL9`O*^SK>=%%+Fu}*@XwYy4>VfscTV>aSU{EVWiT^k$4VyF zOof6`pF|+Y?_zvqwu{S$($^HCAjv|+(e0|fyeMlCSxWefaK0}u0)9%tV8yJFMSZrY z3H21i^T%(#PGG)5Bi*a_yFv4SepjRJJm0S(3~<&+^s0^J`|Lcqb>H0!KO_QQNuzl3 zCS9-IXKU0SxAiJ2;7a%xMFPyl&tYtooyMo4|0P6@H0Hk7OVjc% zsOe$bib8pKZ>SOX3Wc&aodTfENP#-jokUnTIq_5gJ8+HyNC#`iAU3x6K&A8R&kc> zew{R&`$L{{?oD4;CT>An#?0aC-7WA%%fA~!J;d947meb%7aeDnpTqE8LD;=HZJyL4 z)}e&AqHd)zIl>g585y-88Rh${PxKH}0G04{sHJH)Y1*)?BkN^{?(g8`8;2wfP$m2; zSd*Y-yS#F|#(9zltP;K+{>yH@wI5`+EqHsEBmA6fEK4V5f$LhmJ1;y;lZ&a9@Cekn zR@5n#fvsNSiffVsoD#kP-9KV3QJk}_m;SMoO9oI%I7()Xo5tnej$)1;;J_*2ZE&2% zDUs*z4o)Vtz$)SQqu{w6QO6QDs>O}r3lsf8l#2I!?ior}aR^ z_a#d-Axyey3<7)T4TMH&c>4Tynx21-M)Bm02)e@a(l?JBbF=n_go-YPy+l7Izb`li z9jB(}?CdFW3&h+^W_k5l1S&W|6G1l+8gJn7l&lPuZ-a;1Rw4B#NEdEeRmbUb$iDtF zhx>dOxTkkAf@T*BsS5PEFOW&2Nw<#ziraF~TpG=s2}S z?ds_6B^t->uu1e@d9hT-snLu%$JR^Q=V=sAeh>b^hr#{6Oqer!&PnhB4SYw4RSAdV z? +#include #include +int errno; + sqlite3* create_database(char* database_name) { if(!database_name) { @@ -388,7 +391,7 @@ Eina_List* get_values_from_table_sync_order_by(sqlite3* db, const char* table_na free(row_cnt_qry); if(no_of_rows <= 0) { - return EINA_FALSE; + return NULL; } /********************************/ @@ -474,7 +477,7 @@ Eina_List* get_values_from_table_sync_order_by(sqlite3* db, const char* table_na *val_int = temp; row_vals = eina_list_append(row_vals, val_int); } else if(!strcmp(col_type, "TEXT") || !strcmp(col_type, "TEXT PRIMARY KEY NOT NULL")) { - char* val_text = strdup(sqlite3_column_text(stmt, col)); + char* val_text = strdup((const char *)sqlite3_column_text(stmt, col)); row_vals = eina_list_append(row_vals, val_text); } } @@ -488,120 +491,472 @@ Eina_List* get_values_from_table_sync_order_by(sqlite3* db, const char* table_na Eina_List* get_values_from_table_sync(sqlite3* db, const char* table_name, Eina_List* column_names, Eina_List* column_types, const char* where_clause) { - Eina_List* query_vals = NULL; + sqlite3_stmt *stmt; + const char *name; + int query_len; + Eina_List *l; + Eina_List *result = NULL; + char *query; + char *ptr; + int ret; + const char *type; + int col; - if (!db || !table_name) { + if (!db || !table_name || !column_names) { return NULL; } - /*****No rows identification*****/ + query_len = strlen("SELECT "); + EINA_LIST_FOREACH(column_names, l, name) { + query_len += strlen(name) + 2; /* ", " */ + } - char* row_cnt_qry = (char*)malloc(strlen("SELECT COUNT(*) FROM ") + strlen(table_name) + strlen(";") +1); - strcpy(row_cnt_qry, "SELECT COUNT(*) FROM "); - strcat(row_cnt_qry, table_name); - strcat(row_cnt_qry, ";"); + query_len += strlen(" FROM "); + query_len += strlen(table_name) + 1; + query_len += (where_clause ? strlen(where_clause) : 0); + query_len += 2; - int no_of_rows = 0; - //ret = sqlite3_exec(db,var_query, callback,(void*)db, &err_msg); + query = malloc(query_len); + if (!query) { + return NULL; + } - sqlite3_stmt *stmt; - if (sqlite3_prepare_v2(db, row_cnt_qry, -1, &stmt, NULL) == SQLITE_OK) { - if (sqlite3_step(stmt) == SQLITE_ERROR) { - no_of_rows = 0; - } else { - no_of_rows = sqlite3_column_int(stmt, 0); + strcpy(query, "SELECT "); + ptr = query +strlen("SELECT "); + + if (column_names) { + EINA_LIST_FOREACH(column_names, l, name) { + ptr += sprintf(ptr, "%s, ", name); } - sqlite3_finalize(stmt); + ptr -= 2; /* Delete last two characters, ", " */ + } else { + strcpy(ptr, "*"); + ptr++; } - free(row_cnt_qry); - if(no_of_rows <= 0) { - return EINA_FALSE; - } + ptr += sprintf(ptr, " FROM %s %s;", table_name, where_clause ? where_clause : ""); - /********************************/ + LOGD("Query: %s", query); - int ret = 0 ; - char* err_msg = 0; - //int col_count = eina_list_count(column_names); + ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL); + free(query); + if (ret != SQLITE_OK) { + return NULL; + } - int str_len = strlen("SELECT ") + 1; - char* var_query = (char*)malloc(str_len); - strcpy(var_query,"SELECT "); - if(!column_names) { - var_query = realloc(var_query, strlen(var_query) + 3); - strcat(var_query, "* "); - } else { + l = column_types; + col = 0; + while(sqlite3_step(stmt) == SQLITE_ROW) { + type = eina_list_data_get(l); + if (!strncmp(type, "INTEGER", strlen("INTEGER"))) { + int temp; + int *val; + + temp = sqlite3_column_int64(stmt, col); + val = malloc(sizeof(int)); + if (!val) { + /** + * @todo + * Handling exceptional cases. + */ + } + *val = temp; - int col_count = eina_list_count(column_names); - char* col_name = NULL; - for(int col = 0; col < col_count ; col++) { - col_name = eina_list_nth(column_names, col); - var_query = realloc(var_query, strlen(var_query)+strlen(col_name) + 1); - strcat(var_query, col_name); - col_name = NULL; - var_query = realloc(var_query, strlen(var_query)+strlen(" ") + 1); + result = eina_list_append(result, val); + } else if (!strncmp(type, "TEXT", strlen("TEXT"))) { + char *val; + const char *text; - if(col < col_count - 1){ - var_query = realloc(var_query, strlen(var_query) + 3); - strcat(var_query, ", "); + text = (const char *)sqlite3_column_text(stmt, col); + if (!text || text[0] == '\0') { + val = strdup("_null_"); } else { - var_query = realloc(var_query, strlen(var_query) + 2); - strcat(var_query, " "); + val = strdup(text); } + if (!val) { + /** + * @todo + * Handling exceptional cases + */ + } + + result = eina_list_append(result, val); } + l = eina_list_next(l); + col++; } - var_query = realloc(var_query, strlen(var_query) + strlen("FROM ") + 2); - strcat(var_query, "FROM "); - var_query = realloc(var_query, strlen(var_query) + strlen(table_name) + 1); - strcat(var_query, table_name); + sqlite3_finalize(stmt); + return result; +} - if (where_clause) { - var_query = realloc(var_query, strlen(var_query)+strlen(" WHERE ") + 1); - strcat(var_query, " WHERE "); - var_query = realloc(var_query, strlen(var_query)+strlen(where_clause) + 1); - strcat(var_query, where_clause); + +Eina_Bool close_database(sqlite3* db) +{ + if(db) { + sqlite3_close(db); + return EINA_TRUE; } + return EINA_FALSE; +} - var_query = realloc(var_query, strlen(var_query) + 2); - strcat(var_query, ";"); +Eina_List *tg_db_get_user_info(sqlite3 *db, tgl_peer_id_t *user_id) +{ + user_data_s *info; + Eina_List *result; + sqlite3_stmt *stmt; + int ret; + const char *val_text; + + ret = sqlite3_prepare_v2(db, "SELECT " \ + "print_name, structure_version, " \ + "photo_path, photo_id, " \ + "first_name, last_name, " \ + "phone, access_hash, " \ + "real_first_name, real_last_name, " \ + "username, online, last_seen " \ + "FROM user_info_table WHERE user_id = ?", -1, &stmt, NULL); + if (ret != SQLITE_OK) { + return NULL; + } - ret = sqlite3_prepare_v2(db, var_query, -1, &stmt, 0); - if( ret != SQLITE_OK ){ - sqlite3_free(err_msg); + ret = sqlite3_bind_int(stmt, 1, user_id->id); + if (ret != SQLITE_OK) { + sqlite3_finalize(stmt); return NULL; } - while(sqlite3_step(stmt) == SQLITE_ROW) { - int col_val_count = eina_list_count(column_names); - Eina_List* row_vals = NULL; - for(int col = 0; col < col_val_count ; col++) { - char* col_type = eina_list_nth(column_types, col); - if(!strcmp(col_type, "INTEGER") || !strcmp(col_type, "INTEGER PRIMARY KEY NOT NULL")) { - int temp = sqlite3_column_int64(stmt, col); - int* val_int = (int*)malloc(sizeof(int)); - *val_int = temp; - row_vals = eina_list_append(row_vals, val_int); - } else if(!strcmp(col_type, "TEXT") || !strcmp(col_type, "TEXT PRIMARY KEY NOT NULL")) { - char* val_text = strdup(sqlite3_column_text(stmt, col)); - row_vals = eina_list_append(row_vals, val_text); + result = NULL; + while (sqlite3_step(stmt) == SQLITE_ROW) { + info = calloc(1, sizeof(*info)); + if (!info) { + /** + * @todo + * Handling the OOM + */ + LOGE("calloc: %d", errno); + continue; + } + + val_text = (const char *)sqlite3_column_text(stmt, 0); + if (val_text && val_text[0] != '\0') { + info->print_name = strdup(val_text); + if (!info->print_name) { + LOGE("strdup: %d", errno); } } - query_vals = eina_list_append(query_vals, row_vals); + + info->structure_version = sqlite3_column_int(stmt, 1); + val_text = (const char *)sqlite3_column_text(stmt, 2); + if (val_text && val_text[0] != '\0') { + info->photo_path = strdup(val_text); + if (!info->photo_path) { + LOGE("strdup: %d", errno); + } + } + + info->photo_id = sqlite3_column_int(stmt, 3); + + val_text = (const char *)sqlite3_column_text(stmt, 4); + if (val_text && val_text[0] != '\0') { + info->first_name = strdup(val_text); + if (!info->first_name) { + LOGE("strdup: %d", errno); + } + } + + val_text = (const char *)sqlite3_column_text(stmt, 5); + if (val_text && val_text[0] != '\0') { + info->last_name = strdup(val_text); + if (!info->last_name) { + LOGE("strdup: %d", errno); + } + } + + val_text = (const char *)sqlite3_column_text(stmt, 6); + if (val_text && val_text[0] != '\0') { + info->phone = strdup(val_text); + if (!info->phone) { + LOGE("strdup: %d", errno); + } + } + + info->access_hash = sqlite3_column_int(stmt, 7); + + val_text = (const char *)sqlite3_column_text(stmt, 8); + if (val_text && val_text[0] != '\0') { + info->real_first_name = strdup(val_text); + if (!info->real_first_name) { + LOGE("strdup: %d", errno); + } + } + + val_text = (const char *)sqlite3_column_text(stmt, 9); + if (val_text && val_text[0] != '\0') { + info->real_last_name = strdup(val_text); + if (!info->real_last_name) { + LOGE("strdup: %d", errno); + } + } + + val_text = (const char *)sqlite3_column_text(stmt, 10); + if (val_text && val_text[0] != '\0') { + info->username = strdup(val_text); + if (!info->username) { + LOGE("strdup: %d", errno); + } + } + + info->online = sqlite3_column_int(stmt, 11); + info->last_seen = sqlite3_column_int(stmt, 12); + + memcpy(&info->user_id, user_id, sizeof(*user_id)); + + result = eina_list_append(result, info); } - free(var_query); - return query_vals; + sqlite3_finalize(stmt); + return result; } -Eina_Bool close_database(sqlite3* db) +Eina_List *tg_db_get_chat_info(sqlite3 *db, const char *table_name) { - if(db) { - sqlite3_close(db); - return EINA_TRUE; + Eina_List *result = NULL; + tg_chat_info_s *info; + sqlite3_stmt *stmt; + const char *tmp; + int ret; + + ret = sqlite3_prepare_v2(db, "SELECT chat_id, " \ + "flags, print_title, struct_version, " \ + "photo_id, photo_path, " \ + "title, " \ + "users_num, user_list_size, user_list_version, " \ + "inviter_id, chat_users, date, version, admin_id FROM ?", -1, &stmt, NULL); + + if (ret != SQLITE_OK) { + LOGE("Failed to create a stmt"); + return NULL; } - return EINA_FALSE; + + ret = sqlite3_bind_text(stmt, 1, table_name, -1, SQLITE_TRANSIENT); + if (ret != SQLITE_OK) { + LOGE("Failed to bind a text"); + return NULL; + } + + while (sqlite3_step(stmt) == SQLITE_ROW) { + info = calloc(1, sizeof(*info)); + if (!info) { + LOGE("calloc: %d", errno); + continue; + } + info->chat_id = sqlite3_column_int(stmt, 0); + info->flags = sqlite3_column_int(stmt, 1); + tmp = (const char *)sqlite3_column_text(stmt, 2); + if (tmp && tmp[0] != '\0') { + info->print_title = strdup(tmp); + if (!info->print_title) { + LOGE("strdup: %d", errno); + } + } + info->struct_version = sqlite3_column_int(stmt, 3); + info->photo_id = sqlite3_column_int64(stmt, 4); + tmp = (const char *)sqlite3_column_text(stmt, 5); + if (tmp && tmp[0] != '\0') { + info->photo_path = strdup(tmp); + if (!info->photo_path) { + LOGE("strdup: %d", errno); + } + } + tmp = (const char *)sqlite3_column_text(stmt, 6); + if (tmp && tmp[0] != '\0') { + info->title = strdup(tmp); + if (!info->title) { + LOGE("strdup: %d", errno); + } + } + info->users_num = sqlite3_column_int(stmt, 7); + info->user_list_size = sqlite3_column_int(stmt, 8); + info->user_list_version = sqlite3_column_int(stmt, 9); + info->inviter_id = sqlite3_column_int(stmt, 10); + + tmp = (const char *)sqlite3_column_text(stmt, 11); + if (tmp && tmp[0] != '\0') { + char *ptr; + + ptr = strdup(tmp); + if (ptr) { + char *tmp_ptr; + int i; + + for (i = 0; i < info->users_num && *ptr && i < (sizeof(info->chat_users) / sizeof(int)); i++) { + tmp_ptr = ptr; + + while (*tmp_ptr != ',' && *tmp_ptr != '\0') { + tmp_ptr++; + } + *tmp_ptr = '\0'; + + info->chat_users[i] = atoi(ptr); + ptr = tmp_ptr + 1; + } + + if (i != info->users_num) { + /** + * There is some problem. + * The count of loaded user is not correct. + * Fix it forcely. + */ + LOGD("Update user_num: %d -> %d", info->users_num, i); + info->users_num = i; + } + + free(ptr); + } + } + + info->date = sqlite3_column_int(stmt, 12); + info->version = sqlite3_column_int(stmt, 13); + info->admin_id = sqlite3_column_int(stmt, 14); + result = eina_list_append(result, info); + } + + sqlite3_finalize(stmt); + + return result; +} + +tg_peer_info_s *tg_db_get_peer_info(sqlite3 *db, const char *table, int peer_id) +{ + tg_peer_info_s *info; + sqlite3_stmt *stmt; + const char *tmp; + int ret; + + ret = sqlite3_prepare_v2(db, "SELECT peer_type, flags, last_msg_id, last_msg_date, print_name, struct_version, no_of_unread_msgs, last_seen_time, photo_path, photo_id FROM ? WHERE peer_id = ?", -1, &stmt, NULL); + if (ret != SQLITE_OK) { + return NULL; + } + + ret = sqlite3_bind_text(stmt, 1, table, -1, SQLITE_TRANSIENT); + if (ret != SQLITE_OK) { + sqlite3_finalize(stmt); + return NULL; + } + + ret = sqlite3_bind_int(stmt, 2, peer_id); + if (ret != SQLITE_OK) { + sqlite3_finalize(stmt); + return NULL; + } + + if (sqlite3_step(stmt) != SQLITE_ROW) { + sqlite3_finalize(stmt); + return NULL; + } + + info = calloc(1, sizeof(*info)); + if (!info) { + sqlite3_finalize(stmt); + return NULL; + } + + info->peer_id = peer_id; + info->peer_type = sqlite3_column_int(stmt, 0); + info->flags = sqlite3_column_int(stmt, 1); + info->last_msg_id = sqlite3_column_int64(stmt, 2); + info->last_msg_date = sqlite3_column_int(stmt, 3); + tmp = (const char *)sqlite3_column_text(stmt, 4); + if (tmp && tmp[0] != '\0') { + info->print_name = strdup(tmp); + if (!info->print_name) { + LOGE("strdup: %d", errno); + } + } + info->struct_version = sqlite3_column_int(stmt, 5); + info->no_of_unread_msgs = sqlite3_column_int(stmt, 6); + info->last_seen_time = sqlite3_column_int(stmt, 7); + + tmp = (const char *)sqlite3_column_text(stmt, 8); + if (tmp && tmp[0] != '\0') { + info->photo_path = strdup(tmp); + if (!info->photo_path) { + LOGE("strdup: %d\n", errno); + } + } + + info->photo_id = sqlite3_column_int64(stmt, 9); + + sqlite3_finalize(stmt); + return info; +} + +Eina_List *tg_db_get_messages(sqlite3 *db, const char *table_name) +{ + Eina_List *result; + tg_message_s *info; + sqlite3_stmt *stmt; + const char *tmp; + int ret; + + ret = sqlite3_prepare_v2(db, "SELECT msg_id, flags, fwd_from_id, fwd_date, from_id, to_id, out, unread, date, service, message, msg_state, message_len, media_type, media_id, unique_id FROM ?", -1, &stmt, NULL); + if (ret != SQLITE_OK) { + return NULL; + } + + ret = sqlite3_bind_text(stmt, 1, table_name, -1, SQLITE_TRANSIENT); + if (ret != SQLITE_OK) { + sqlite3_finalize(stmt); + return NULL; + } + + result = NULL; + while (sqlite3_step(stmt) == SQLITE_OK) { + info = calloc(1, sizeof(*info)); + if (!info) { + LOGE("calloc: %d", errno); + continue; + } + + info->msg_id = sqlite3_column_int(stmt, 0); + info->flags = sqlite3_column_int(stmt, 1); + info->fwd_from_id = sqlite3_column_int(stmt, 2); + info->fwd_date = sqlite3_column_int(stmt, 3); + info->from_id = sqlite3_column_int(stmt, 4); + info->to_id = sqlite3_column_int(stmt, 5); + info->out = sqlite3_column_int(stmt, 6); + info->unread = sqlite3_column_int(stmt, 7); + info->date = sqlite3_column_int(stmt, 8); + info->service = sqlite3_column_int(stmt, 9); + tmp = (const char *)sqlite3_column_text(stmt, 10); + if (tmp && tmp[0] != '\0') { + info->message = strdup(tmp); + if (!info->message) { + LOGE("strdup: %d", errno); + } + } + info->msg_state = sqlite3_column_int(stmt, 11); + info->message_len = sqlite3_column_int(stmt, 12); + info->media_type = sqlite3_column_int(stmt, 13); + tmp = (const char *)sqlite3_column_text(stmt, 14); + if (tmp && tmp[0] != '\0') { + info->media_id = strdup(tmp); + if (!info->media_id) { + LOGE("strdup: %d", errno); + } + } + info->unique_id = sqlite3_column_int(stmt, 15); + result = eina_list_append(result, info); + + } + sqlite3_finalize(stmt); + return result; +} + +char *tg_db_get_image_path_from_db(sqlite3 *db, int media_id) +{ + return NULL; } diff --git a/TelegramTizen/db_manager/tg_db_manager.h b/TelegramTizen/db_manager/tg_db_manager.h index 5d89ede..8e3425c 100644 --- a/TelegramTizen/db_manager/tg_db_manager.h +++ b/TelegramTizen/db_manager/tg_db_manager.h @@ -20,7 +20,9 @@ extern Eina_List* get_values_from_table_sync(sqlite3* db, const char* table_name extern Eina_List* get_values_from_table_sync_order_by(sqlite3* db, const char* table_name, Eina_List* column_names, Eina_List* column_types, const char* order_column, Eina_Bool is_asc, const char* where_clause); extern Eina_Bool close_database(sqlite3* db); extern int get_number_of_rows(sqlite3* db, char* table_name, char* where_clause); - - +extern Eina_List *tg_db_get_user_info(sqlite3 *db, tgl_peer_id_t *user_id); +extern Eina_List *tg_db_get_chat_info(sqlite3 *db, const char *table_name); +extern tg_peer_info_s *tg_db_get_peer_info(sqlite3 *db, const char *table, int peer_id); +extern Eina_List *tg_db_get_messages(sqlite3 *db, const char *table_name); #endif /* TG_DB_MANAGER_H_ */ diff --git a/TelegramTizen/inc/contact_selection_view.h b/TelegramTizen/inc/contact_selection_view.h index 41c2f64..a5a0bc1 100644 --- a/TelegramTizen/inc/contact_selection_view.h +++ b/TelegramTizen/inc/contact_selection_view.h @@ -11,5 +11,4 @@ extern void launch_contact_selction_view(void *data); - #endif /* CONTACT_SELECTION_VIEW_H_ */ diff --git a/TelegramTizen/src/contact_selection_view.c b/TelegramTizen/src/contact_selection_view.c index a068919..e7cfaf3 100644 --- a/TelegramTizen/src/contact_selection_view.c +++ b/TelegramTizen/src/contact_selection_view.c @@ -7,6 +7,16 @@ #include "contact_selection_view.h" #include "group_chat_entry_view.h" +static Evas_Object* create_image_object_from_file(const char *icon_name, Evas_Object *parent) +{ + Evas_Object *icon = elm_image_add(parent); + evas_object_size_hint_weight_set(icon, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(icon, EVAS_HINT_FILL, EVAS_HINT_FILL); + elm_image_file_set(icon, icon_name, NULL); + evas_object_show(icon); + return icon; +} + void on_buddy_selected(void *data, Evas_Object *obj, void *event_info) { Elm_Object_Item *it = event_info; @@ -275,7 +285,7 @@ void launch_contact_selction_view(void *data) evas_object_data_set(buddy_gen_list, "app_data", ad); Eina_Bool all_items_selected = EINA_FALSE; - evas_object_data_set(buddy_gen_list, "all_selected", (void*)all_items_selected); + evas_object_data_set(buddy_gen_list, "all_selected", (void *)((int)all_items_selected)); itc.item_style = "default_style"; itc.func.text_get = on_buddy_name_get_cb; diff --git a/TelegramTizen/src/group_chat_entry_view.c b/TelegramTizen/src/group_chat_entry_view.c index 5bcb263..f3dfcc3 100644 --- a/TelegramTizen/src/group_chat_entry_view.c +++ b/TelegramTizen/src/group_chat_entry_view.c @@ -7,6 +7,16 @@ #include "group_chat_entry_view.h" #include "server_requests.h" +static Evas_Object *create_image_object_from_file(const char *icon_name, Evas_Object *parent) +{ + Evas_Object *icon = elm_image_add(parent); + evas_object_size_hint_weight_set(icon, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(icon, EVAS_HINT_FILL, EVAS_HINT_FILL); + elm_image_file_set(icon, icon_name, NULL); + evas_object_show(icon); + return icon; +} + char* on_image_load_text_get_cb(void *data, Evas_Object *obj, const char *part) { int id = (int) data; diff --git a/TelegramTizen/src/telegramtizen.c b/TelegramTizen/src/telegramtizen.c index 78bd658..ab6529e 100644 --- a/TelegramTizen/src/telegramtizen.c +++ b/TelegramTizen/src/telegramtizen.c @@ -9,7 +9,6 @@ #include "device_contacts_manager.h" #include "contacts-db-utils.h" #include "server_requests.h" -#include "tg_buddy_chat_view.h" #include "tg_init_screen.h" #include "tg_user_main_view.h" #include "tg_messaging_view.h" @@ -1110,7 +1109,6 @@ static int _on_service_client_msg_received_cb(void *data, bundle *const rec_msg) char* chat_id_str = NULL; result = bundle_get_str(rec_msg, "chat_id", &chat_id_str); - int chat_id = atoi(chat_id_str); #if 0 // get group chat details from database.(chat info) @@ -1143,11 +1141,8 @@ static int _on_service_client_msg_received_cb(void *data, bundle *const rec_msg) show_toast(app, "new group created"); #endif } else if (strcmp(rec_key_val, "contact_updated") == 0) { - - char* buddy_id_str = NULL; result = bundle_get_str(rec_msg, "buddy_id", &buddy_id_str); - int buddy_id = atoi(buddy_id_str); char* update_msg = NULL; result = bundle_get_str(rec_msg, "update_message", &update_msg); @@ -1167,7 +1162,6 @@ static int _on_service_client_msg_received_cb(void *data, bundle *const rec_msg) char* buddy_id_str = NULL; result = bundle_get_str(rec_msg, "buddy_id", &buddy_id_str); - int buddy_id = atoi(buddy_id_str); char* buddy_name = NULL; result = bundle_get_str(rec_msg, "buddy_name", &buddy_name); diff --git a/TelegramTizen/src/tg_buddy_list.c b/TelegramTizen/src/tg_buddy_list.c index b58936c..5433bf5 100644 --- a/TelegramTizen/src/tg_buddy_list.c +++ b/TelegramTizen/src/tg_buddy_list.c @@ -6,10 +6,19 @@ #include "tg_buddy_list.h" #include "tg_chat_conv_view.h" #include "contact_selection_view.h" -#include "tg_buddy_chat_view.h" void refresh_buddy_list(void *data); +static Evas_Object* create_image_object_from_file(const char *icon_name, Evas_Object *parent) +{ + Evas_Object *icon = elm_image_add(parent); + evas_object_size_hint_weight_set(icon, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(icon, EVAS_HINT_FILL, EVAS_HINT_FILL); + elm_image_file_set(icon, icon_name, NULL); + evas_object_show(icon); + return icon; +} + char* on_list_text_get_cb(void *data, Evas_Object *obj, const char *part) { @@ -331,7 +340,7 @@ static void on_buddy_clicked(void *data, Evas_Object *obj, void *event_info) int item_id = (int) data; appdata_s* ad = evas_object_data_get(obj, "app_data"); - peer_with_pic_s* sel_item = eina_list_nth(ad->peer_list, item_id); + peer_with_pic_s *sel_item = eina_list_nth(ad->peer_list, item_id); ad->buddy_in_cahtting_data = sel_item->use_data; diff --git a/TelegramTizen/src/tg_chat_conv_view.c b/TelegramTizen/src/tg_chat_conv_view.c index b1c1973..24683ce 100644 --- a/TelegramTizen/src/tg_chat_conv_view.c +++ b/TelegramTizen/src/tg_chat_conv_view.c @@ -212,7 +212,7 @@ void on_chat_buddy_msg_receive(tg_message_s *M, int type_of_chat) tgl_do_load_photo(TLS, pic ,&on_buddy_pic_msg_loaded,M); } #endif - char* path = ui_utils_get_resource(BLUR_BG); + const char *path = ui_utils_get_resource(BLUR_BG); bubble_table = create_image_bubble_table(chat_conv_view_data.ad->win, CHAT_MESSAGE_BUBBLE_RECEIVE, path, res, M->media_id); @@ -290,7 +290,7 @@ static int chat_history_db_callback(void *data, int argc, char **argv, char **az long long media_id = atoll(media_id_str); - char* img_path = get_image_path_from_db(media_id); + const char* img_path = get_image_path_from_db(media_id); if (img_path == NULL || strlen(img_path) == 0) { img_path = ui_utils_get_resource(BLUR_BG); diff --git a/TelegramTizen/src/tg_db_wrapper.c b/TelegramTizen/src/tg_db_wrapper.c index a152696..7731940 100644 --- a/TelegramTizen/src/tg_db_wrapper.c +++ b/TelegramTizen/src/tg_db_wrapper.c @@ -999,7 +999,9 @@ tg_message_s* get_message_from_message_table(long long msg_id, char* table_name) char* where_clause = NULL; char msg_id_str[50]; - sprintf(msg_id_str,"%d",msg_id); + + sprintf(msg_id_str, "%lld", msg_id); + where_clause = (char*)malloc(strlen(MESSAGE_INFO_TABLE_MESSAGE_ID) + strlen(" = ") + strlen(msg_id_str) + 1); strcpy(where_clause, MESSAGE_INFO_TABLE_MESSAGE_ID); strcat(where_clause, " = "); @@ -1343,9 +1345,15 @@ void insert_media_info_to_db(tg_message_s *M, char* file_path, int width, int he col_values = eina_list_append(col_values,M->media_id); col_values = eina_list_append(col_values, &(media_type)); - long temp_val = 0; - + long long temp_val = 0; char access_hash_str[50]; + + /** + * @todo + * Should implement this to get the temp_val. + * Currently it is ZERO always. + */ + sprintf(access_hash_str, "%lld", temp_val); col_values = eina_list_append(col_values, access_hash_str); @@ -1533,8 +1541,8 @@ char* get_image_path_from_db(long long media_id) char* table_name = MEDIA_INFO_TABLE_NAME; char usr_str[50]; - sprintf(usr_str,"%lld",media_id); - char* where_clause = (char*)malloc(strlen(MEDIA_INFO_TABLE_MEDIA_ID) + strlen(" = '") + strlen(usr_str) + strlen("'") + 1); + sprintf(usr_str, "%lld", media_id); + char* where_clause = (char *)malloc(strlen(MEDIA_INFO_TABLE_MEDIA_ID) + strlen(" = '") + strlen(usr_str) + strlen("'") + 1); strcpy(where_clause, MEDIA_INFO_TABLE_MEDIA_ID); strcat(where_clause, " = '"); strcat(where_clause, usr_str); @@ -1766,3 +1774,5 @@ Eina_List* get_image_details_from_db(long long media_id) } return vals; } + + diff --git a/TelegramTizen/src/tg_init_screen.c b/TelegramTizen/src/tg_init_screen.c index 2aa3348..0f7c8b6 100644 --- a/TelegramTizen/src/tg_init_screen.c +++ b/TelegramTizen/src/tg_init_screen.c @@ -10,6 +10,17 @@ static Evas_Object* get_single_box(appdata_s* ad, Eina_Bool is_next); static Evas_Object* get_next_previous_box(appdata_s* ad); + +static Evas_Object* create_image_object_from_file(const char *icon_name, Evas_Object *parent) +{ + Evas_Object *icon = elm_image_add(parent); + evas_object_size_hint_weight_set(icon, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(icon, EVAS_HINT_FILL, EVAS_HINT_FILL); + elm_image_file_set(icon, icon_name, NULL); + evas_object_show(icon); + return icon; +} + static void on_next_btn_clicked(void* data, Evas_Object* obj, void* event) { appdata_s* ad = data; diff --git a/TelegramTizen/src/tg_messaging_view.c b/TelegramTizen/src/tg_messaging_view.c index 5fd44c3..5b95ece 100644 --- a/TelegramTizen/src/tg_messaging_view.c +++ b/TelegramTizen/src/tg_messaging_view.c @@ -9,7 +9,17 @@ #include "tg_db_wrapper.h" #include "server_requests.h" -static Evas_Object * image_item_provider(void *data, Evas_Object *entry, const char *item) +static Evas_Object *create_image_object_from_file(const char *icon_name, Evas_Object *parent) +{ + Evas_Object *icon = elm_image_add(parent); + evas_object_size_hint_weight_set(icon, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(icon, EVAS_HINT_FILL, EVAS_HINT_FILL); + elm_image_file_set(icon, icon_name, NULL); + evas_object_show(icon); + return icon; +} + +static inline Evas_Object * image_item_provider(void *data, Evas_Object *entry, const char *item) { Evas_Object* layout = NULL; if (!strcmp(item, "itemprovider")) @@ -27,14 +37,17 @@ static Evas_Object * image_item_provider(void *data, Evas_Object *entry, const c // get media details. - char* img_path = get_image_path_from_db(atoll(msg->media_id)); + char *img_path = get_image_path_from_db(atoll(msg->media_id)); if (img_path == NULL || strlen(img_path) == 0) { int img_size = (int)evas_object_data_get(entry, "media_size"); char img_size_str[10]; + const char *tmp; + sprintf(img_size_str, "%dkbs", img_size); - img_path = ui_utils_get_resource(BLUR_BG); + tmp = ui_utils_get_resource(BLUR_BG); + img_path = strdup(tmp); char edj_path[PATH_MAX] = {0, }; app_get_resource(EDJ_CHAT_CONV_FILE, edj_path, (int)PATH_MAX); @@ -225,7 +238,9 @@ Evas_Object* on_message_item_content_get_cb(void *data, Evas_Object *obj, const if (img_path == NULL || strlen(img_path) == 0) { - img_path = ui_utils_get_resource(BLUR_BG); + const char *tmp; + tmp = ui_utils_get_resource(BLUR_BG); + img_path = strdup(tmp); is_blur_image = EINA_TRUE; } @@ -291,8 +306,8 @@ Evas_Object* on_message_item_content_get_cb(void *data, Evas_Object *obj, const sizeof(res), format); } - char time_str[20]={0,}; - snprintf(time_str, sizeof(time_str), res); + char time_str[20] = {0,}; + strncpy(time_str, res, sizeof(time_str)); char temp_time[256] = {0,}; snprintf(temp_time, sizeof(temp_time), "%s", time_str); @@ -717,7 +732,7 @@ Evas_Object* on_message_item_content_get_cb(void *data, Evas_Object *obj, const } char time_str[20]={0,}; - snprintf(time_str, sizeof(time_str), res); + strncpy(time_str, res, sizeof(time_str)); elm_object_part_text_set(entry, "time", time_str); Evas_Object *status_obj; @@ -1388,7 +1403,7 @@ void launch_messaging_view_cb(appdata_s* ad, int user_id) user_data_with_pic_s *sel_item = eina_list_nth(ad->buddy_list, user_id); user_data_s* user = sel_item->use_data; - Evas_Object *profile_pic = NULL; + Evas_Object *profile_pic; if (user->photo_path && strcmp(user->photo_path, "") != 0) { profile_pic = create_image_object_from_file(user->photo_path, layout); } else { diff --git a/TelegramTizen/src/tg_start_messaging_view.c b/TelegramTizen/src/tg_start_messaging_view.c index 2d1f0c7..810f520 100644 --- a/TelegramTizen/src/tg_start_messaging_view.c +++ b/TelegramTizen/src/tg_start_messaging_view.c @@ -6,16 +6,24 @@ */ #include "tg_start_messaging_view.h" -#include "tg_buddy_chat_view.h" #include "tg_db_wrapper.h" #include "tg_messaging_view.h" +static Evas_Object* create_image_object_from_file(const char *icon_name, Evas_Object *parent) +{ + Evas_Object *icon = elm_image_add(parent); + evas_object_size_hint_weight_set(icon, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(icon, EVAS_HINT_FILL, EVAS_HINT_FILL); + elm_image_file_set(icon, icon_name, NULL); + evas_object_show(icon); + return icon; +} + static void on_new_msg_menu_item_selected(void *data, Evas_Object *obj, void *event_info) { int index = (int)data; } - static char* on_new_msg_menu_item_name_get_cb(void *data, Evas_Object *obj, const char *part) { if (!strcmp(part,"elm.text")) @@ -206,6 +214,17 @@ Evas_Object* on_buddy_list_image_requested(void *data, Evas_Object *obj, const c } +static void on_user_list_search_clicked(void *data, Evas_Object *obj, void *event_info) +{ + appdata_s* ad = data; + show_toast(ad, "search clicked"); +} + +static void on_menu_list_clicked_cb(void *data, Evas_Object *obj, void *event_info) +{ + Elm_Object_Item *it = event_info; + elm_genlist_item_selected_set(it, EINA_FALSE); +} void launch_start_messaging_view(appdata_s* ad) { diff --git a/TelegramTizen/src/tg_user_main_view.c b/TelegramTizen/src/tg_user_main_view.c index 19fca78..824c3c8 100644 --- a/TelegramTizen/src/tg_user_main_view.c +++ b/TelegramTizen/src/tg_user_main_view.c @@ -8,7 +8,15 @@ #include "tg_user_main_view.h" #include "tg_start_messaging_view.h" - +static Evas_Object *create_image_object_from_file(const char *icon_name, Evas_Object *parent) +{ + Evas_Object *icon = elm_image_add(parent); + evas_object_size_hint_weight_set(icon, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(icon, EVAS_HINT_FILL, EVAS_HINT_FILL); + elm_image_file_set(icon, icon_name, NULL); + evas_object_show(icon); + return icon; +} static void on_new_message_clicked(void *data, Evas_Object *obj, void *event_info) { @@ -44,9 +52,14 @@ static Evas_Object* on_menu_item_image_get_cb(void *data, Evas_Object *obj, cons static void on_menu_item_selected(void *data, Evas_Object *obj, void *event_info) { - int index = (int)data; + int index __attribute__((unused)) = (int)data; } +static void on_menu_list_clicked_cb(void *data, Evas_Object *obj, void *event_info) +{ + Elm_Object_Item *it = event_info; + elm_genlist_item_selected_set(it, EINA_FALSE); +} Evas_Object* create_side_panel_list(appdata_s* ad, Evas_Object *parent) { @@ -443,6 +456,12 @@ Evas_Object* on_buddy_photo_requested(void *data, Evas_Object *obj, const char * } +static void on_user_list_search_clicked(void *data, Evas_Object *obj, void *event_info) +{ + appdata_s* ad = data; + show_toast(ad, "search clicked"); +} + void launch_user_main_view_cb(appdata_s* ad) { if (!ad) diff --git a/TelegramTizen/tg_utils/tg_common.h b/TelegramTizen/tg_utils/tg_common.h index 6b49de6..fff692e 100644 --- a/TelegramTizen/tg_utils/tg_common.h +++ b/TelegramTizen/tg_utils/tg_common.h @@ -261,17 +261,17 @@ typedef enum MESSAGE_STATE { typedef struct user_data { tgl_peer_id_t user_id; - char* print_name; + char *print_name; int structure_version; - char* photo_path; + char *photo_path; int photo_id; - char* first_name; - char* last_name; - char* phone; + char *first_name; + char *last_name; + char *phone; int access_hash; - char* real_first_name; - char* real_last_name; - char* username; + char *real_first_name; + char *real_last_name; + char *username; int online; int last_seen; Eina_Bool is_selected; @@ -411,7 +411,6 @@ extern void show_toast(appdata_s* ad, char* value); extern void layout_back_cb(void *data, Evas_Object *obj, void *event_info); extern void tg_login_nf_back_cb(void *data, Evas_Object *obj, void *event_info); extern void detail_list_nf_back_cb(void *data, Evas_Object *obj, void *event_info); -extern void load_rec_msg_to_db(struct tgl_state *TLS, struct tgl_message *M); extern void create_buddy_msg_table(const char* table_name); extern void load_buddy_list_data(appdata_s *ad); extern void load_group_chat_data(appdata_s *ad); @@ -430,7 +429,7 @@ static char *trim(char *s) { } #endif -static char* trim(char * s) +static inline char* trim(char * s) { if (!s) return NULL; @@ -460,17 +459,6 @@ static Evas_Object* create_circle_button(Evas_Object *parent, char* text, char* return button; } -static void on_menu_list_clicked_cb(void *data, Evas_Object *obj, void *event_info) -{ - Elm_Object_Item *it = event_info; - elm_genlist_item_selected_set(it, EINA_FALSE); -} - -static void on_user_list_search_clicked(void *data, Evas_Object *obj, void *event_info) -{ - appdata_s* ad = data; - show_toast(ad, "search clicked"); -} static Evas_Object* create_button(Evas_Object *parent, char *style, char *text) { @@ -500,7 +488,7 @@ static void app_get_resource(const char *edj_file_in, char *edj_path_out, int ed } } -static void telegram_image_mask_delete_cb(Evas_Object *obj) +static inline void telegram_image_mask_delete_cb(Evas_Object *obj) { if (obj == NULL) return; @@ -550,61 +538,27 @@ static Eina_Bool compare_date_with_current_date(int rtime) { return EINA_FALSE; } -static void telegram_set_c(Evas_Object *image, char *image_path, char *mask_path, int width, int height) -{ - if (image == NULL) - return; - if (image_path == NULL) - return; - - Evas_Object *img_obj = NULL; - void *mask; - //if (image_path != NULL) - //mask = ea_image_effect_mask(image_path, mask_path, width, height, 0, 0); - img_obj = elm_image_object_get(image); - evas_object_image_colorspace_set(img_obj, EVAS_COLORSPACE_ARGB8888); - evas_object_image_size_set(img_obj, width, height); - evas_object_image_data_set(img_obj, mask); - evas_object_image_alpha_set(img_obj, EINA_TRUE); - evas_object_event_callback_add(img_obj, EVAS_CALLBACK_DEL, telegram_image_mask_delete_cb, NULL); -} - -static Evas_Object* create_image_object_from_file(const char *icon_name, Evas_Object *parent) -{ - Evas_Object *icon = elm_image_add(parent); - evas_object_size_hint_weight_set(icon, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - evas_object_size_hint_align_set(icon, EVAS_HINT_FILL, EVAS_HINT_FILL); - elm_object_focus_set(icon, EINA_FALSE); - elm_image_file_set(icon, icon_name, NULL); - evas_object_show(icon); - return icon; -} - -static void buddy_icon_del_cb(void *data, Evas *e, Evas_Object *icon, void *event_info) +static inline void buddy_icon_del_cb(void *data, Evas *e, Evas_Object *icon, void *event_info) { user_data_with_pic_s *item = data; item->contact_icon = NULL; } -static const char *_ui_utils_get_res_path() +static inline const char *ui_utils_get_resource(const char *res_name) { - char res_folder_path[PATH_MAX] = {'\0'}; - if (res_folder_path[0] == '\0') { - char *res_path_buff = app_get_resource_path(); - strncpy(res_folder_path, res_path_buff, PATH_MAX-1); - free(res_path_buff); + static char res_path[PATH_MAX] = {'\0'}; + + char *res_path_buff = app_get_resource_path(); + if (!res_path_buff) { + return NULL; } - return res_folder_path; -} + snprintf(res_path, sizeof(res_path) - 1, "%s%s", res_path_buff, res_name); + free(res_path_buff); -static char *ui_utils_get_resource(const char *res_name) -{ - static char res_path[PATH_MAX] = {'\0'}; - snprintf(res_path, PATH_MAX, "%s%s", _ui_utils_get_res_path(), res_name); return res_path; } -static char* get_current_time() +static inline char *get_current_time() { Eina_Strbuf *strbuf = eina_strbuf_new(); time_t local_time = time(NULL); @@ -619,17 +573,20 @@ static char* get_current_time() return ret; } -static char *replace(const char *s, char ch, const char *repl) +static inline char *replace(const char *s, char ch, const char *repl) { int count = 0; const char *t; - for(t=s; *t; t++) + + for(t = s; *t; t++) { count += (*t == ch); + } size_t rlen = strlen(repl); - char *res = malloc(strlen(s) + (rlen-1)*count + 1); + char *res = malloc(strlen(s) + (rlen - 1) * count + 1); char *ptr = res; - for(t=s; *t; t++) { + + for(t = s; *t; t++) { if(*t == ch) { memcpy(ptr, repl, rlen); ptr += rlen; @@ -637,293 +594,302 @@ static char *replace(const char *s, char ch, const char *repl) *ptr++ = *t; } } + *ptr = 0; return res; } -static Evas_Object * create_scroller(Evas_Object *parent) +static inline Evas_Object * create_scroller(Evas_Object *parent) { Evas_Object *scroller = elm_scroller_add(parent); + if (!scroller) { + /** + * @todo + * Handling this exceptional cases. + */ + return NULL; + } elm_scroller_bounce_set(scroller, EINA_FALSE, EINA_FALSE); elm_scroller_policy_set(scroller, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_OFF); evas_object_show(scroller); return scroller; } -static int telegram_is_drm_file(const char *file_path) +static inline int telegram_is_drm_file(const char *file_path) { return 0; } -static TELEGRAM_APP_FILE_TYPE_E __telegram_common_get_file_type_by_file_ext(const char * file_ext, const char * fullpath) +static inline TELEGRAM_APP_FILE_TYPE_E __telegram_common_get_file_type_by_file_ext(const char *file_ext, const char *fullpath) { - int i = 0; + const char *ptr; if (file_ext == NULL) { LOGI("file_ext is NULL"); return TELEGRAM_APP_FILE_TYPE_ETC; } - switch (file_ext[i]) { + ptr = file_ext + 1; + switch (*file_ext) { case 'a': case 'A': - if (strcasecmp("ASF", &file_ext[i]) == 0) { + if (strcasecmp("SF", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_VIDEO; } - if (strcasecmp("AMR", &file_ext[i]) == 0) { + if (strcasecmp("MR", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_VOICE; } - if (strcasecmp("AWB", &file_ext[i]) == 0) { + if (strcasecmp("WB", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_VOICE; } - if (strcasecmp("AAC", &file_ext[i]) == 0) { + if (strcasecmp("AC", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_MUSIC; } - if (strcasecmp("AVI", &file_ext[i]) == 0) { + if (strcasecmp("VI", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_VIDEO; } break; case 'b': case 'B': - if (strcasecmp("BMP", &file_ext[i]) == 0) { + if (strcasecmp("MP", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_IMAGE; } break; case 'd': case 'D': - if (strcasecmp("DOC", &file_ext[i]) == 0) { + if (strcasecmp("OC", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_DOC; } - if (strcasecmp("DOCX", &file_ext[i]) == 0) { + if (strcasecmp("OCX", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_DOC; } - if (strcasecmp("DIVX", &file_ext[i]) == 0) { + if (strcasecmp("IVX", ptr) == 0) { if (telegram_is_drm_file(fullpath) == 0) { return TELEGRAM_APP_FILE_TYPE_DRM; } else { return TELEGRAM_APP_FILE_TYPE_VIDEO; } } - if (strcasecmp("DCF", &file_ext[i]) == 0) { + if (strcasecmp("CF", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_DRM; } - if (strcasecmp("DM", &file_ext[i]) == 0) { + if (strcasecmp("M", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_DRM; } break; case 'g': case 'G': - if (strcasecmp("GIF", &file_ext[i]) == 0) { + if (strcasecmp("IF", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_IMAGE; } - if (strcasecmp("G72", &file_ext[i]) == 0) { + if (strcasecmp("72", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_MUSIC; } break; case 'h': case 'H': - if (strcasecmp("HTML", &file_ext[i]) == 0) { + if (strcasecmp("TML", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_HTML; } - if (strcasecmp("HTM", &file_ext[i]) == 0) { + if (strcasecmp("TM", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_HTML; } break; case 'i': case 'I': - if (strcasecmp("IMY", &file_ext[i]) == 0) { + if (strcasecmp("MY", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_MUSIC; } - if (strcasecmp("ICS", &file_ext[i]) == 0) { + if (strcasecmp("CS", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_VCALENDAR; } break; case 'j': case 'J': - if (strcasecmp("JPG", &file_ext[i]) == 0) { + if (strcasecmp("PG", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_IMAGE; } - if (strcasecmp("JPEG", &file_ext[i]) == 0) { + if (strcasecmp("PEG", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_IMAGE; } - if (strcasecmp("JPE", &file_ext[i]) == 0) { + if (strcasecmp("PE", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_IMAGE; } break; case 'm': case 'M': - if (strcasecmp("MMF", &file_ext[i]) == 0) { + if (strcasecmp("MF", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_MUSIC; } - if (strcasecmp("MP3", &file_ext[i]) == 0) { + if (strcasecmp("P3", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_MUSIC; } - if (strcasecmp("MID", &file_ext[i]) == 0) { + if (strcasecmp("ID", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_MUSIC; } - if (strcasecmp("MIDI", &file_ext[i]) == 0) { + if (strcasecmp("IDI", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_MUSIC; } - if (strcasecmp("MP4", &file_ext[i]) == 0) { + if (strcasecmp("P4", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_VIDEO; } - if (strcasecmp("MPG", &file_ext[i]) == 0) { + if (strcasecmp("PG", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_VIDEO; } - if (strcasecmp("MPEG", &file_ext[i]) == 0) { + if (strcasecmp("PEG", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_VIDEO; } - if (strcasecmp("M4A", &file_ext[i]) == 0) { + if (strcasecmp("4A", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_MUSIC; } - if (strcasecmp("M3G", &file_ext[i]) == 0) { + if (strcasecmp("3G", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_FLASH; } - if (strcasecmp("MXMF", &file_ext[i]) == 0) { + if (strcasecmp("XMF", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_MUSIC; } - if (strcasecmp("MKV", &file_ext[i]) == 0) { + if (strcasecmp("KV", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_VIDEO; } break; case 'o': case 'O': - if (strcasecmp("opml", &file_ext[i]) == 0) { + if (strcasecmp("pml", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_RSS; } - if (strcasecmp("ODF", &file_ext[i]) == 0) { + if (strcasecmp("DF", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_DRM; } - if (strcasecmp("ORO", &file_ext[i]) == 0) { + if (strcasecmp("RO", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_DRM; } break; case 'p': case 'P': - if (strcasecmp("PNG", &file_ext[i]) == 0) { + if (strcasecmp("NG", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_IMAGE; } - if (strcasecmp("PJPEG", &file_ext[i]) == 0) { + if (strcasecmp("JPEG", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_IMAGE; } - if (strcasecmp("PDF", &file_ext[i]) == 0) { + if (strcasecmp("DF", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_PDF; } - if (strcasecmp("PPT", &file_ext[i]) == 0) { + if (strcasecmp("PT", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_PPT; } - if (strcasecmp("PPTX", &file_ext[i]) == 0) { + if (strcasecmp("PTX", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_PPT; } break; case 'r': case 'R': - if (strcasecmp("RO", &file_ext[i]) == 0) { + if (strcasecmp("O", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_DRM; } break; case 's': case 'S': - if (strcasecmp("SDP", &file_ext[i]) == 0) { + if (strcasecmp("DP", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_VIDEO; } - if (strcasecmp("SPM", &file_ext[i]) == 0) { + if (strcasecmp("PM", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_MUSIC; } - if (strcasecmp("SMP", &file_ext[i]) == 0) { + if (strcasecmp("MP", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_MUSIC; } - if (strcasecmp("SPF", &file_ext[i]) == 0) { + if (strcasecmp("PF", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_MUSIC; } - if (strcasecmp("SWF", &file_ext[i]) == 0) { + if (strcasecmp("WF", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_FLASH; } - if (strcasecmp("SVG", &file_ext[i]) == 0) { + if (strcasecmp("VG", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_SVG; } - if (strcasecmp("SVGZ", &file_ext[i]) == 0) { + if (strcasecmp("VGZ", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_SVG; } break; case 't': case 'T': - if (strcasecmp("TXT", &file_ext[i]) == 0) { + if (strcasecmp("XT", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_TXT; } - if (strcasecmp("TPK", &file_ext[i]) == 0) { + if (strcasecmp("PK", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_TPK; } break; case 'v': case 'V': - if (strcasecmp("VCF", &file_ext[i]) == 0) { + if (strcasecmp("CF", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_VCONTACT; } - if (strcasecmp("VTS", &file_ext[i]) == 0) { + if (strcasecmp("TS", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_VCALENDAR; } - if (strcasecmp("VCS", &file_ext[i]) == 0) { + if (strcasecmp("CS", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_VCALENDAR; } break; case 'w': case 'W': - if (strcasecmp("WAV", &file_ext[i]) == 0) { + if (strcasecmp("AV", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_MUSIC; } - if (strcasecmp("WBMP", &file_ext[i]) == 0) { + if (strcasecmp("BMP", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_IMAGE; } - if (strcasecmp("WGT", &file_ext[i]) == 0) { + if (strcasecmp("GT", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_WGT; } - if (strcasecmp("WMA", &file_ext[i]) == 0) { + if (strcasecmp("MA", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_MUSIC; } - if (strcasecmp("WMV", &file_ext[i]) == 0) { + if (strcasecmp("MV", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_VIDEO; } break; case 'x': case 'X': - if (strcasecmp("XLS", &file_ext[i]) == 0) { + if (strcasecmp("LS", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_EXCEL; } - if (strcasecmp("XLSX", &file_ext[i]) == 0) { + if (strcasecmp("LSX", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_EXCEL; } - if (strcasecmp("XMF", &file_ext[i]) == 0) { + if (strcasecmp("MF", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_MUSIC; } - if (strcasecmp("XHTML", &file_ext[i]) == 0) { + if (strcasecmp("HTML", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_HTML; } break; case '3': - if (strcasecmp("3GP", &file_ext[i]) == 0) { + if (strcasecmp("GP", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_VIDEO; } - if (strcasecmp("3GPP", &file_ext[i]) == 0) { + if (strcasecmp("GPP", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_VIDEO; } - if (strcasecmp("3G2", &file_ext[i]) == 0) { + if (strcasecmp("G2", ptr) == 0) { return TELEGRAM_APP_FILE_TYPE_VIDEO; } break; @@ -931,9 +897,7 @@ static TELEGRAM_APP_FILE_TYPE_E __telegram_common_get_file_type_by_file_ext(cons return TELEGRAM_APP_FILE_TYPE_ETC; } - - -static char* telegram_common_get_file_ext(const char *a_pszfile_name) +static inline char* telegram_common_get_file_ext(const char *a_pszfile_name) { if (a_pszfile_name != NULL) { int nlen = strlen(a_pszfile_name); @@ -953,7 +917,7 @@ static char* telegram_common_get_file_ext(const char *a_pszfile_name) } -static TELEGRAM_APP_FILE_TYPE_E telegram_common_get_file_type(const char *filepath) +static inline TELEGRAM_APP_FILE_TYPE_E telegram_common_get_file_type(const char *filepath) { TELEGRAM_APP_FILE_TYPE_E file_type = TELEGRAM_APP_FILE_TYPE_NONE; if(filepath == NULL) diff --git a/tg-engine-service/.sdk_delta.info b/tg-engine-service/.sdk_delta.info deleted file mode 100644 index e16048c23fd7a800942f15598c791aca2e7e184e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5827 zcma)=e~esJ702(ryW4iROWFRyUsMZJQZ(~YVn!-p-L6%~hLXkxZGvX^?abTRx1D`6 zee(ud6M|`hn4rdz#vgxZ)ISUYCe?tnfI_igh{>+5!T3juxJ5;*2^!q3Qq=Fc_uMyk z_Pwz^f4ui5^EvmPbMCq4p7*2>LQ1hZsTP8$8b(2(8N_#lUwde`F5TSx90+zN`o zM{()bkGQWF{a(2d*QbJVLbOyw&)23d9m?%(2P_njXeM5wea+aTP67XcQR#_ewbj(g9ROv@TtV%Vm@2UcfMU{SxrS_6`V0jgsh5Lzxv3^+dz8%4Mt4dyv zXs_pvy!H)E$e9nOq@1~7m00OjE92$*G<>f(rcWK+ZTMLl`Ca@xN9zkdj6zB`4$$1u zk_ot+rF1hQXO9aE9);1Ak0om~+x%j5?U;t-%nsbA`58_QFkh>a?P>f|{9{1xVjQct za=aDRDnOs>9kkLaNz(Tne22s+f zlv-s{pY&AmN>>S6rXF=Fr85C!QN;~dUOQ7O32WV~1DEQ&8~c5KD~Q9TzNBV>Na^>$ z`DPNg%2a}u44*0hN)LualgUHLA z#)a#>E#8)bA5Wtc@55H&`n2%Y16=+tR4`VL9#3AFL<+~P8fMltu+2O5>ElRY69qXN zLbVx}bGPV+tdS@$H}+k;yx_!7>)xmktEry|;!$KrqaHN_H_8jI|FEP-SHriZv#8-u z3$Zp6fi8MrS=8`n(qeXJ>^B-g+(idmsC6^ypk%>06 z+0y?}Cj?lE+~#WO0i#NMa$qu5xM?V!%`_{H*GoT>6^YNUoAa?C=b`I zRxtS1ZI6C;i(!@T=!~Z;%?G15+1B~M@jd5R2b>jEMvjM(&T+P<-Flv|6y|)QPprT} zfz#FuY8u1qnr|F4klN9P6`F!ff;*-xoI5$jS|G(0=DAnqCOGN!8n^e~B#<{G)T#0* zEaYEPw{3zubDgL@Oe{oUYYVIb$+E9>B)G$u1_yT=MtuTz*hHfCAWXGzoPKA*^ps)f zDu0^k0vNyN$O?nWQx5*zHSI3Ig1`I@gU>nO^Js>t3n)wme#NeViONftts66>qA3Q= z^HndvOWij(c{6|LFb7ce1LHjCy%)hKqY5Q{lr-Jt9lGo82YG0IMWA15rC?*Ak%VPe zWB#_W<3>Zy;%;9oes7I&B7OSooJD^H)D&qUPq&*AZMjLbGgG_Sa`|h(eLM%ob(;*w z)lFXuc^&1;2Bxe0gWE5dCc{K*osuvn@a7P&2>8`qC*k3G;V84a} zX?rHeq%%|J#|%Y;=;dc@$z)-^)Y3fxF`8f9fjXc36&%;{Z4- zav`IWZx}c$auJ46pT&)Jz5*aC5>**zZLKg7B<0C2Q3Yc~{)_oAifkdsBqA6q^51Mw z%|BRgC0!-}WJSKIz1DqY;r~qn&WgN%#Um%E7tN0=2rKd}ht3ZW2rKeG*c3Fjv)uVg z0IkUXve(@1YMV^GJU!>XY%qe-3XjU}_Q$z1a4u + diff --git a/tg-engine-service/src/server_response.c b/tg-engine-service/src/server_response.c index 918aff8..2f4d984 100644 --- a/tg-engine-service/src/server_response.c +++ b/tg-engine-service/src/server_response.c @@ -406,7 +406,7 @@ void send_message_read_by_buddy_response(int buddy_id, int message_id, char* tab } char msg_id_str[50]; - sprintf(msg_id_str,"%ld",message_id); + sprintf(msg_id_str,"%d", message_id); if (bundle_add_str(msg, "message_id", msg_id_str) != 0) { ERR("Failed to add data by key to bundle"); @@ -462,7 +462,7 @@ void send_message_sent_to_buddy_response(int buddy_id, int message_id, char* tab } char msg_id_str[50]; - sprintf(msg_id_str,"%ld",message_id); + sprintf(msg_id_str,"%d", message_id); if (bundle_add_str(msg, "message_id", msg_id_str) != 0) { ERR("Failed to add data by key to bundle"); diff --git a/tg-engine-service/src/tg_db_wrapper.c b/tg-engine-service/src/tg_db_wrapper.c index e5e03c7..b57f2e7 100644 --- a/tg-engine-service/src/tg_db_wrapper.c +++ b/tg-engine-service/src/tg_db_wrapper.c @@ -570,10 +570,10 @@ struct tgl_message* get_message_from_message_table(long long msg_id, char* table col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT); col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER); - char* where_clause = NULL; + char *where_clause = NULL; char msg_id_str[50]; - sprintf(msg_id_str,"%d",msg_id); - where_clause = (char*)malloc(strlen(MESSAGE_INFO_TABLE_MESSAGE_ID) + strlen(" = ") + strlen(msg_id_str) + 1); + sprintf(msg_id_str, "%lld", msg_id); + where_clause = (char *)malloc(strlen(MESSAGE_INFO_TABLE_MESSAGE_ID) + strlen(" = ") + strlen(msg_id_str) + 1); strcpy(where_clause, MESSAGE_INFO_TABLE_MESSAGE_ID); strcat(where_clause, " = "); strcat(where_clause, msg_id_str); @@ -680,7 +680,6 @@ struct tgl_message* get_message_from_message_table(long long msg_id, char* table char *temp_media_id = (char*)eina_list_nth(ts_msg, 14); - char* dummy_val = ""; char *eptr; if(message->media.type == tgl_message_media_none) { @@ -811,40 +810,40 @@ void insert_msg_into_db(struct tgl_message *M, char* table_name, int unique_id) col_values = eina_list_append(col_values, &(M->message_len)); col_values = eina_list_append(col_values, &(M->media.type)); - char* dummy_val = ""; + char *dummy_val = ""; if(M->media.type == tgl_message_media_none) { col_values = eina_list_append(col_values, (dummy_val)); } else if(M->media.type == tgl_message_media_photo) { - char* temp_media_id[50]; + char temp_media_id[50]; sprintf(temp_media_id, "%lld", M->media.photo.id); col_values = eina_list_append(col_values, temp_media_id); } else if(M->media.type == tgl_message_media_document) { - char* temp_media_id[50]; - sprintf(temp_media_id, "%lld", M->media.document.dc_id); + char temp_media_id[50]; + sprintf(temp_media_id, "%d", M->media.document.dc_id); col_values = eina_list_append(col_values, temp_media_id); } else if(M->media.type == tgl_message_media_geo) { col_values = eina_list_append(col_values, (dummy_val)); } else if(M->media.type == tgl_message_media_contact) { - char* temp_media_id[50]; - sprintf(temp_media_id, "%lld",M->media.user_id); + char temp_media_id[50]; + sprintf(temp_media_id, "%d",M->media.user_id); col_values = eina_list_append(col_values, temp_media_id); } else if(M->media.type == tgl_message_media_unsupported) { col_values = eina_list_append(col_values, (dummy_val)); } else if(M->media.type == tgl_message_media_photo_encr) { - char* temp_media_id[50]; + char temp_media_id[50]; sprintf(temp_media_id, "%lld",M->media.encr_photo.id); col_values = eina_list_append(col_values, temp_media_id); } else if(M->media.type == tgl_message_media_document_encr) { - char* temp_media_id[50]; + char temp_media_id[50]; sprintf(temp_media_id, "%lld",M->media.document.id); col_values = eina_list_append(col_values, temp_media_id); @@ -935,40 +934,40 @@ void update_msg_into_db(struct tgl_message *M, char* table_name, int unique_id) col_values = eina_list_append(col_values, &(M->message_len)); col_values = eina_list_append(col_values, &(M->media.type)); - char* dummy_val = ""; + char *dummy_val = ""; if(M->media.type == tgl_message_media_none) { col_values = eina_list_append(col_values, (dummy_val)); } else if(M->media.type == tgl_message_media_photo) { - char* temp_media_id[50]; + char temp_media_id[50]; sprintf(temp_media_id, "%lld", M->media.photo.id); col_values = eina_list_append(col_values, temp_media_id); } else if(M->media.type == tgl_message_media_document) { - char* temp_media_id[50]; - sprintf(temp_media_id, "%lld", M->media.document.dc_id); + char temp_media_id[50]; + sprintf(temp_media_id, "%d", M->media.document.dc_id); col_values = eina_list_append(col_values, temp_media_id); } else if(M->media.type == tgl_message_media_geo) { col_values = eina_list_append(col_values, (dummy_val)); } else if(M->media.type == tgl_message_media_contact) { - char* temp_media_id[50]; - sprintf(temp_media_id, "%lld",M->media.user_id); + char temp_media_id[50]; + sprintf(temp_media_id, "%d",M->media.user_id); col_values = eina_list_append(col_values, temp_media_id); } else if(M->media.type == tgl_message_media_unsupported) { col_values = eina_list_append(col_values, (dummy_val)); } else if(M->media.type == tgl_message_media_photo_encr) { - char* temp_media_id[50]; + char temp_media_id[50]; sprintf(temp_media_id, "%lld",M->media.encr_photo.id); col_values = eina_list_append(col_values, temp_media_id); } else if(M->media.type == tgl_message_media_document_encr) { - char* temp_media_id[50]; + char temp_media_id[50]; sprintf(temp_media_id, "%lld",M->media.document.id); col_values = eina_list_append(col_values, temp_media_id); @@ -982,7 +981,7 @@ void update_msg_into_db(struct tgl_message *M, char* table_name, int unique_id) } - char* where_clause = NULL; + char *where_clause = NULL; if (unique_id > 0) { @@ -996,8 +995,8 @@ void update_msg_into_db(struct tgl_message *M, char* table_name, int unique_id) } else { char usr_str[50]; - sprintf(usr_str,"%d",M->id); - where_clause = (char*)malloc(strlen(MESSAGE_INFO_TABLE_MESSAGE_ID) + strlen(" = ") + strlen(usr_str) + 1); + sprintf(usr_str,"%lld", M->id); + where_clause = (char *)malloc(strlen(MESSAGE_INFO_TABLE_MESSAGE_ID) + strlen(" = ") + strlen(usr_str) + 1); strcpy(where_clause, MESSAGE_INFO_TABLE_MESSAGE_ID); strcat(where_clause, " = "); strcat(where_clause, usr_str); @@ -1067,7 +1066,6 @@ Eina_List* get_registered_user_info() Eina_Bool is_chat_id_already_exists(struct tgl_chat *chat_info) { // get chat name chat id from chat_info_table - int t = 0; sqlite3* db = create_database(DEFAULT_TG_DATABASE_PATH); if(db) { char* table_name = CHAT_INFO_TABLE_NAME; @@ -1875,7 +1873,6 @@ void insert_media_info_to_db(struct tgl_message *M, char* file_path) int photo_loc_dc = -1; col_values = eina_list_append(col_values, &photo_loc_dc); - int photo_loc_vol = -1; col_values = eina_list_append(col_values, ""); int photo_loc_id = -1; @@ -1928,31 +1925,35 @@ void insert_media_info_to_db(struct tgl_message *M, char* file_path) for (int j = 0; j < 4; j++) { - char* photo_type = ""; - col_values = eina_list_append(col_values, photo_type); - - int photo_loc_dc = -1; - col_values = eina_list_append(col_values, &photo_loc_dc); - - int photo_loc_vol = -1; - col_values = eina_list_append(col_values, ""); - - int photo_loc_id = -1; - col_values = eina_list_append(col_values, &photo_loc_id); - - - col_values = eina_list_append(col_values, ""); + char *photo_type; + int *photo_loc_dc; + int *photo_loc_id; + int *photo_width; + int *photo_height; + int *photo_size; + char *photo_data; + + photo_type = strdup(" "); + photo_loc_dc = malloc(sizeof(*photo_loc_dc)); + *photo_loc_dc = -1; + photo_loc_id = malloc(sizeof(*photo_loc_id)); + *photo_loc_id = -1; + photo_width = malloc(sizeof(*photo_width)); + *photo_width = -1; + photo_height = malloc(sizeof(*photo_height)); + *photo_height = -1; + photo_size = malloc(sizeof(*photo_size)); + *photo_size = -1; + photo_data = strdup(" "); - int photo_width = -1; - col_values = eina_list_append(col_values, &photo_width); - - int photo_height = -1; - col_values = eina_list_append(col_values, &photo_height); - - int photo_size = -1; - col_values = eina_list_append(col_values, &photo_size); - - char* photo_data = ""; + col_values = eina_list_append(col_values, photo_type); + col_values = eina_list_append(col_values, photo_loc_dc); + col_values = eina_list_append(col_values, strdup(" ")); + col_values = eina_list_append(col_values, photo_loc_id); + col_values = eina_list_append(col_values, strdup(" ")); + col_values = eina_list_append(col_values, photo_width); + col_values = eina_list_append(col_values, photo_height); + col_values = eina_list_append(col_values, photo_size); col_values = eina_list_append(col_values, photo_data); } @@ -1982,31 +1983,30 @@ void insert_media_info_to_db(struct tgl_message *M, char* file_path) for (int j = 0; j < 4; j++) { - char* photo_type = ""; - col_values = eina_list_append(col_values, photo_type); - - int photo_loc_dc = -1; - col_values = eina_list_append(col_values, &photo_loc_dc); - - int photo_loc_vol = -1; - col_values = eina_list_append(col_values, ""); - - int photo_loc_id = -1; - col_values = eina_list_append(col_values, &photo_loc_id); - - - col_values = eina_list_append(col_values, ""); - - int photo_width = -1; - col_values = eina_list_append(col_values, &photo_width); + char* photo_type = strdup(" "); + int *photo_loc_dc = malloc(sizeof(*photo_loc_dc)); + int *photo_loc_vol = malloc(sizeof(*photo_loc_vol)); + int *photo_loc_id = malloc(sizeof(*photo_loc_id)); + int *photo_width = malloc(sizeof(*photo_width)); + int *photo_height = malloc(sizeof(*photo_height)); + int *photo_size = malloc(sizeof(*photo_size)); + char* photo_data = strdup(" "); + + *photo_loc_dc = -1; + *photo_loc_vol = -1; + *photo_loc_id = -1; + *photo_width = -1; + *photo_height = -1; + *photo_size = -1; - int photo_height = -1; - col_values = eina_list_append(col_values, &photo_height); - - int photo_size = -1; - col_values = eina_list_append(col_values, &photo_size); - - char* photo_data = ""; + col_values = eina_list_append(col_values, photo_type); + col_values = eina_list_append(col_values, photo_loc_dc); + col_values = eina_list_append(col_values, strdup(" ")); + col_values = eina_list_append(col_values, photo_loc_id); + col_values = eina_list_append(col_values, strdup(" ")); + col_values = eina_list_append(col_values, photo_width); + col_values = eina_list_append(col_values, photo_height); + col_values = eina_list_append(col_values, photo_size); col_values = eina_list_append(col_values, photo_data); } } @@ -2270,31 +2270,30 @@ void update_sent_media_info_in_db(struct tgl_message *M, long long unique_val) int j = i; for (j = i; j < 4; j++) { - char* photo_type = ""; - col_values = eina_list_append(col_values, photo_type); - - int photo_loc_dc = -1; - col_values = eina_list_append(col_values, &photo_loc_dc); - - int photo_loc_vol = -1; - col_values = eina_list_append(col_values, ""); - - int photo_loc_id = -1; - col_values = eina_list_append(col_values, &photo_loc_id); - + char* photo_type = strdup(" "); + int *photo_loc_dc = malloc(sizeof(*photo_loc_dc)); + int *photo_loc_vol = malloc(sizeof(*photo_loc_vol)); + int *photo_loc_id = malloc(sizeof(*photo_loc_id)); + int *photo_width = malloc(sizeof(*photo_width)); + int *photo_height = malloc(sizeof(*photo_height)); + int *photo_size = malloc(sizeof(*photo_size)); + char* photo_data = strdup(" "); + + *photo_loc_dc = -1; + *photo_loc_vol = -1; + *photo_loc_id = -1; + *photo_width = -1; + *photo_height = -1; + *photo_size = -1; - col_values = eina_list_append(col_values, ""); - - int photo_width = -1; - col_values = eina_list_append(col_values, &photo_width); - - int photo_height = -1; - col_values = eina_list_append(col_values, &photo_height); - - int photo_size = -1; - col_values = eina_list_append(col_values, &photo_size); - - char* photo_data = ""; + col_values = eina_list_append(col_values, photo_type); + col_values = eina_list_append(col_values, photo_loc_dc); + col_values = eina_list_append(col_values, strdup(" ")); + col_values = eina_list_append(col_values, photo_loc_id); + col_values = eina_list_append(col_values, strdup(" ")); + col_values = eina_list_append(col_values, photo_width); + col_values = eina_list_append(col_values, photo_height); + col_values = eina_list_append(col_values, photo_size); col_values = eina_list_append(col_values, photo_data); } @@ -2329,31 +2328,30 @@ void update_sent_media_info_in_db(struct tgl_message *M, long long unique_val) for (int j = 0; j < 4; j++) { - char* photo_type = ""; - col_values = eina_list_append(col_values, photo_type); + char* photo_type = strdup(" "); + int *photo_loc_dc = malloc(sizeof(*photo_loc_dc)); + int *photo_loc_vol = malloc(sizeof(*photo_loc_vol)); + int *photo_loc_id = malloc(sizeof(*photo_loc_id)); + int *photo_width = malloc(sizeof(*photo_width)); + int *photo_height = malloc(sizeof(*photo_height)); + int *photo_size = malloc(sizeof(*photo_size)); + char* photo_data = strdup(" "); + + *photo_loc_dc = -1; + *photo_loc_vol = -1; + *photo_loc_id = -1; + *photo_width = -1; + *photo_height = -1; + *photo_size = -1; - int photo_loc_dc = -1; - col_values = eina_list_append(col_values, &photo_loc_dc); - - int photo_loc_vol = -1; - col_values = eina_list_append(col_values, ""); - - int photo_loc_id = -1; - col_values = eina_list_append(col_values, &photo_loc_id); - - - col_values = eina_list_append(col_values, ""); - - int photo_width = -1; - col_values = eina_list_append(col_values, &photo_width); - - int photo_height = -1; - col_values = eina_list_append(col_values, &photo_height); - - int photo_size = -1; - col_values = eina_list_append(col_values, &photo_size); - - char* photo_data = ""; + col_values = eina_list_append(col_values, photo_type); + col_values = eina_list_append(col_values, photo_loc_dc); + col_values = eina_list_append(col_values, strdup(" ")); + col_values = eina_list_append(col_values, photo_loc_id); + col_values = eina_list_append(col_values, strdup(" ")); + col_values = eina_list_append(col_values, photo_width); + col_values = eina_list_append(col_values, photo_height); + col_values = eina_list_append(col_values, photo_size); col_values = eina_list_append(col_values, photo_data); } @@ -2383,31 +2381,30 @@ void update_sent_media_info_in_db(struct tgl_message *M, long long unique_val) for (int j = 0; j < 4; j++) { - char* photo_type = ""; - col_values = eina_list_append(col_values, photo_type); - - int photo_loc_dc = -1; - col_values = eina_list_append(col_values, &photo_loc_dc); - - int photo_loc_vol = -1; - col_values = eina_list_append(col_values, ""); - - int photo_loc_id = -1; - col_values = eina_list_append(col_values, &photo_loc_id); - - - col_values = eina_list_append(col_values, ""); - - int photo_width = -1; - col_values = eina_list_append(col_values, &photo_width); + char* photo_type = strdup(" "); + int *photo_loc_dc = malloc(sizeof(*photo_loc_dc)); + int *photo_loc_vol = malloc(sizeof(*photo_loc_vol)); + int *photo_loc_id = malloc(sizeof(*photo_loc_id)); + int *photo_width = malloc(sizeof(*photo_width)); + int *photo_height = malloc(sizeof(*photo_height)); + int *photo_size = malloc(sizeof(*photo_size)); + char* photo_data = strdup(" "); + + *photo_loc_dc = -1; + *photo_loc_vol = -1; + *photo_loc_id = -1; + *photo_width = -1; + *photo_height = -1; + *photo_size = -1; - int photo_height = -1; - col_values = eina_list_append(col_values, &photo_height); - - int photo_size = -1; - col_values = eina_list_append(col_values, &photo_size); - - char* photo_data = ""; + col_values = eina_list_append(col_values, photo_type); + col_values = eina_list_append(col_values, photo_loc_dc); + col_values = eina_list_append(col_values, strdup(" ")); + col_values = eina_list_append(col_values, photo_loc_id); + col_values = eina_list_append(col_values, strdup(" ")); + col_values = eina_list_append(col_values, photo_width); + col_values = eina_list_append(col_values, photo_height); + col_values = eina_list_append(col_values, photo_size); col_values = eina_list_append(col_values, photo_data); } } diff --git a/tg-engine-service/tg_engine/tg_engine.c b/tg-engine-service/tg_engine/tg_engine.c index c412b5e..226129f 100644 --- a/tg-engine-service/tg_engine/tg_engine.c +++ b/tg-engine-service/tg_engine/tg_engine.c @@ -298,7 +298,7 @@ void tg_marked_read(struct tgl_state *TLS, int num, struct tgl_message *list[]) } -void tg_logprintf(const char *format, ...) __attribute__((format(printf, 1, 2))) +void tg_logprintf(const char *format, ...) { } @@ -508,7 +508,7 @@ void tg_user_update(struct tgl_state *TLS, struct tgl_user *buddy, unsigned flag name_of_buddy = strdup(buddy->first_name); name_of_buddy_len = strlen(name_of_buddy); } else { - name_of_buddy = NO_NAME; + name_of_buddy = (char *)NO_NAME; name_of_buddy_len = strlen(NO_NAME); } @@ -517,7 +517,7 @@ void tg_user_update(struct tgl_state *TLS, struct tgl_user *buddy, unsigned flag * @note * Unable to allocate heap for buddy name */ - name_of_buddy = NO_NAME; + name_of_buddy = (char *)NO_NAME; name_of_buddy_len = strlen(NO_NAME); } @@ -1683,21 +1683,19 @@ void send_media_to_buddy(int buddy_id, int message_id, int media_id, int msg_typ #endif } -static const char *_ui_utils_get_res_path() -{ - char res_folder_path[PATH_MAX] = {'\0'}; - if (res_folder_path[0] == '\0') { - char *res_path_buff = app_get_resource_path(); - strncpy(res_folder_path, res_path_buff, PATH_MAX-1); - free(res_path_buff); - } - return res_folder_path; -} - static char *ui_utils_get_resource(const char *res_name) { static char res_path[PATH_MAX] = {'\0'}; - snprintf(res_path, PATH_MAX, "%s%s", _ui_utils_get_res_path(), res_name); + char *path; + + path = app_get_resource_path(); + if (!path) { + return NULL; + } + + snprintf(res_path, PATH_MAX, "%s%s", path, res_name); + free(path); + return res_path; } diff --git a/tg-engine-service/tg_engine_utils/tg_common.h b/tg-engine-service/tg_engine_utils/tg_common.h index b7a8450..0b919cc 100644 --- a/tg-engine-service/tg_engine_utils/tg_common.h +++ b/tg-engine-service/tg_engine_utils/tg_common.h @@ -24,10 +24,8 @@ typedef enum MESSAGE_STATE { TG_MESSAGE_STATE_UNKNOWN } TG_MESSAGE_STATE; - - //static char* get_table_name_from_number(const char* phone_no) -static char* get_table_name_from_number(const int id) +static char *get_table_name_from_number(const int id) { char id_str[50]; sprintf(id_str, "%d", id); -- 2.7.4