Projects STRLCPY neomutt Commits 9afd863f
🤬
  • conn: add mutt_socket_buffer_readln_d()

    Read a line from a socket into a Buffer.
  • Loading...
  • Richard Russon committed 2 years ago
    9afd863f
    1 parent b5041f10
Revision indexing in progress... (symbol navigation in revisions will be accurate after indexed)
  • ■ ■ ■ ■ ■ ■
    conn/socket.c
    skipped 29 lines
    30 30   
    31 31  #include "config.h"
    32 32  #include <errno.h>
     33 +#include <stdbool.h>
    33 34  #include <string.h>
    34 35  #include <time.h>
    35 36  #include "private.h"
    skipped 288 lines
    324 325   }
    325 326  }
    326 327   
     328 +/**
     329 + * mutt_socket_buffer_readln_d - Read a line from a socket into a Buffer
     330 + * @param buf Buffer to store the line
     331 + * @param conn Connection to a server
     332 + * @param dbg Debug level for logging
     333 + * @retval >0 Success, number of bytes read
     334 + * @retval -1 Error
     335 + */
     336 +int mutt_socket_buffer_readln_d(struct Buffer *buf, struct Connection *conn, int dbg)
     337 +{
     338 + char ch;
     339 + bool has_cr = false;
     340 + 
     341 + mutt_buffer_reset(buf);
     342 + 
     343 + while (true)
     344 + {
     345 + if (mutt_socket_readchar(conn, &ch) != 1)
     346 + return -1;
     347 + 
     348 + if (ch == '\n')
     349 + break;
     350 + 
     351 + if (has_cr)
     352 + {
     353 + mutt_buffer_addch(buf, '\r');
     354 + has_cr = false;
     355 + }
     356 + 
     357 + if (ch == '\r')
     358 + has_cr = true;
     359 + else
     360 + mutt_buffer_addch(buf, ch);
     361 + }
     362 + 
     363 + mutt_debug(dbg, "%d< %s\n", conn->fd, mutt_buffer_string(buf));
     364 + return 0;
     365 +}
     366 + 
  • ■ ■ ■ ■ ■ ■
    conn/socket.h
    skipped 25 lines
    26 26   
    27 27  #include <time.h>
    28 28   
     29 +struct Buffer;
    29 30  struct Connection;
    30 31   
    31 32  /**
    skipped 26 lines
    58 59  #define mutt_socket_send(conn, buf) mutt_socket_send_d(conn, buf, MUTT_SOCK_LOG_CMD)
    59 60  #define mutt_socket_send_d(conn, buf, dbg) mutt_socket_write_d(conn, buf, mutt_str_len(buf), dbg)
    60 61  #define mutt_socket_write_n(conn, buf, len) mutt_socket_write_d(conn, buf, len, MUTT_SOCK_LOG_CMD)
     62 + 
     63 +#define mutt_socket_buffer_readln(buf, conn) mutt_socket_buffer_readln_d(buf, conn, MUTT_SOCK_LOG_CMD)
     64 +int mutt_socket_buffer_readln_d(struct Buffer *buf, struct Connection *conn, int dbg);
    61 65   
    62 66  #endif /* MUTT_CONN_SOCKET_H */
    63 67   
Please wait...
Page is in error, reload to recover