<commit_before>/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <assert.h>
#include <netinet/ip.h>
#include "MozQuic.h"
#include "qdrive-common.h"

// -qdrive -qdrive-testN

#define SERVER_NAME "foo.example.com"

/*  About Certificate Verifcation::
    The sample/nss-config directory is a sample that can be passed
    to mozquic_nss_config(). It contains a NSS database with a cert
    and key for foo.example.com that is signed by a CA defined by CA.cert.der.
*/

int qdrive_server_crash = 0;

int main(int argc, char **argv)
{
  char *argVal, *t;
  struct mozquic_config_t config;
  mozquic_connection_t *c;

  if (has_arg(argc, argv, "-quiet", &argVal)) {
    fclose(stderr);
  }

  char *cdir = getenv ("MOZQUIC_NSS_CONFIG");
  if (mozquic_nss_config(cdir) != MOZQUIC_OK) {
    fprintf(stderr,"MOZQUIC_NSS_CONFIG FAILURE [%s]\n", cdir ? cdir : "");
    test_assert(0);
  }
  
  memset(&config, 0, sizeof(config));

  {
    struct sockaddr_in sin;
    socklen_t slen;
    int tfd = socket(AF_INET, SOCK_DGRAM, 0);
    memset (&sin, 0, sizeof (sin));
    sin.sin_family = AF_INET;
    slen = sizeof(sin);
    if (!bind(tfd, (const struct sockaddr *)&sin, sizeof (sin)) &&
        !getsockname(tfd, (struct sockaddr *) &sin,  &slen)) {
      config.originPort = ntohs(sin.sin_port);
    }
    close(tfd);
  }
  test_assert(config.originPort);<commit_msg>give qdrive-server a default port (1776)<commit_after>/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <assert.h>
#include <netinet/ip.h>
#include "MozQuic.h"
#include "qdrive-common.h"

// -qdrive -qdrive-testN

#define SERVER_NAME "foo.example.com"

/*  About Certificate Verifcation::
    The sample/nss-config directory is a sample that can be passed
    to mozquic_nss_config(). It contains a NSS database with a cert
    and key for foo.example.com that is signed by a CA defined by CA.cert.der.
*/

int qdrive_server_crash = 0;

int main(int argc, char **argv)
{
  char *argVal;
  struct mozquic_config_t config;
  mozquic_connection_t *c;

  if (has_arg(argc, argv, "-quiet", &argVal)) {
    fclose(stderr);
  }

  char *cdir = getenv ("MOZQUIC_NSS_CONFIG");
  if (mozquic_nss_config(cdir) != MOZQUIC_OK) {
    fprintf(stderr,"MOZQUIC_NSS_CONFIG FAILURE [%s]\n", cdir ? cdir : "");
    test_assert(0);
  }
  
  memset(&config, 0, sizeof(config));

  {
    struct sockaddr_in sin;
    socklen_t slen;
    int tfd = socket(AF_INET, SOCK_DGRAM, 0);
    memset (&sin, 0, sizeof (sin));
    sin.sin_family = AF_INET;
    sin.sin_port = htons(1776);
    slen = sizeof(sin);
    if (!bind(tfd, (const struct sockaddr *)&sin, sizeof (sin)) &&
        !getsockname(tfd, (struct sockaddr *) &sin,  &slen)) {
      config.originPort = ntohs(sin.sin_port);
    } else {
      sin.sin_port = 0;
      if (!bind(tfd, (const struct sockaddr *)&sin, sizeof (sin)) &&
          !getsockname(tfd, (struct sockaddr *) &sin,  &slen)) {
        config.originPort = ntohs(sin.sin_port);
      } else {
        test_assert(0);
      }
    }
    close(tfd);
  }
  test_assert(config.originPort);
{'fraction_non_alphanumeric': 0.14429347826086958, 'fraction_numerical': 0.008695652173913044, 'mean_word_length': 3.3408018867924527, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '3600537', 'n_tokens_mistral': 1425, 'n_tokens_neox': 1384, 'n_words': 373}