qlic.c (1795B)
1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h> 4 #include <qlic_common.h> 5 #include <cliq_apis.h> 6 #include <qlic_response_handler.h> 7 #include <qlic_oauth.h> 8 #include <qlic_private.h> 9 #include "config.h" 10 11 int qlic_send_text_msg(const char* __access_token, const char* __chat_id) { 12 QlicString* access_token = NULL; 13 access_token = init_qlic_string(); 14 access_token->len = strlen(__access_token); 15 access_token->string = (char*)malloc(access_token->len * sizeof(__access_token)); 16 strncpy(access_token->string, __access_token, access_token->len); 17 QlicContext* qlic_context = qlic_context_access_init(access_token); 18 if (qlic_context == NULL) { 19 qlic_error("Cannot init network library"); 20 return -1; 21 } 22 QlicString* chat_id = init_qlic_string(); 23 __QLIC_ASSIGN_STRING(chat_id, __chat_id); 24 qlic_context->request_url = qlic_send_message_str(chat_id); 25 qlic_request(qlic_context, qlic_handle_send_message, true); 26 return 0; 27 } 28 29 static void qlic_usage() { 30 fputs("usage: qlic [-va] [-r chat_id]\n", stderr); 31 exit(1); 32 } 33 34 // TODO Send error back 35 int main(int argc, char* argv[]) { 36 int i; 37 QlicContext* ctx = qlic_init(); 38 for (i = 1; i < argc; i++) { 39 if (!strcmp(argv[i], "-v")) { 40 fputs("qlic"QLIC_VERSION"\n", stderr); 41 } else if (!strcmp(argv[i], "-a")) { 42 char* access_token = start_oauth_server(ctx); 43 if (access_token == NULL) { 44 qlic_error("Access token is empty, authentication failed"); 45 return -1; 46 } 47 /* these options take one argument */ 48 } else if (!strcmp(argv[i], "-r")) { 49 // TODO read access_token from state.json 50 char* access_token = "1000.429cf5132d6cc978960bfdd6e0a425cc.80bbd5584b0c35133c4f82143e6811b2"; 51 // FIXME possible buffer overflow here 52 qlic_send_text_msg(access_token, argv[++i]); 53 } else { 54 qlic_usage(); 55 } 56 } 57 return 0; 58 } 59