afify / azan (public) (License: MIT) (since 2020-03-08) (hash sha1)
azan is a simple muslim prayers notifier for unix-like systems.
List of commits:
Subject Hash Author Date (UTC)
[fix] [Valgrind] Memory leaks, stack errors. f06c1192c98f0405b727b9ca4346ed7262476c33 Hassan Afify 2019-09-24 16:02:56
[fix] create_cache bug, clean Makefile *.log 7d998c3f864fe07102b3fa07f83ea754159a9927 Hassan Afify 2019-09-24 05:38:39
[feat] argument options, next_fajr 4cd6ef1633f3e5cd3afe36be70e9c718911e701d Hassan Afify 2019-09-23 09:38:57
[doc] Update CONTRIBUTING, README & man page a16565d0b498313a8df232d3e2f5e7c1367dc191 Hassan Afify 2019-09-22 10:23:25
[doc] Update CONTRIBUTING, README & man page 0b978479fbe5d6e626a55a5ac78231393a267025 Hassan Afify 2019-09-22 10:23:25
[feat] Edit Makefile, Add config.def.h, config.mk c9e13a7b6dcc00894620f5788c04f4afba0f59d4 Hassan Afify 2019-09-21 17:11:34
[fix] Replace CODE_STYLE with CONTRIBUTING.md be2b91ef8d73aea536bc45446808633561d8afd9 Hassan Afify 2019-09-21 11:14:30
[feat] Edit Makefile, azan.c 538877a4311572caa1ddb88ffd0bac5e0b4379bc Hassan Afify 2019-09-20 12:59:05
[feat] Edit Makefile f41f74a524feb96228eb35a77a336862d5ca958c Hassan Afify 2019-09-19 05:04:00
[feat] Self Calcutation 1be712f454adda33c8a182a4478a3abf5dba6745 Hassan Afify 2019-09-17 08:11:15
[init] Initial Commit 2654768d0412e07cf7aa4b78a41b125aeceab82e Hassan Afify 2019-09-04 01:44:23
Commit f06c1192c98f0405b727b9ca4346ed7262476c33 - [fix] [Valgrind] Memory leaks, stack errors.
- free memory.
- in read_cache_file: fix loop
- assign pointer to NULL after free()
- check returned pointer form functions and free

* Valgrind result:
- total heap usage: 15 allocs, 15 frees
- SUMMARY: 0 errors from 0 contexts
Author: Hassan Afify
Author date (UTC): 2019-09-24 16:02
Committer name: Hassan Afify
Committer date (UTC): 2019-09-24 16:02
Parent(s): 7d998c3f864fe07102b3fa07f83ea754159a9927
Signing key: 0F6CD1196B2A5658
Tree: ec30efbc36c4b53efe33f9fd66990468c5e8c209
File Lines added Lines deleted
azan.c 45 23
azan.h 1 1
File azan.c changed (mode: 100644) (index bed1c2a..ba30940)
... ... create_cache_file(time_t t, char* full_path)
376 376 (long)prayer_array[5] (long)prayer_array[5]
377 377 ); );
378 378
379 free(cache_dir);
380 cache_dir = NULL;
379 381 (void)fclose(fpointer); (void)fclose(fpointer);
380 382 } }
381 383
 
