initial commit

This commit is contained in:
root
2024-06-03 16:43:53 +03:00
commit 21e3fd0797
1535 changed files with 60499 additions and 0 deletions

BIN
junet/Auth/.db.h.un~ Normal file

Binary file not shown.

10
junet/Auth/Makefile Normal file
View File

@@ -0,0 +1,10 @@
TARGET: auth_exe
auth_exe: auth.o main.o
gcc auth.o main.o -o auth_exe `mysql_config --cflags --libs` -lm
auth.o: auth.c
gcc -c auth.c -o auth.o
main.o: main.c
gcc -c main.c -o main.o `mysql_config --cflags --libs`
clean:
rm auth.o
rm main.o

71
junet/Auth/auth.c Normal file
View File

@@ -0,0 +1,71 @@
#include "auth.h"
ld
toRadians(ld degree){
ld one_deg = (M_PI)/180;
return (one_deg * degree);
}
ld
sq_root(ld value){
ld err = 1e-10;
ld ans = 0;
ld low = 0 , high = 0;
if(value < 1){
low = value , high = 1;
}
else{
low = 1 , high = value;
}
for(int i = 1 ; i <= 67 ; i++ ){
ld mid = low + (high - low)/2.0;
if( mid*mid <= value ){
ans = mid;
low = mid + err;
}
else{
high = mid - err;
}
}
return ans;
}
ld
orthodromic_distance(ld stu_lat,ld stu_long,ld teach_lat,ld teach_long){
stu_lat = toRadians(stu_lat);
stu_long = toRadians(stu_long);
teach_lat = toRadians(teach_lat);
teach_long = toRadians(teach_long);
ld diff_lat = teach_lat - stu_lat;
ld diff_long = teach_long - stu_long;
ld ans = pwr2(sin(diff_lat/2)) +
cos(stu_lat) * cos(teach_lat) *
pwr2(sin(diff_long/2));
ans = 2 * asin(sq_root(ans));
// Radius of Earth in
// Kilometers, R = 6371
// Use R = 3956 for miles
ld R = 6371;
//ans in meter...
ans = ans * R * (ld)1000;
return ans;
}
bool
check_range(ld dist){
//better implementation for future....
return dist <= (ld)100;
}

27
junet/Auth/auth.h Normal file
View File

@@ -0,0 +1,27 @@
#ifndef __AUTH__
#define __AUTH__
#ifndef _MATH_H_
#include <math.h>
#endif
#ifndef _STDBOOL_H
#include <stdbool.h>
#endif
#define ld long double
#define pwr2(x) (x * x)
ld
sq_root(ld x);
ld
toRadians( ld degree );
ld
orthodromic_distance(ld stu_lat, ld stu_long, ld teach_lat, ld teach_long);
bool
check_range(ld dist);
#endif // __AUTH__

BIN
junet/Auth/auth_exe Normal file

Binary file not shown.

41
junet/Auth/db.h Normal file
View File

@@ -0,0 +1,41 @@
#ifndef __DB_H_
#define __DB_H_
#include <mysql.h>
#ifndef __STDIO_H
#include <stdio.h>
#endif
#ifndef __STDLIB_H
#include <stdlib.h>
#endif
#ifndef __STRING_H
#include <string.h>
#endif
#ifndef __STDARG_H
#include <stdarg.h>
#endif
void
connect_to_db(char db[],MYSQL *con);
void
retrieve_table(char table[],MYSQL *con);
MYSQL_RES *
extract_table(MYSQL *con);
int
num_of_entries(MYSQL_RES *result_table);
#define ITERATE_TABLE(row,result) { \
while( (row = mysql_fetch_row(result) ) ) {
#define ITERATE_TABLE_END }}
#endif

27
junet/Auth/db.h~ Normal file
View File

@@ -0,0 +1,27 @@
#ifndef __DB_H_
#define __DB_H_
#include <mysql.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
void
connect_to_db(char db[],MYSQL *con);
void
retrieve_table(char table[],MYSQL *con);
MYSQL_RES *
extract_table(MYSQL *con);
int
num_of_entries(MYSQL_RES *result_table);
#define ITERATE_TABLE(row,result) { \
while( (row = mysql_fetch_row(result) ) ) {
#define ITERATE_TABLE_END }}
#endif

87
junet/Auth/main.c Normal file
View File

@@ -0,0 +1,87 @@
#include<stdio.h>
#include<stdlib.h>
#include <string.h>
#include<mysql.h>
#include "auth.h"
void
error_found(MYSQL *con){
printf("%s\n",mysql_error(con));
mysql_close(con);
}
int
main(int argv , char **argc){
//Pass the Teacher latitude and longitude from command line argument.
//Teacher latitude and longitude...
ld teach_lat = strtold(argc[1],NULL) , teach_long = strtold(argc[2],NULL);
MYSQL *con = mysql_init(NULL);
if( con == NULL ){
printf("mysql_init() failed\n");
return 0;
}
if( mysql_real_connect(con,"localhost","usr","admin@1224"
,"bpitattendance", 0,NULL,0) == NULL ){
error_found(con);
}
if( mysql_query(con, "SELECT * FROM attendance") ){
error_found(con);
}
MYSQL_RES *result = mysql_store_result(con);
if( result == NULL ){
error_found(con);
}
int num_fields = mysql_num_fields(result);
MYSQL_ROW row;
int enroll = 0;
long double stu_lat = 0 , stu_long = 0;
long double dist = 0;
char en_num[15];
char query[150]="";
while( (row = mysql_fetch_row(result) ) ){
enroll = (int)strtoll(row[0],NULL,10);
stu_lat = strtold(row[1],NULL);
stu_long = strtold(row[2],NULL);
strcpy(query,"");
sprintf(en_num,"%d",enroll);
dist = orthodromic_distance(stu_lat,stu_long,teach_lat,teach_long);
if( check_range(dist) ){
strcat(query,"UPDATE attendance SET is_present = true WHERE enroll_num =");
strcat(query,en_num);
strcat(query,";");
if( mysql_query(con, query ) ){
error_found(con);
}
printf("%ld is present\n",enroll);
}
else{
strcat(query,"UPDATE attendance SET is_present = false WHERE enroll_num =");
strcat(query,en_num);
strcat(query,";");
if( mysql_query(con,query ) ){
error_found(con);
}
printf("%ld is absent\n",enroll);
}
}
mysql_free_result(result);
mysql_close(con);
return 0;
}