Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
John McEleney
/
mailutils
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit
d4f70062
...
d4f70062143f7a313c288ad0ccec29fa82147e31
authored
2003-08-28 19:34:42 +0000
by
Sergey Poznyakoff
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Use lbuf stuff
1 parent
7ada98e7
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
46 deletions
auth/gsasl.c
auth/gsasl.c
View file @
d4f7006
...
...
@@ -32,6 +32,7 @@
#include <mailutils/stream.h>
#include <gsasl.h>
#include <lbuf.h>
char
*
gsasl_cram_md5_pwd
=
SITE_CRAM_MD5_PWD
;
...
...
@@ -87,47 +88,17 @@ struct _gsasl_stream {
int
last_err
;
/* Last Gsasl error code */
int
fd
;
/* File descriptor */
char
*
buffer
;
/* Line buffer */
size_t
size
;
/* Allocated size */
size_t
level
;
/* Current filling level */
struct
_line_buffer
*
lb
;
};
static
void
_gsasl_destroy
(
stream_t
stream
)
{
struct
_gsasl_stream
*
s
=
stream_get_owner
(
stream
);
free
(
s
->
buffer
);
_auth_lb_destroy
(
&
s
->
lb
);
s
->
buffer
=
NULL
;
}
#define buffer_drop(s) s->level = 0
int
buffer_grow
(
struct
_gsasl_stream
*
s
,
const
char
*
ptr
,
size_t
size
)
{
if
(
!
s
->
buffer
)
{
s
->
buffer
=
malloc
(
size
);
s
->
size
=
size
;
s
->
level
=
0
;
}
else
if
(
s
->
size
-
s
->
level
<
size
)
{
size_t
newsize
=
s
->
size
+
size
;
s
->
buffer
=
realloc
(
s
->
buffer
,
newsize
);
if
(
s
->
buffer
)
s
->
size
=
newsize
;
}
if
(
!
s
->
buffer
)
return
ENOMEM
;
memcpy
(
s
->
buffer
+
s
->
level
,
ptr
,
size
);
s
->
level
+=
size
;
return
0
;
}
static
int
_gsasl_readline
(
stream_t
stream
,
char
*
optr
,
size_t
osize
,
off_t
offset
,
size_t
*
nbytes
)
...
...
@@ -137,15 +108,10 @@ _gsasl_readline (stream_t stream, char *optr, size_t osize,
size_t
len
,
sz
;
char
*
bufp
;
if
(
s
->
level
)
{
len
=
s
->
level
>
osize
?
osize
:
s
->
level
;
memcpy
(
optr
,
s
->
buffer
,
len
);
if
(
s
->
level
>
len
)
if
(
_auth_lb_level
(
&
s
->
lb
))
{
memmove
(
s
->
buffer
,
s
->
buffer
+
len
,
s
->
level
-
len
);
s
->
level
-=
len
;
}
len
=
_auth_lb_readline
(
s
->
lb
,
optr
,
osize
-
1
);
optr
[
len
]
=
0
;
if
(
nbytes
)
*
nbytes
=
len
;
return
0
;
...
...
@@ -164,7 +130,7 @@ _gsasl_readline (stream_t stream, char *optr, size_t osize,
return
errno
;
}
rc
=
buffer
_grow
(
s
,
buf
,
sz
);
rc
=
_auth_lb
_grow
(
s
,
buf
,
sz
);
if
(
rc
)
return
rc
;
...
...
@@ -182,7 +148,8 @@ _gsasl_readline (stream_t stream, char *optr, size_t osize,
bufp
=
malloc
(
len
+
1
);
if
(
!
bufp
)
return
ENOMEM
;
rc
=
gsasl_decode
(
s
->
sess_ctx
,
s
->
buffer
,
s
->
level
,
bufp
,
&
len
);
rc
=
gsasl_decode
(
s
->
sess_ctx
,
_auth_lb_data
(
s
->
lb
),
_auth_lb_level
(
s
->
lb
),
bufp
,
&
len
);
if
(
rc
!=
GSASL_OK
)
{
s
->
last_err
=
rc
;
...
...
@@ -195,13 +162,13 @@ _gsasl_readline (stream_t stream, char *optr, size_t osize,
if
(
len
>
osize
)
{
memcpy
(
optr
,
bufp
,
osize
);
buffer
_drop
(
s
);
buffer
_grow
(
s
,
bufp
+
osize
,
len
-
osize
);
_auth_lb
_drop
(
s
);
_auth_lb
_grow
(
s
,
bufp
+
osize
,
len
-
osize
);
len
=
osize
;
}
else
{
buffer
_drop
(
s
);
_auth_lb
_drop
(
s
);
memcpy
(
optr
,
bufp
,
len
);
}
...
...
@@ -257,7 +224,7 @@ _gsasl_write (stream_t stream, const char *iptr, size_t isize,
int
rc
;
struct
_gsasl_stream
*
s
=
stream_get_owner
(
stream
);
rc
=
buffer
_grow
(
s
,
iptr
,
isize
);
rc
=
_auth_lb
_grow
(
s
,
iptr
,
isize
);
if
(
rc
)
return
rc
;
...
...
@@ -377,6 +344,8 @@ gsasl_stream_create (stream_t *stream, int fd,
else
stream_set_write
(
*
stream
,
_gsasl_write
,
s
);
_auth_lb_create
(
&
s
->
lb
);
return
0
;
}
...
...
Please
register
or
sign in
to post a comment