... ... read_azan_cache_file(char* azan_cache_file)
398 400 (void)fclose(fp); (void)fclose(fp);
399 401
400 402 time_t* pray_times_array; /* the returned array */ time_t* pray_times_array; /* the returned array */
401 pray_times_array = calloc(6, sizeof(time_t));
403 pray_times_array = calloc(12, sizeof(time_t));
402 404
403 405 if (pray_times_array == NULL) { if (pray_times_array == NULL) {
404 406 printf("Error, allocating memory [ Line %d ]\n", __LINE__); printf("Error, allocating memory [ Line %d ]\n", __LINE__);
405 407 exit(EXIT_FAILURE); exit(EXIT_FAILURE);
406 408 } }
407
408 409 char* tmp_pray[6]; /* string array hold temp values for checking */ char* tmp_pray[6]; /* string array hold temp values for checking */
409 410
410 411 /* /*
411 * split each key value sepeated by <,>
412 * the first strtok should take the string
412 * split each key value sepeated by <\n>
413 * the first strtok take the string
413 414 * if the value is not NULL: * if the value is not NULL:
414 * 1-clean_json string, 2-convert to time_t 3-assign to returned array
415 * 1-convert to time_t 2-assign to returned array
415 416 */ */
416 417 char delim[] = "\n"; char delim[] = "\n";
417 418
418 for(int i=0; i<6; i++){
419 if (i == 0) {
420 tmp_pray[0] = strtok(buffer, delim);
421 } else {
422 tmp_pray[i] = strtok(NULL, delim);
423 }
419 tmp_pray[0] = strtok(buffer, delim);
420 if (tmp_pray[0] != NULL) {
421 pray_times_array[0] = (time_t)atol(tmp_pray[0]);
422 }
423
424 for(int i=1; i<5; i++){
425 tmp_pray[i] = strtok(NULL, delim);
424 426 if (tmp_pray[i] != NULL) { if (tmp_pray[i] != NULL) {
425 427 pray_times_array[i] = (time_t)atol(tmp_pray[i]); pray_times_array[i] = (time_t)atol(tmp_pray[i]);
426 428 } }
427 429 } }
428 430
429 return pray_times_array;
431 if (pray_times_array != NULL) {
432 return pray_times_array;
433 } else {
434 exit(EXIT_FAILURE);
435 }
430 436 } }
431 437
432 438 static int static int
 
... ... print_next_prayer(time_t current_time, char* azan_cache_file)
452 458 } }
453 459
454 460 free(azan_array); free(azan_array);
461 azan_array = NULL;
455 462 return 0; return 0;
456 463 } }
457 464
 
... ... get_cache_dir(void)
515 522 char* cache_dir; char* cache_dir;
516 523 cache_dir = calloc(128, sizeof(char)); cache_dir = calloc(128, sizeof(char));
517 524
518 if (user_home == NULL) {
525 if (user_home == NULL || cache_dir == NULL) {
519 526 printf("Error, allocating memory [ Line %d ]\n", __LINE__); printf("Error, allocating memory [ Line %d ]\n", __LINE__);
520 527 exit(EXIT_FAILURE); exit(EXIT_FAILURE);
521 528 } }
 
