<commit_before>/*
 * Copyright (c) 2003 Regents of The University of Michigan.
 * All Rights Reserved.  See COPYRIGHT.
 */

/*****     smtp.c     *****/
#include "config.h"

#include <sys/param.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/param.h>
#include <netinet/in.h>
#include <arpa/inet.h>

#ifdef HAVE_LIBSSL
#include <openssl/ssl.h>
#include <openssl/rand.h>
#include <openssl/err.h>
#endif /* HAVE_LIBSSL */

#include <inttypes.h>
#include <netdb.h>
#include <unistd.h>
#include <strings.h>
#include <string.h>
#include <syslog.h>

#include <snet.h>

#include "queue.h"
#include "line_file.h"
#include "envelope.h"
#include "smtp.h"
#include "denser.h"
#include "bprint.h"
#include "argcargv.h"
#include "timeval.h"
#include "simta.h"
#include "mx.h"

#ifdef DEBUG
void	(*smtp_logger)(char *) = stdout_logger;
#else /* DEBUG */
void	(*smtp_logger)(char *) = NULL;
#endif /* DEBUG */


    void
stdout_logger( char *line )
{
    printf( "<-- %s\n", line );
    return;
}


    int
smtp_connect( SNET **snetp, struct host_q *hq )
{
    SNET			*snet;
    char			*line;
    char			*remote_host;
    char			*c;
    struct sockaddr_in		sin;
    int				s;
    struct timeval		tv;
    DNSR			*dnsr;
    struct dnsr_result		*result;

    if ( simta_debug ) fprintf( stderr, "smtp_connect dnsr: %s\n", hq->hq_hostname );

    if (( dnsr = dnsr_new( )) == NULL ) {
	syslog( LOG_ERR, "dnsr_new: %m" );
	hq->hq_status = HOST_DOWN;
	return( SMTP_ERR_REMOTE );
    }

    if (( result = get_mx( dnsr, hq->hq_hostname )) == NULL ) {
	if ( simta_debug ) fprintf( stderr, "smtp_connect: get_mx failed\n" );
	hq->hq_status = HOST_DOWN;
	return( SMTP_ERR_REMOTE );
    }
    if ( simta_debug ) fprintf( stderr, "smtp_connect: get_mx success\n" );


#ifdef DEBUG
    if ( result->r_answer[ 0 ].rr_ip == NULL ) {
	printf( "dnsr is broke\n" );
    }
#endif /* DEBUG */

    if ( result->r_answer[ 0 ].rr_type == DNSR_TYPE_MX ) {
	memcpy( &(sin.sin_addr.s_addr), &(result->r_answer[ 0 ].rr_ip->ip_ip ),
	    sizeof( struct in_addr ));
    } else {
	memcpy( &(sin.sin_addr.s_addr), &(result->r_answer[ 0 ].rr_a ),<commit_msg>Don't kill yourself if dnsr is broke<commit_after>/*
 * Copyright (c) 2003 Regents of The University of Michigan.
 * All Rights Reserved.  See COPYRIGHT.
 */

/*****     smtp.c     *****/
#include "config.h"

#include <sys/param.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/param.h>
#include <netinet/in.h>
#include <arpa/inet.h>

#ifdef HAVE_LIBSSL
#include <openssl/ssl.h>
#include <openssl/rand.h>
#include <openssl/err.h>
#endif /* HAVE_LIBSSL */

#include <inttypes.h>
#include <netdb.h>
#include <unistd.h>
#include <strings.h>
#include <string.h>
#include <syslog.h>

#include <snet.h>

#include "queue.h"
#include "line_file.h"
#include "envelope.h"
#include "smtp.h"
#include "denser.h"
#include "bprint.h"
#include "argcargv.h"
#include "timeval.h"
#include "simta.h"
#include "mx.h"

#ifdef DEBUG
void	(*smtp_logger)(char *) = stdout_logger;
#else /* DEBUG */
void	(*smtp_logger)(char *) = NULL;
#endif /* DEBUG */


    void
stdout_logger( char *line )
{
    printf( "<-- %s\n", line );
    return;
}


    int
smtp_connect( SNET **snetp, struct host_q *hq )
{
    SNET			*snet;
    char			*line;
    char			*remote_host;
    char			*c;
    struct sockaddr_in		sin;
    int				s;
    struct timeval		tv;
    DNSR			*dnsr;
    struct dnsr_result		*result;

    if ( simta_debug ) fprintf( stderr, "smtp_connect dnsr: %s\n", hq->hq_hostname );

    if (( dnsr = dnsr_new( )) == NULL ) {
	syslog( LOG_ERR, "dnsr_new: %m" );
	hq->hq_status = HOST_DOWN;
	return( SMTP_ERR_REMOTE );
    }

    if (( result = get_mx( dnsr, hq->hq_hostname )) == NULL ) {
	if ( simta_debug ) fprintf( stderr, "smtp_connect: get_mx failed\n" );
	hq->hq_status = HOST_DOWN;
	return( SMTP_ERR_REMOTE );
    }
    if ( simta_debug ) fprintf( stderr, "smtp_connect: get_mx success\n" );


    if ( result->r_answer[ 0 ].rr_ip == NULL ) {
#ifdef DEBUG
	printf( "dnsr is broke\n" );
#endif /* DEBUG */
	return( SMTP_ERR_SYSCALL );
    }

    if ( result->r_answer[ 0 ].rr_type == DNSR_TYPE_MX ) {
	memcpy( &(sin.sin_addr.s_addr), &(result->r_answer[ 0 ].rr_ip->ip_ip ),
	    sizeof( struct in_addr ));
    } else {
	memcpy( &(sin.sin_addr.s_addr), &(result->r_answer[ 0 ].rr_a ),
{'fraction_non_alphanumeric': 0.17387346381429222, 'fraction_numerical': 0.0036413290851160674, 'mean_word_length': 3.3557978196233895, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '266881', 'n_tokens_mistral': 1910, 'n_tokens_neox': 1839, 'n_words': 412}