@@ -324,6 +324,7 @@ void get_ba_member_email(uint64_t userid, char** email /*OUT*/, size_t *length /
324
324
{
325
325
binresult * bres ;
326
326
const binresult * users ;
327
+ char * fname , * lname ;
327
328
328
329
binparam params [] = { P_STR ("auth" , psync_my_auth ), P_STR ("timeformat" , "timestamp" ), P_NUM ("userids" , userid ) };
329
330
bres = psync_api_run_command ("account_users" , params );
@@ -342,17 +343,21 @@ void get_ba_member_email(uint64_t userid, char** email /*OUT*/, size_t *length /
342
343
debug (D_WARNING , "Account_users returned empty result!\n" );
343
344
return ;
344
345
} else {
345
- const char * emailret = psync_find_result (users -> array [0 ], "email" , PARAM_STR )-> str ;
346
- * length = strlen (emailret );
347
- * email = psync_strndup (emailret , * length );
346
+ const char * resret = psync_find_result (users -> array [0 ], "email" , PARAM_STR )-> str ;
347
+ * length = strlen (resret );
348
+ * email = psync_strndup (resret , * length );
349
+ fname = psync_find_result (users -> array [0 ], "firstname" , PARAM_STR )-> str ;
350
+ lname = psync_find_result (users -> array [0 ], "lastname" , PARAM_STR )-> str ;
348
351
}
349
352
psync_free (bres );
350
353
351
354
if (* length ) {
352
355
psync_sql_res * q ;
353
- q = psync_sql_prep_statement ("INSERT INTO baccountemail (id, mail) VALUES (?, ?)" );
356
+ q = psync_sql_prep_statement ("REPLACE INTO baccountemail (id, mail, firstname, lastname ) VALUES (?, ?, ?, ?)" );
354
357
psync_sql_bind_uint (q , 1 , userid );
355
358
psync_sql_bind_lstring (q , 2 , * email , * length );
359
+ psync_sql_bind_lstring (q , 3 , fname , strlen (fname ));
360
+ psync_sql_bind_lstring (q , 4 , lname , strlen (lname ));
356
361
psync_sql_run_free (q );
357
362
}
358
363
@@ -437,7 +442,7 @@ void get_ba_team_name(uint64_t teamid, char** name /*OUT*/, size_t *length /*OUT
437
442
438
443
binresult * bres ;
439
444
int i ;
440
- const binresult * users ;
445
+ const binresult * teams ;
441
446
442
447
res = psync_sql_query ("SELECT name FROM baccountteam WHERE id=?" );
443
448
psync_sql_bind_uint (res , 1 , teamid );
@@ -462,23 +467,19 @@ void get_ba_team_name(uint64_t teamid, char** name /*OUT*/, size_t *length /*OUT
462
467
if (api_error_result (bres ))
463
468
return ;
464
469
465
- users = psync_find_result (bres , "teams" , PARAM_ARRAY );
470
+ teams = psync_find_result (bres , "teams" , PARAM_ARRAY );
466
471
467
472
//debug(D_NOTICE, "Result contains %d teams\n", users->length);
468
473
469
- if (!users -> length ){
474
+ if (!teams -> length ){
470
475
psync_free (bres );
471
476
debug (D_WARNING , "Account_teams returned empty result!\n" );
472
477
return ;
473
- } else {
474
-
475
- for (i = 0 ; i < users -> length ; ++ i ){
476
- //vis(i, users->array[i], param);
477
- const char * emailret = "" ;
478
- emailret = psync_find_result (users -> array [i ], "name" , PARAM_STR )-> str ;
479
- * length = strlen (emailret );
480
- * name = psync_strndup (emailret , * length );
481
- }
478
+ } else {
479
+ const char * teamret = "" ;
480
+ teamret = psync_find_result (teams -> array [0 ], "name" , PARAM_STR )-> str ;
481
+ * length = strlen (teamret );
482
+ * name = psync_strndup (teamret , * length );
482
483
}
483
484
psync_free (bres );
484
485
@@ -488,8 +489,7 @@ void get_ba_team_name(uint64_t teamid, char** name /*OUT*/, size_t *length /*OUT
488
489
psync_sql_bind_lstring (q , 2 , * name , * length );
489
490
psync_sql_run_free (q );
490
491
491
- return ;
492
-
492
+ return ;
493
493
}
494
494
495
495
// static void insert_cache_email(int i, const binresult *user, void *_this) {
@@ -517,9 +517,6 @@ void get_ba_team_name(uint64_t teamid, char** name /*OUT*/, size_t *length /*OUT
517
517
// }
518
518
519
519
void cache_account_emails () {
520
- psync_sql_res * q ;
521
-
522
- //do_psync_account_users(userids, 0, &insert_cache_email, params);
523
520
binresult * bres ;
524
521
int i ;
525
522
const binresult * users ;
@@ -546,7 +543,7 @@ void cache_account_emails() {
546
543
debug (D_WARNING , "Account_users returned empty result!\n" );
547
544
goto end_close ;
548
545
} else {
549
-
546
+ psync_sql_res * q ;
550
547
psync_sql_start_transaction ();
551
548
q = psync_sql_prep_statement ("DELETE FROM baccountemail" );
552
549
if (unlikely (psync_sql_run_free (q ))) {
@@ -556,21 +553,31 @@ void cache_account_emails() {
556
553
557
554
for (i = 0 ; i < users -> length ; ++ i ) {
558
555
const char * nameret = 0 ;
559
- const binresult * team = users -> array [i ];
560
- uint64_t teamid = 0 ;
556
+ const binresult * user = users -> array [i ];
557
+ uint64_t userid = 0 ;
561
558
psync_sql_res * res ;
562
-
563
- nameret = psync_find_result (team , "name" , PARAM_STR )-> str ;
564
- teamid = psync_find_result (team , "id" , PARAM_NUM )-> num ;
565
- //debug(D_NOTICE, "Team name %s team id %lld\n", nameret,(long long)teamid);
566
-
567
- res = psync_sql_prep_statement ("INSERT INTO baccountteam (id, name) VALUES (?, ?)" );
568
- psync_sql_bind_uint (res , 1 , teamid );
569
- psync_sql_bind_lstring (res , 2 , nameret , strlen (nameret ));
570
- if (unlikely (psync_sql_run_free (res ))) {
571
- psync_sql_rollback_transaction ();
572
- goto end_close ;
573
- }
559
+ char * fname , * lname ;
560
+ int active = 0 ;
561
+ int frozen = 0 ;
562
+
563
+ active = psync_find_result (user , "active" , PARAM_BOOL )-> num ;
564
+ frozen = psync_find_result (user , "frozen" , PARAM_BOOL )-> num ;
565
+ nameret = psync_find_result (user , "email" , PARAM_STR )-> str ;
566
+ userid = psync_find_result (user , "id" , PARAM_NUM )-> num ;
567
+ fname = psync_find_result (user , "firstname" , PARAM_STR )-> str ;
568
+ lname = psync_find_result (user , "lastname" , PARAM_STR )-> str ;
569
+
570
+ if (userid && (active || frozen )) {
571
+ res = psync_sql_prep_statement ("INSERT INTO baccountemail (id, mail, firstname, lastname) VALUES (?, ?, ?, ?)" );
572
+ psync_sql_bind_uint (res , 1 , userid );
573
+ psync_sql_bind_lstring (res , 2 , nameret , strlen (nameret ));
574
+ psync_sql_bind_lstring (res , 3 , fname , strlen (fname ));
575
+ psync_sql_bind_lstring (res , 4 , lname , strlen (lname ));
576
+ if (unlikely (psync_sql_run_free (res ))) {
577
+ psync_sql_rollback_transaction ();
578
+ goto end_close ;
579
+ }
580
+ }
574
581
}
575
582
psync_sql_commit_transaction ();
576
583
}
@@ -646,8 +653,10 @@ void cache_account_teams() {
646
653
res = psync_sql_prep_statement ("INSERT INTO baccountteam (id, name) VALUES (?, ?)" );
647
654
psync_sql_bind_uint (res , 1 , teamid );
648
655
psync_sql_bind_lstring (res , 2 , nameret , strlen (nameret ));
649
- psync_sql_run_free (res );
656
+ if (unlikely (psync_sql_run_free (res )))
657
+ psync_sql_rollback_transaction ();
650
658
}
659
+ psync_sql_commit_transaction ();
651
660
//vis(i, users->array[i], param);
652
661
}
653
662
psync_free (bres );
0 commit comments