... ... get_cache_file_name(time_t t)
540 547 (void)snprintf(azan_cache_file, max_file_name, "azan_%.2i-%.2i-%i.txt", (void)snprintf(azan_cache_file, max_file_name, "azan_%.2i-%.2i-%i.txt",
541 548 day, month, year); day, month, year);
542 549
543 static char full_path[256];
550 char* full_path = calloc(128, sizeof(char));
551 if (full_path == NULL) {
552 printf("Error! reading array [ Line %d ]\n", __LINE__);
553 exit(EXIT_FAILURE);
554 }
544 555 strcpy(full_path, cache_dir); strcpy(full_path, cache_dir);
545 556 strcat(full_path, "/"); strcat(full_path, "/");
546 557 strcat(full_path, azan_cache_file); strcat(full_path, azan_cache_file);
547 558
559 free(cache_dir);
548 560 return full_path; return full_path;
549 561 } }
550 562
551 static void
563 static int
552 564 send_notification(char* azan_cache_file) send_notification(char* azan_cache_file)
553 565 { {
554 566 time_t* azan_array; time_t* azan_array;
 
... ... send_notification(char* azan_cache_file)
564 576 strncpy(command, body, sizeof(char)*sizeof(body)); strncpy(command, body, sizeof(char)*sizeof(body));
565 577
566 578 for (int i=0; i<5; i++) { for (int i=0; i<5; i++) {
567 // convert_timet_to_str;
568 579 char prayer_first_letter = conv_prayer_int_to_char(i); char prayer_first_letter = conv_prayer_int_to_char(i);
569 580 char pfl[3]; char pfl[3];
570 581 pfl[0] = prayer_first_letter; pfl[0] = prayer_first_letter;
 
... ... send_notification(char* azan_cache_file)
574 585 strncat(command, pfl, sizeof(char)*3); strncat(command, pfl, sizeof(char)*3);
575 586 strncat(command, prayer_time, sizeof(char)*128); strncat(command, prayer_time, sizeof(char)*128);
576 587 strncat(command, "\\n", sizeof(char)*2); strncat(command, "\\n", sizeof(char)*2);
577 // printf("%c %s\n", prayer_first_letter, prayer_time);
578 588 free(prayer_time); free(prayer_time);
589 prayer_time = NULL;
579 590 } }
580 591 strncat(command, "'", sizeof(char)*1); strncat(command, "'", sizeof(char)*1);
592
581 593 free(azan_array); free(azan_array);
582 (void)system(command);
594 azan_array = NULL;
595 if (system(command) == 0){
596 return 0;
597 } else {
598 return -1;
583 599 } }
600 }
584 601
585 602 int int
586 603 main(int argc, char *argv[]) main(int argc, char *argv[])
 
... ... main(int argc, char *argv[])
596 613 (void)puts("azan-"VERSION); (void)puts("azan-"VERSION);
597 614 break; break;
598 615 case 'n': case 'n':
599 send_notification(full_path);
616 if (send_notification(full_path) < 0){
617 printf("Error Creating Cache File\n");
618 return -1;
619 }
620 free(full_path);
621 full_path = NULL;
600 622 break; break;
601 623 case 'a': case 'a':
602 624 print_all_prayers(full_path); print_all_prayers(full_path);
625 free(full_path);
626 full_path = NULL;
603 627 break; break;
604 628 case 'h': case 'h':
605 629 usage(); usage();
 
... ... main(int argc, char *argv[])
614 638 /* Create cache file if not exists */ /* Create cache file if not exists */
615 639 if (create_cache_file(t, full_path) < 0) { if (create_cache_file(t, full_path) < 0) {
616 640 printf("Error Creating Cache File\n"); printf("Error Creating Cache File\n");
617 free(full_path);
618 full_path = NULL;
619 641 return -1; return -1;
620 642 } }
621 643
622 644 /* Read cache file */ /* Read cache file */
623 645 if (print_next_prayer(t, full_path) < 0){ if (print_next_prayer(t, full_path) < 0){
624 646 printf("Error Reading Cache File\n"); printf("Error Reading Cache File\n");
625 free(full_path);
626 full_path = NULL;
627 647 return -1; return -1;
628 648 } }
649 free(full_path);
650 full_path = NULL;
629 651 } }
630 652
631 653 return 0; return 0;
File azan.h changed (mode: 100644) (index 4195b9c..d6e15a3)
... ... static int print_all_prayers(char* azan_cache_file);
48 48 static char conv_prayer_int_to_char(int pray_numb); static char conv_prayer_int_to_char(int pray_numb);
49 49 static char* get_cache_file_name(time_t t); static char* get_cache_file_name(time_t t);
50 50 static char* get_cache_dir(void); static char* get_cache_dir(void);
51 static void send_notification(char* azan_cache_file);
51 static int send_notification(char* azan_cache_file);
52 52
53 53 // static Prayer todays_prayers[6] = { // static Prayer todays_prayers[6] = {
54 54 // // prayer_name, hour, min, todays_timestamp, equation_oftime // // prayer_name, hour, min, todays_timestamp, equation_oftime
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/afify/azan

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/afify/azan

Clone this repository using git:
git clone git://git.rocketgit.com/user/afify/azan

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main