• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

*NIXコンソール用Google ToDo(Tasks) クライアント


Commit MetaInfo

Revision57b88b17f31e853c7479bded797a1edd78075cd9 (tree)
Zeit2020-01-15 21:40:23
AutorKoine Yuusuke(koinec) <koinec@user...>
CommiterKoine Yuusuke(koinec)

Log Message

  • WorkBackup

Ändern Zusammenfassung

Diff

--- a/src/libtodo.h
+++ b/src/libtodo.h
@@ -69,6 +69,8 @@ LIBTODO_API_API_EXTERN
6969 LIBTODO_API_API_EXTERN
7070 int LibToDo_CreateUserOAuthURL( char *pstr_url );
7171 LIBTODO_API_API_EXTERN
72+ int LibToDo_CreateConfigFile( char *pstr_code );
73+LIBTODO_API_API_EXTERN
7274 int LibToDo_GetData( LibToDo_Data *p_data, int i_id );
7375 LIBTODO_API_API_EXTERN
7476 int LibToDo_GetTopDataID( void );
--- a/src/libtodo_api.c
+++ b/src/libtodo_api.c
@@ -80,6 +80,24 @@ int
8080 /* ===================================================================*/
8181 LIBTODO_API_API_EXTERN
8282 int
83+ LibToDo_CreateConfigFile(
84+ char *pstr_code )
85+{
86+ int i_result;
87+
88+ if( NULL == pstr_code ) {
89+ return -0x01;
90+ }
91+
92+ i_result = ConfigFile_CreateConfig( pstr_code );
93+
94+ return i_result;
95+}
96+
97+
98+/* ===================================================================*/
99+LIBTODO_API_API_EXTERN
100+int
83101 LibToDo_GetData(
84102 LibToDo_Data *p_data,
85103 int i_id )
--- a/src/libtodo_configfile.c
+++ b/src/libtodo_configfile.c
@@ -138,16 +138,58 @@ int
138138 ConfigFile_CreateConfig(
139139 char *pstr_code )
140140 {
141- //int i_len;
142- //FILE *fp;
143- //char str_buf[1024];
141+ int i_len;
142+ int i_result;
143+ FILE *fp;
144+ char str_buf[1024];
144145 struct stat t_buf;
145146
146147 if( 0x00 == stat( gstr_configfile, &t_buf ) ) { return 0x01; }
147148
148149 memset( &gt_config, 0x00, sizeof( LibToDo_Config ) );
149150
150- ConfigFile_WriteConfig();
151+
152+ fp = fopen("../../todocmd.conf", "r" );
153+ if( NULL == fp ) {
154+ return -0x01;
155+ }
156+
157+ do {
158+ if( NULL == fgets( str_buf, 1024, fp )) { break; }
159+
160+ i_len = strnlen( str_buf, 1024 );
161+ if( 14 > i_len ) { continue; }
162+
163+ str_buf[13] = '\0'; // '=' -> NULL (for seperate key & value)
164+ if( '\n' == str_buf[i_len - 1] ) {
165+ str_buf[i_len - 1] = '\0';
166+ i_len--;
167+ }
168+ if( !strcmp( str_buf, "client_id " ))
169+ { strncpy( gt_config.str_client_id, (str_buf + 14), 256 ); }
170+ if( !strcmp( str_buf, "client_secret" ))
171+ { strncpy( gt_config.str_client_secret, (str_buf + 14), 256 ); }
172+
173+ }while( !feof(fp) );
174+ fclose( fp );
175+
176+ strncpy( gt_config.str_code, pstr_code, 256 );
177+
178+ i_result = GLAPI_Base_GetToken();
179+ if( 0x00 != i_result ) {
180+ return -0x02;
181+ }
182+
183+ //printf( "access_token =%s\n", gt_config.str_access_token );
184+ //printf( "refresh_token=%s\n", gt_config.str_refresh_token );
185+ //printf( "token_type =%s\n", gt_config.str_token_type );
186+ //printf( "client_id =%s\n", gt_config.str_client_id );
187+ //printf( "client_secret=%s\n", gt_config.str_client_secret );
188+
189+ i_result = ConfigFile_WriteConfig();
190+ if( 0x00 != i_result ) {
191+ return -0x03;
192+ }
151193
152194 return 0x00;
153195 }
--- a/src/libtodo_configfile.h
+++ b/src/libtodo_configfile.h
@@ -45,6 +45,8 @@ LIBTODO_CONFIGFILE_EXTERN
4545 LIBTODO_CONFIGFILE_EXTERN
4646 int ConfigFile_Global_CreateOAuthURL( char *pstr_url );
4747 LIBTODO_CONFIGFILE_EXTERN
48+ int ConfigFile_CreateConfig( char *pstr_code );
49+LIBTODO_CONFIGFILE_EXTERN
4850 void ConfigFile_SetConfigFilePath( char *pstr_cfgpath );
4951 LIBTODO_CONFIGFILE_EXTERN
5052 int ConfigFile_ReadConfig( void );
--- a/src/libtodo_glapi_base.c
+++ b/src/libtodo_glapi_base.c
@@ -269,17 +269,19 @@ int
269269 LIBTODO_GLAPI_BASE_EXTERN
270270 int
271271 GLAPI_Base_GetToken(
272- char *pstr_code )
272+ void )
273273 {
274274 int i_result;
275- //json_object *p_json;
275+ json_object *p_json;
276+ json_object *p_jerr;
276277 GLAPI_Result t_glrefresh;
278+ char str_err[64];
277279
278280 GLAPI_Base_AllocResultArea( &t_glrefresh );
279281
280282 snprintf( (char *)t_glrefresh.pb_request, 32767,
281- "code=%s&client_id=%s&client_secret=%sredirect_uri=urn%%3Aietf%%3Awg%%3Aoauth%%3A2.0%%3Aoob&grant_type=authorization_code&access_type=offline",
282- pstr_code, gt_config.str_client_id, gt_config.str_client_secret );
283+ "code=%s&client_id=%s&client_secret=%s&redirect_uri=urn%%3Aietf%%3Awg%%3Aoauth%%3A2.0%%3Aoob&grant_type=authorization_code&access_type=offline",
284+ gt_config.str_code, gt_config.str_client_id, gt_config.str_client_secret );
283285
284286 i_result = GLAPI_Base_SendAPI( &t_glrefresh, SENDAPI_MODE_POST, LIBTODO_GL_TOKEN_URI, NULL );
285287 if( 0 > i_result ) {
@@ -287,11 +289,17 @@ int
287289 return -0x01;
288290 }
289291
290-/* XXX (2020/01/14)
291292 p_json = json_tokener_parse( (const char *)t_glrefresh.pb_result );
292- i_result = ProcJson_GetAccessToken( p_json );
293+
294+ p_jerr = ProcJson_GetJsonChildString( str_err, p_json, "error", 64 );
295+ if( NULL == p_jerr ) {
296+ ProcJson_GetJsonChildString( gt_config.str_access_token, p_json, "access_token", 256 );
297+ ProcJson_GetJsonChildString( gt_config.str_refresh_token, p_json, "refresh_token", 256 );
298+ ProcJson_GetJsonChildString( gt_config.str_token_type, p_json, "token_type", 64 );
299+ }
300+
293301 json_object_put( p_json );
294-*/
302+
295303 GLAPI_Base_FreeResultArea( &t_glrefresh );
296304
297305 return 0x00;
--- a/src/libtodo_glapi_base.h
+++ b/src/libtodo_glapi_base.h
@@ -61,6 +61,8 @@ LIBTODO_GLAPI_BASE_EXTERN
6161 LIBTODO_GLAPI_BASE_EXTERN
6262 int GLAPI_Base_RefreshToken( void );
6363 LIBTODO_GLAPI_BASE_EXTERN
64+ int GLAPI_Base_GetToken( void );
65+LIBTODO_GLAPI_BASE_EXTERN
6466 int GLAPI_Base_DoAPI( GLAPI_Result *p_glresult, Byte b_mode, char *pstr_url );
6567
6668 #endif
--- a/src/todocmd_setup.c
+++ b/src/todocmd_setup.c
@@ -39,13 +39,13 @@ int
3939 Setup_SetupScenery(
4040 void )
4141 {
42- int i_err;
42+ int i_len;
4343 int i_result;
4444 char str_url[1024];
4545 char str_code[512];
4646
47- i_err = LibToDo_CreateUserOAuthURL( str_url );
48- if( 0x00 != i_err ) {
47+ i_result = LibToDo_CreateUserOAuthURL( str_url );
48+ if( 0x00 != i_result ) {
4949 return -0x01;
5050 }
5151
@@ -57,6 +57,12 @@ int
5757
5858 fgets( str_code, 512, stdin );
5959
60+ i_len = strnlen( str_code, 512 );
61+ if( 0 < i_len ) {
62+ str_code[i_len - 1] = '\0';
63+ i_len--;
64+ }
65+
6066 puts(" Is the input code correct below? (Y/N): " );
6167
6268 printf(" CODE: [%s]\n", str_code );
@@ -65,8 +71,12 @@ int
6571 return 0x00;
6672 }
6773
74+ i_result = LibToDo_CreateConfigFile( str_code );
75+ if( 0x00 != i_result ) {
76+ return -0x02;
77+ }
6878
69-
79+ puts(" Success! - Create ConfigFile.");
7080
7181 return 0x00;
7282 }