-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpush.c
More file actions
62 lines (48 loc) · 1.39 KB
/
Copy pathpush.c
File metadata and controls
62 lines (48 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <arpa/inet.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdlib.h>
//socket stuff
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <signal.h>
#include <netdb.h>
#include <fcntl.h>
//for mkdir
#include <sys/stat.h>
#include "utils.h"
#include "file_transfer.h"
#include "networking.h"
#include "sound.h"
int push(int argc, char * argv[]){
//init connection and ask for a transmission
struct client_session * cs = malloc(sizeof(struct client_session));
new_client_session(argv, cs);
// this stuff is for sound
int kidid;
if (cs->user.sound){
kidid = play_song(cs->path_to_programdir,"bumble.mp3", 3);
}
struct ft_init init;
new_ft_init(TR_RECV, cs->repo_name, &cs->user, &init);
write(cs->client_fd, &init, sizeof(struct ft_init));
send_full_directory_contents(cs->client_fd, ".dit");
//kill the mpg123 if sound is on
if(cs->user.sound){
kill(kidid, SIGKILL);
}
int server_side_result;
read(cs->client_fd, &server_side_result, sizeof(int));
close(cs->client_fd);
free(cs);
if(server_side_result == TR_SUCCESS){
printf("\nServer sucessfully recived the push...\n");
exit(0);
}
printf("FAILURE. Make sure you have inited this repo\n\n"
" try: dit init && dit push...\n");
exit(1);
}