update: function cleanups, better way to handle package paths

This commit is contained in:
ngn
2024-06-28 23:09:24 +03:00
parent ed52710355
commit 5513abb371
27 changed files with 203 additions and 156 deletions

View File

@ -2,7 +2,6 @@
#include "../../include/mptp.h"
#include "../../include/util.h"
#include <arpa/inet.h>
#include <stdbool.h>
#include <string.h>
#include <errno.h>

View File

@ -2,7 +2,6 @@
#include "../../include/mptp.h"
#include "../../include/util.h"
#include <arpa/inet.h>
#include <stdbool.h>
#include <string.h>

View File

@ -1,19 +1,21 @@
#include "../../include/mptp.h"
#include "../../include/util.h"
#include <errno.h>
#include <stdio.h>
#include <unistd.h>
bool lm_mptp_sendfile(int sock, struct sockaddr *addr, char *path){
if (NULL == path)
return false;
lm_mptp_t packet;
bool ret = false;
if (NULL == path) {
lm_mptp_init(&packet, false, MPTP_S2C_BRUH, true);
goto end;
}
FILE *file = fopen(path, "r");
size_t read = 0;
if(NULL == file){
pdebug(__func__, "failed to open file: %s", path);
lm_mptp_init(&packet, false, MPTP_S2C_BRUH, true);
goto end;
}
@ -36,13 +38,27 @@ end:
}
bool lm_mptp_recvfile(int sock, char *path){
if(NULL == path)
return false;
if(unlink(path) < 0 && errno != ENOENT)
return false;
FILE *file = fopen(path, "a");
bool ret = false;
lm_mptp_t packet;
if(NULL == file){
pdebug(__func__, "failed to open file: %s", path);
goto end;
}
while(lm_mptp_client_recv(sock, &packet)){
if(!lm_mptp_client_verify(&packet))
goto end;
if(MPTP_FLAGS_CODE(&packet) != MPTP_S2C_COOL)
goto end;
if(MPTP_IS_LAST(&packet))
break;