234
232
size_t tcount = 0;
238
235
size = strlen(message);
238
/* loop if we wrote some data but not everything, or if error is
240
while ((count = write(cn->handle,
241
((const char *)message) + tcount,
242
size - tcount)) > 0) {
241
count = write(cn->handle, ((const char *)message) + tcount,
244
245
if (tcount == size)
246
if (tcount - p_tcount == 0) {
247
/* no write at all, we give up */
248
cn->connected = CONN_ERROR;
253
} while (count < 0 &&
254
(errno == EAGAIN || errno == EINTR || errno == EINPROGRESS));
257
if (count <= 0 && tcount > 0)
258
fatal("shit happens errno:%d count:%d tcount:%d (%s)\n", errno,
259
count, tcount, message);
263
* if no fatal error, return WRITE_KEEP, which makes caller
264
* keep line in its FIFO
266
* Cannot do: we might have written a partial line
268
if (errno == EAGAIN || errno == EINTR || errno == EINPROGRESS)
272
if (cn_is_connected(cn)) {
273
mylog(LOG_DEBUGVERB, "write(fd %d) : %s", cn->handle,
275
cn->connected = CONN_ERROR;
277
mylog(LOG_DEBUGVERB, "write : %s", strerror(errno));
280
mylog(LOG_DEBUGVERB, "%d/%d bytes sent !", tcount, size);
248
} while (count > 0 || (count < 0 && errno == EINTR));
250
/* If we reach this point, we have a partial write */
253
/* if no fatal error, return WRITE_KEEP, which makes caller keep line
256
* Shitty: we might have written a partial line, so we hack the line...
257
* Callers of _write_socket muse provide a writable message
259
if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINPROGRESS) {
260
memmove(message, message + tcount, size - tcount + 1);
263
/* other errors, EPIPE or worse, close the connection, repport error */
264
if (cn_is_connected(cn)) {
266
mylog(LOG_INFO, "Broken socket: %s.", strerror(errno));
267
connection_close(cn);
268
cn->connected = CONN_ERROR;
270
mylog(LOG_DEBUGVERB, "write: %d, %s", cn->handle, strerror(errno));
284
274
static int write_socket(connection_t *cn, char *line)
324
322
if (cn->anti_flood)
325
323
/* one line at a time */
325
} while ((line = list_remove_first(cn->outgoing)));
331
329
void write_line_fast(connection_t *cn, char *line)
334
r = write_socket(cn, line);
337
list_add_first(cn->outgoing, bip_strdup(line));
340
cn->connected = CONN_ERROR;
345
fatal("internal error 7");
332
char *nline = bip_strdup(line);
335
list_add_first(cn->outgoing, nline);
337
r = write_socket(cn, nline);
347
fatal("internal error 7");
350
353
void write_lines(connection_t *cn, list_t *lines)
352
355
list_append(cn->outgoing, lines);
355
359
void write_line(connection_t *cn, char *line)
357
361
list_add_last(cn->outgoing, bip_strdup(line));
360
365
list_t *read_lines(connection_t *cn, int *error)
1279
1283
/* in basic mode (mode 1), accept a leaf certificate if we can find it
1280
1284
* in the store */
1281
if (c->ssl_check_mode == SSL_CHECK_BASIC && depth == 0 && result == 0 &&
1285
if (c->ssl_check_mode == SSL_CHECK_BASIC && result == 0 &&
1282
1286
(err == X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY ||
1283
1287
err == X509_V_ERR_CERT_UNTRUSTED ||
1284
1288
err == X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE ||
1285
1289
err == X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT ||
1286
err == X509_V_ERR_CERT_HAS_EXPIRED)) {
1290
err == X509_V_ERR_CERT_HAS_EXPIRED ||
1291
err == X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN)) {
1288
1293
if (X509_STORE_get_by_subject(ctx, X509_LU_X509,
1289
1294
X509_get_subject_name(err_cert), &xobj) > 0 &&
1440
1445
case SSL_CHECK_BASIC:
1441
1446
SSL_CTX_set_verify(conn->ssl_ctx_h, SSL_VERIFY_PEER,
1442
1447
bip_ssl_verify_callback);
1443
SSL_CTX_set_verify_depth(conn->ssl_ctx_h, 0);
1448
/* SSL_CTX_set_verify_depth(conn->ssl_ctx_h, 0); */
1445
1450
case SSL_CHECK_CA:
1446
1451
SSL_CTX_set_verify(conn->ssl_ctx_h, SSL_VERIFY_PEER,