projects
/
silc.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Integer type name change.
[silc.git]
/
lib
/
silcsftp
/
sftp_util.c
diff --git
a/lib/silcsftp/sftp_util.c
b/lib/silcsftp/sftp_util.c
index eb4652accfde62761205aac15da665dca6fd77e5..574f884173f15710f321f24b1e363f6e18ac57bf 100644
(file)
--- a/
lib/silcsftp/sftp_util.c
+++ b/
lib/silcsftp/sftp_util.c
@@
-25,15
+25,18
@@
/* Encodes a SFTP packet of type `packet' of length `len'. The variable
argument list is encoded as data payload to the buffer. Returns the
encoded packet or NULL on error. The caller must free the returned
/* Encodes a SFTP packet of type `packet' of length `len'. The variable
argument list is encoded as data payload to the buffer. Returns the
encoded packet or NULL on error. The caller must free the returned
- buffer. */
+ buffer. If `packet_buf' is non-NULL then the new packet data is put
+ to that buffer instead of allocating new one. If the new data cannot
+ fit to `packet_buf' will be reallocated. */
-SilcBuffer silc_sftp_packet_encode(SilcSFTPPacket packet, uint32 len, ...)
+SilcBuffer silc_sftp_packet_encode(SilcSFTPPacket packet,
+ SilcBuffer packet_buf, SilcUInt32 len, ...)
{
SilcBuffer buffer;
va_list vp;
va_start(vp, len);
{
SilcBuffer buffer;
va_list vp;
va_start(vp, len);
- buffer = silc_sftp_packet_encode_vp(packet, len, vp);
+ buffer = silc_sftp_packet_encode_vp(packet,
packet_buf,
len, vp);
va_end(vp);
return buffer;
va_end(vp);
return buffer;
@@
-42,13
+45,25
@@
SilcBuffer silc_sftp_packet_encode(SilcSFTPPacket packet, uint32 len, ...)
/* Same as silc_sftp_packet_encode but takes the variable argument list
pointer as argument. */
/* Same as silc_sftp_packet_encode but takes the variable argument list
pointer as argument. */
-SilcBuffer silc_sftp_packet_encode_vp(SilcSFTPPacket packet, uint32 len,
+SilcBuffer silc_sftp_packet_encode_vp(SilcSFTPPacket packet,
+ SilcBuffer packet_buf, SilcUInt32 len,
va_list vp)
{
SilcBuffer buffer;
va_list vp)
{
SilcBuffer buffer;
+ bool dyn;
int ret;
int ret;
- buffer = silc_buffer_alloc(4 + 1 + len);
+ if (packet_buf) {
+ if (packet_buf->truelen < 4 + 1 + len)
+ packet_buf = silc_buffer_realloc(packet_buf, 4 + 1 + len);
+
+ buffer = packet_buf;
+ dyn = FALSE;
+ } else {
+ buffer = silc_buffer_alloc(4 + 1 + len);
+ dyn = TRUE;
+ }
+
silc_buffer_pull_tail(buffer, SILC_BUFFER_END(buffer));
silc_buffer_format(buffer,
SILC_STR_UI_INT(len),
silc_buffer_pull_tail(buffer, SILC_BUFFER_END(buffer));
silc_buffer_format(buffer,
SILC_STR_UI_INT(len),
@@
-58,7
+73,8
@@
SilcBuffer silc_sftp_packet_encode_vp(SilcSFTPPacket packet, uint32 len,
ret = silc_buffer_format_vp(buffer, vp);
if (ret < 0) {
ret = silc_buffer_format_vp(buffer, vp);
if (ret < 0) {
- silc_buffer_free(buffer);
+ if (dyn)
+ silc_buffer_free(buffer);
return NULL;
}
return NULL;
}
@@
-73,10
+89,10
@@
SilcBuffer silc_sftp_packet_encode_vp(SilcSFTPPacket packet, uint32 len,
SilcSFTPPacket silc_sftp_packet_decode(SilcBuffer packet,
unsigned char **payload,
SilcSFTPPacket silc_sftp_packet_decode(SilcBuffer packet,
unsigned char **payload,
-
ui
nt32 *payload_len)
+
SilcUI
nt32 *payload_len)
{
{
-
ui
nt32 len;
-
ui
nt8 type;
+
SilcUI
nt32 len;
+
SilcUI
nt8 type;
int ret;
ret = silc_buffer_unformat(packet,
int ret;
ret = silc_buffer_unformat(packet,
@@
-264,7
+280,7
@@
SilcSFTPAttributes silc_sftp_attr_decode(SilcBuffer buffer)
sizeof(*attr->extended_data));
for (i = 0; i < attr->extended_count; i++) {
unsigned char *tmp, *tmp2;
sizeof(*attr->extended_data));
for (i = 0; i < attr->extended_count; i++) {
unsigned char *tmp, *tmp2;
-
ui
nt32 tmp_len, tmp2_len;
+
SilcUI
nt32 tmp_len, tmp2_len;
if (silc_buffer_unformat(buffer,
SILC_STR_UI32_NSTRING(&tmp, &tmp_len),
if (silc_buffer_unformat(buffer,
SILC_STR_UI32_NSTRING(&tmp, &tmp_len),
@@
-371,7
+387,7
@@
SilcBuffer silc_sftp_name_encode(SilcSFTPName name)
`count' many name, longname and attribute values. Returns the allocated
structure or NULL on error. */
`count' many name, longname and attribute values. Returns the allocated
structure or NULL on error. */
-SilcSFTPName silc_sftp_name_decode(
ui
nt32 count, SilcBuffer buffer)
+SilcSFTPName silc_sftp_name_decode(
SilcUI
nt32 count, SilcBuffer buffer)
{
SilcSFTPName name;
int i;
{
SilcSFTPName name;
int i;
@@
-435,7
+451,6
@@
SilcSFTPStatus silc_sftp_map_errno(int err)
case ENOENT:
case ENOTDIR:
case EBADF:
case ENOENT:
case ENOTDIR:
case EBADF:
- case ELOOP:
ret = SILC_SFTP_STATUS_NO_SUCH_FILE;
break;
case EPERM:
ret = SILC_SFTP_STATUS_NO_SUCH_FILE;
break;
case EPERM: