openbsd-ports/net/dctc/patches/patch-src_dc_xfer_common_c
jasper 267981508a - update dctc to a less ancient version 0.85.9
- merge parts of pkg/SECURITY into pkg/MESSAGE
- fix license marker

feedback and ok ajacoutot@
2008-08-25 15:14:43 +00:00

127 lines
4.7 KiB
Plaintext

$OpenBSD: patch-src_dc_xfer_common_c,v 1.1 2008/08/25 15:14:43 jasper Exp $
--- src/dc_xfer_common.c.orig Fri Aug 22 12:30:03 2008
+++ src/dc_xfer_common.c Fri Aug 22 12:37:45 2008
@@ -61,6 +61,15 @@ $Id: dc_xfer_common.c,v 1.3 2004/01/09 18:16:01 ericpr
#include "misc.h"
#include "main.h"
+/* compability macros for reading/writing to sockets */
+#ifdef __OpenBSD__
+# define sock_read(sck, buf, size, flags) read(sck, buf, size)
+# define sock_write(sck, buf, size, flags) write(sck, buf, size)
+#else
+# define sock_read(sck, buf, size, flags) recv(sck, buf, size, flags)
+# define sock_write(sck, buf, size, flags) send(sck, buf, size, flags)
+#endif
+
int hub_logged=0; /* set to 1 when dctc is logged on the hub */
/********************************************************/
@@ -249,7 +258,7 @@ int send_file_data(int sck,char *filename, unsigned lo
act->last_touch=time(NULL);
get_ul_slices(bl_semid,sizeof(buf)/512); /* obtain upload authorization */
- res=send(sck,buf,sizeof(buf),MSG_NOSIGNAL /* |MSG_WAITALL */ );
+ res=sock_write(sck,buf,sizeof(buf),MSG_NOSIGNAL /* |MSG_WAITALL */ );
act->last_touch=time(NULL);
if(res!=sizeof(buf))
@@ -259,7 +268,7 @@ int send_file_data(int sck,char *filename, unsigned lo
}
sent_data+=res;
- sprintf(ul_stat,"%lu:%llu/%llu/%llu/%llu",act->thread_id,start_pos,file_len,(i+1)*sizeof(buf),a);
+ snprintf(ul_stat, sizeof(ul_stat), "%lu:%d/%lu/%lu/%lu",act->thread_id,start_pos,file_len,(i+1)*sizeof(buf),a);
disp_msg(XFER_UL_STAT,NULL,ul_stat,NULL);
}
@@ -279,7 +288,7 @@ int send_file_data(int sck,char *filename, unsigned lo
act->last_touch=time(NULL);
get_ul_slices(bl_semid,(remain+511)/512); /* obtain upload authorization */
- res=send(sck,buf,remain,MSG_NOSIGNAL /* |MSG_WAITALL */ );
+ res=sock_write(sck,buf,remain,MSG_NOSIGNAL /* |MSG_WAITALL */ );
act->last_touch=time(NULL);
if(res!=remain)
@@ -350,7 +359,7 @@ int send_array_data(int sck,GByteArray *ba,WAIT_ACT *a
act->last_touch=time(NULL);
get_ul_slices(bl_semid,BLOCK_SIZE/512); /* obtain upload authorization */
- res=send(sck,ba->data+cur_pos,BLOCK_SIZE,MSG_NOSIGNAL /* |MSG_WAITALL */ );
+ res=sock_write(sck,ba->data+cur_pos,BLOCK_SIZE,MSG_NOSIGNAL /* |MSG_WAITALL */ );
act->last_touch=time(NULL);
if(res!=BLOCK_SIZE)
@@ -368,7 +377,7 @@ int send_array_data(int sck,GByteArray *ba,WAIT_ACT *a
act->last_touch=time(NULL);
get_ul_slices(bl_semid,(remain+511)/512); /* obtain upload authorization */
- res=send(sck,ba->data+cur_pos,remain,MSG_NOSIGNAL /* |MSG_WAITALL */ );
+ res=sock_write(sck,ba->data+cur_pos,remain,MSG_NOSIGNAL /* |MSG_WAITALL */ );
act->last_touch=time(NULL);
if(res!=remain)
@@ -463,15 +472,16 @@ int com_up_get_list_len_process(const char *cmd,WAIT_A
disp_msg(DEBUG_MSG,"reply",out->str,NULL);
- res=send(sck,out->str,out->len,MSG_NOSIGNAL);
+ res=sock_write(sck,out->str,out->len,MSG_NOSIGNAL);
res=(res!=out->len);
g_string_free(out,TRUE);
- if(res)
+
+ if(res || !strcmp(cmd,"$GetListLen"))
{
if(cpy_data!=NULL)
g_byte_array_free(cpy_data,TRUE);
free_one_ul_slot(bl_semid);
- return 1;
+ return strcmp(cmd,"$GetListLen");
}
/* get command */
@@ -487,7 +497,7 @@ int com_up_get_list_len_process(const char *cmd,WAIT_A
g_string_sprintfa(out,"%lu|",(unsigned long)100000+rand()%500000);
else
g_string_sprintfa(out,"%lu|",(unsigned long)cpy_data->len);
- res=send(sck,out->str,out->len,MSG_NOSIGNAL);
+ res=sock_write(sck,out->str,out->len,MSG_NOSIGNAL);
res=(res!=out->len);
g_string_free(out,TRUE);
if(res)
@@ -1045,7 +1055,7 @@ int start_a_xdownload(WAIT_ACT *act, WAIT_REVCON *act_
get_dl_slices(bl_semid,(amount+1023)/1024);
act->last_touch=time(NULL);
- ret=recv(act->sock_fd,buf,amount,MSG_WAITALL|MSG_NOSIGNAL);
+ ret=sock_read(act->sock_fd,buf,amount,MSG_WAITALL|MSG_NOSIGNAL);
if((ret==-1)||(ret==0))
{ /* error or nothing received */
goto end_on_error;
@@ -1122,12 +1132,11 @@ int copie_fd_to_bytearray(int remote, GByteArray **ba,
/* touch the action slot to avoid timeout */
act->last_touch=time(NULL);
-#if 0
ret=recv(remote,(*ba)->data+pos,nb,MSG_WAITALL|MSG_NOSIGNAL);
-#else
+#if 0
ret=recv(remote,(*ba)->data+pos,nb,MSG_NOSIGNAL);
- printf("%d (nb:%lu, amount: %lu)\n",ret,nb,amount);
#endif
+ printf("%d (nb:%lu, amount: %lu)\n",ret,nb,amount);
if((ret==-1)||(ret==0))
{ /* error or nothing received */
@@ -2515,7 +2524,7 @@ void get_dc_line_and_process(int sck)
static int call_counter=0;
char tmp[512];
- sprintf(tmp,"call counter: %d",call_counter++);
+ snprintf(tmp, sizeof(tmp), "call counter: %d",call_counter++);
disp_msg(DEBUG_MSG,"get_dc_lines_until_no_more",tmp,NULL);