Ignore:
Timestamp:
01/06/06 16:50:32 (14 years ago)
Author:
spascoe
Message:

Implemented higher level auth message passing (the receiver doesn't
need to know the message length). The client will use this mechanism to
send the private string. This is working with stand alone bbftp client/server.

Embedded bbftpd is broken until I make corresponding
changes to the python API.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TI05-delivery/trunk/src/bbftp-client-3.2.0/bbftpc/bbftp_private_user.c

    r1077 r1078  
    4646void printmessage(FILE *strm , int flag, int errcode, int tok, char *fmt, ...); 
    4747 
     48 
     49/* prototypes */ 
     50static int ndg_message_recv(char **buffer, int *length, char *logmessage); 
     51static int ndg_message_send(char *buffer, int length, char *logmessage); 
    4852 
    4953/******************************************************************************* 
     
    126130{ 
    127131  char msg[NDG_MESSAGE_LEN]; 
    128  
     132  char default_privatestr[] = "none"; 
     133   
    129134  /* Send version verification message.  */ 
    130135  sprintf(msg, "%.*s", NDG_MESSAGE_LEN - 1, NDG_HANDSHAKE); 
     
    142147  } 
    143148 
     149  /* Send the privatestr */ 
     150  // If there is no private string, send default 
     151  if (privatestr == NULL) { 
     152    privatestr = default_privatestr; 
     153  } 
     154 
     155  if (ndg_message_send(privatestr, strlen(privatestr) + 1, logmessage) == -1) { 
     156    return -1; 
     157  } 
     158 
    144159  return  0 ; 
    145160} 
     161 
     162/* 
     163 * Higher level message transfer functions. 
     164 * 
     165 */ 
     166 
     167/** 
     168 * Send a message, declaring it's length to the client. 
     169 * 
     170 * @param buffer a pointer to the message buffer 
     171 * @param length the number of bytes to send 
     172 * @param[out] loggmessage is filled with the error message on error 
     173 * @return 0 if OK, -1 if error 
     174 */ 
     175static int ndg_message_send(char *buffer, int length, char *logmessage) { 
     176  char ctrl[NDG_MESSAGE_LEN]; 
     177 
     178  sprintf(ctrl, "NDG-msg: %i", length); 
     179  if (bbftp_private_send(ctrl, NDG_MESSAGE_LEN, logmessage) == -1) { 
     180    return -1; 
     181  } 
     182 
     183  if (bbftp_private_send(buffer, length, logmessage) == -1) { 
     184    return -1; 
     185  } 
     186 
     187  return 0; 
     188} 
     189 
     190/** 
     191 * Receive a message of variable length 
     192 * 
     193 * @param[out] buffer is set to newly allocated message buffer 
     194 * @param[out] length is set to the length of the message 
     195 * @param[out] logmessage is filled with the logmessage on error 
     196 * @return 0 if OK, -1 if error 
     197 */ 
     198static int ndg_message_recv(char **buffer, int *length, char *logmessage) { 
     199  char ctrl[NDG_MESSAGE_LEN]; 
     200 
     201  if (bbftp_private_recv(ctrl, NDG_MESSAGE_LEN, logmessage) == -1) { 
     202    return -1; 
     203  } 
     204  if (sscanf(ctrl, "NDG-msg: %i", length) != 1) { 
     205    sprintf(logmessage, "ndg_message_recv ctrl error: %40s", ctrl); 
     206    return -1; 
     207  } 
     208 
     209  if ((*buffer = (char *)malloc(*length * sizeof(char))) == NULL) { 
     210    sprintf(logmessage, "ngd_message_recv malloc error"); 
     211    return -1; 
     212  } 
     213 
     214  if (bbftp_private_recv(buffer, *length, logmessage) == -1) { 
     215    free(*buffer); *buffer = NULL; 
     216    return -1; 
     217  } 
     218 
     219  return 0; 
     220} 
     221   
Note: See TracChangeset for help on using the changeset viewer.