text:
#include <linux/config.h>
#include <linux/slab.h>
#include <linux/string.h>
#include <linux/skbuff.h>
#include <linux/delay.h>
#include <linux/proc_fs.h>
#include <linux/init.h>
#include <linux/random.h>
#include <linux/module.h>
#include <linux/seq_file.h>

#include <net/irda/irda.h>
#include <net/irda/irda_device.h>
#include <net/irda/irqueue.h>
#include <net/irda/irlmp.h>
#include <net/irda/irlmp_frame.h>
#include <net/irda/irlap_frame.h>
#include <net/irda/irlap.h>
#include <net/irda/timer.h>
#include <net/irda/qos.h>

static hashbin_t *irlap = NULL;
int sysctl_slot_timeout = SLOT_TIMEOUT * 1000 / HZ;

/* This is the delay of missed pf period before generating an event
 * to the application. The spec mandate 3 seconds, but in some cases
 * it's way too long. - Jean II */
int sysctl_warn_noreply_time = 3;

extern void irlap_queue_xmit(struct irlap_cb *self, struct sk_buff *skb);
static void __irlap_close(struct irlap_cb *self);
static void irlap_init_qos_capabilities(struct irlap_cb *self,
					struct qos_info *qos_user);

#ifdef CONFIG_IRDA_DEBUG
static char *lap_reasons[] = {
	"ERROR, NOT USED",
	"LAP_DISC_INDICATION",
	"LAP_NO_RESPONSE",
	"LAP_RESET_INDICATION",
	"LAP_FOUND_NONE",
	"LAP_MEDIA_BUSY",
	"LAP_PRIMARY_CONFLICT",
	"ERROR, NOT USED",
};
#endif	/* CONFIG_IRDA_DEBUG */

int __init irlap_init(void)
{
	/* Check if the compiler did its job properly.
	 * May happen on some ARM configuration, check with Russell King. */
	IRDA_ASSERT(sizeof(struct xid_frame) == 14, ;);
	IRDA_ASSERT(sizeof(struct test_frame) == 10, ;);
	IRDA_ASSERT(sizeof(struct ua_frame) == 10, ;);
	IRDA_ASSERT(sizeof(struct snrm_frame) == 11, ;);

	/* Allocate master array */
	irlap = hashbin_new(HB_LOCK);
	if (irlap == NULL) {
	        IRDA_ERROR("%s: can't allocate irlap hashbin!\n",
			   __FUNCTION__);
		return -ENOMEM;
	}

	return 0;
}

void __exit irlap_cleanup(void)
{
	IRDA_ASSERT(irlap != NULL, return;);

	hashbin_delete(irlap, (FREE_FUNC) __irlap_close);
}

/*
 * Function irlap_open (driver)
 *
 *    Initialize IrLAP layer
 *
 */
struct irlap_cb *irlap_open(struct net_device *dev, struct qos_info *qos,
			    const char *hw_name)
{
	struct irlap_cb *self;

	IRDA_DEBUG(4, "%s()\n", __FUNCTION__);

	/* Initialize the irlap structure. */
	self = kmalloc(sizeof(struct irlap_cb), GFP_KERNEL);
	if (self == NULL)
		return NULL;

	memset(self, 0, sizeof(struct irlap_cb));
	self->magic = LAP_MAGIC;

	/* Make a binding between the layers */
	self->netdev = dev;
	self->qos_dev = qos;
	/* Copy hardware name */
	if(hw_name != NULL) {
		strlcpy(self->hw_name, hw_name, sizeof(self->hw_name));
	} else {
		self->hw_name[0] = '\0';
	}

	/* FIXME: should we get our own field? */
	dev->atalk_ptr = self;

	self->state = LAP_OFFLINE;

	/* Initialize transmit queue */
	skb_queue_head_init(&self->txq);
	skb_queue_head_init(&self->txq_ultra);
	skb_queue_head_init(&self->wx_list);

	/* My unique IrLAP device address! */
	/* We don't want the broadcast address, neither the NULL address
	 * (most often used to signify "invalid"), and we don't want an
	 * address already in use (otherwise connect won't be able
	 * to select the proper link). - Jean II */
	do {
		get_random_bytes(&self->saddr, sizeof(self->saddr));
	} while ((self->saddr == 0x0) || (self->saddr == BROADCAST) ||
		 (hashbin_lock_find(irlap, self->saddr, NULL)) );
	/* Copy to the driver */
	memcpy(dev->dev_addr, &self->saddr, 4);

	init_timer(&self->slot_timer);
	init_timer(&self->query_timer);
	init_timer(&self->discovery_timer);
	init_timer(&self->final_timer);
	init_timer(&self->poll_timer);
	init_timer(&self->wd_timer);
	init_timer(&self->backoff_timer);
	init_timer(&self->media_busy_timer);

	irlap_apply_default_connection_parameters(self);

	self->N3 = 3; /* # connections attemts to try before giving up */

	self->state = LAP_NDM;

	hashbin_insert(irlap, (irda_queue_t *) self, self->saddr, NULL);

	irlmp_register_link(self, self->saddr, &self->notify);

	return self;
}
EXPORT_SYMBOL(irlap_open);

/*
 * Function __irlap_close (self)
 *
 *    Remove IrLAP and all allocated memory. Stop any pending timers.
 *
 */
static void __irlap_close(struct irlap_cb *self)
{
	IRDA_ASSERT(self != NULL, return;);
	IRDA_ASSERT(self->magic == LAP_MAGIC, return;);

	/* Stop timers */
	del_timer(&self->slot_timer);
	del_timer(&self->query_timer);
	del_timer(&self->discovery_timer);
	del_timer(&self->final_timer);
	del_timer(&self->poll_timer);
	del_timer(&self->wd_timer);
	del_timer(&self->backoff_timer);
	del_timer(&self->media_busy_timer);

	irlap_flush_all_queues(self);

	self->magic = 0;

	kfree(self);
}

/*
 * Function irlap_close (self)
 *
 *    Remove IrLAP instance
 *
 */
void irlap_close(struct irlap_cb *self)
{
	struct irlap_cb *lap;

	IRDA_DEBUG(4, "%s()\n", __FUNCTION__);

	IRDA_ASSERT(self != NULL, return;);
	IRDA_ASSERT(self->magic == LAP_MAGIC, return;);

	/* We used to send a LAP_DISC_INDICATION here, but this was
	 * racy. This has been move within irlmp_unregister_link()
	 * itself. Jean II */

	/* Kill the LAP and all LSAPs on top of it */
	irlmp_unregister_link(self->saddr);
	self->notify.instance = NULL;

	/* Be sure that we manage to remove ourself from the hash */
	lap = hashbin_remove(irlap, self->saddr, NULL);
	if (!lap) {
		IRDA_DEBUG(1, "%s(), Didn't find myself!\n", __FUNCTION__);
		return;
	}
	__irlap_close(lap);
}
EXPORT_SYMBOL(irlap_close);

/*
 * Function irlap_connect_indication (self, skb)
 *
 *    Another device is attempting to make a connection
 *
 */
void irlap_connect_indication(struct irlap_cb *self, struct sk_buff *skb)
{
	IRDA_DEBUG(4, "%s()\n", __FUNCTION__);

	IRDA_ASSERT(self != NULL, return;);
	IRDA_ASSERT(self->magic == LAP_MAGIC, return;);

	irlap_init_qos_capabilities(self, NULL); /* No user QoS! */

	irlmp_link_connect_indication(self->notify.instance, self->saddr,
				      self->daddr, &self->qos_tx, skb);
}

/*
 * Function irlap_connect_response (self, skb)
 *
 *    Service user has accepted incoming connection
 *
 */
void irlap_connect_response(struct irlap_cb *self, struct sk_buff *userdata)
{
	IRDA_DEBUG(4, "%s()\n", __FUNCTION__);

	irlap_do_event(self, CONNECT_RESPONSE, userdata, NULL);
}

/*
 * Function irlap_connect_request (self, daddr, qos_user, sniff)
 *
 *    Request connection with another device, sniffing is not implemented
 *    yet.
 *
 */
void irlap_connect_request(struct irlap_cb *self, __u32 daddr,
			   struct qos_info *qos_user, int sniff)
{
	IRDA_DEBUG(3, "%s(), daddr=0x%08x\n", __FUNCTION__, daddr);

	IRDA_ASSERT(self != NULL, return;);
	IRDA_ASSERT(self->magic == LAP_MAGIC, return;);

	self->daddr = daddr;

	/*
	 *  If the service user specifies QoS values for this connection,
	 *  then use them
	 */
	irlap_init_qos_capabilities(self, qos_user);

	if ((self->state == LAP_NDM) && !self->media_busy)
		irlap_do_event(self, CONNECT_REQUEST, NULL, NULL);
	else
		self->connect_pending = TRUE;
}

/*
 * Function irlap_connect_confirm (self, skb)
 *
 *    Connection request has been accepted
 *
 */
void irlap_connect_confirm(struct irlap_cb *self, struct sk_buff *skb)
{
	IRDA_DEBUG(4, "%s()\n", __FUNCTION__);

	IRDA_ASSERT(self != NULL, return;);
	IRDA_ASSERT(self->magic == LAP_MAGIC, return;);

	irlmp_link_connect_confirm(self->notify.instance, &self->qos_tx, skb);
}

/*
 * Function irlap_data_indication (self, skb)
 *
 *    Received data frames from IR-port, so we just pass them up to
 *    IrLMP for further processing
 *
 */
void irlap_data_indication(struct irlap_cb *self, struct sk_buff *skb,
			   int unreliable)
{
	/* Hide LAP header from IrLMP layer */
	skb_pull(skb, LAP_ADDR_HEADER+LAP_CTRL_HEADER);

	irlmp_link_data_indication(self->notify.instance, skb, unreliable);
}

/*
 * Function irlap_data_request (self, skb)
 *
 *    Queue data for transmission, must wait until XMIT state
 *
 */
void irlap_data_request(struct irlap_cb *self, struct sk_buff *skb,
			int unreliable)
{
	IRDA_ASSERT(self != NULL, return;);
	IRDA_ASSERT(self->magic == LAP_MAGIC, return;);

	IRDA_DEBUG(3, "%s()\n", __FUNCTION__);

	IRDA_ASSERT(skb_headroom(skb) >= (LAP_ADDR_HEADER+LAP_CTRL_HEADER),
		    return;);
	skb_push(skb, LAP_ADDR_HEADER+LAP_CTRL_HEADER);

	/*
	 *  Must set frame format now so that the rest of the code knows
	 *  if its dealing with an I or an UI frame
	 */
	if (unreliable)
		skb->data[1] = UI_FRAME;
	else
		skb->data[1] = I_FRAME;

	/* Don't forget to refcount it - see irlmp_connect_request(). */
	skb_get(skb);

	/* Add at the end of the queue (keep ordering) - Jean II */
	skb_queue_tail(&self->txq, skb);

	/*
	 *  Send event if this frame only if we are in the right state
	 *  FIXME: udata should be sent first! (skb_queue_head?)
	 */
	if ((self->state == LAP_XMIT_P) || (self->state == LAP_XMIT_S)) {
		/* If we are not already processing the Tx queue, trigger
		 * transmission immediately - Jean II */
		if((skb_queue_len(&self->txq) <= 1) && (!self->local_busy))
			irlap_do_event(self, DATA_REQUEST, skb, NULL);
		/* Otherwise, the packets will be sent normally at the
		 * next pf-poll - Jean II */
	}
}

/*
 * Function irlap_unitdata_request (self, skb)
 *
 *    Send Ultra data. This is data that must be sent outside any connection
 *
 */
#ifdef CONFIG_IRDA_ULTRA
void irlap_unitdata_request(struct irlap_cb *self, struct sk_buff *skb)
{
	IRDA_ASSERT(self != NULL, return;);
	IRDA_ASSERT(self->magic == LAP_MAGIC, return;);

	IRDA_DEBUG(3, "%s()\n", __FUNCTION__);

	IRDA_ASSERT(skb_headroom(skb) >= (LAP_ADDR_HEADER+LAP_CTRL_HEADER),
	       return;);
	skb_push(skb, LAP_ADDR_HEADER+LAP_CTRL_HEADER);

	skb->data[0] = CBROADCAST;
	skb->data[1] = UI_FRAME;

	/* Don't need to refcount, see irlmp_connless_data_request() */

	skb_queue_tail(&self->txq_ultra, skb);

	irlap_do_event(self, SEND_UI_FRAME, NULL, NULL);
}
#endif /*CONFIG_IRDA_ULTRA */

/*
 * Function irlap_udata_indication (self, skb)
 *
 *    Receive Ultra data. This is data that is received outside any connection
 *
 */
#ifdef CONFIG_IRDA_ULTRA
void irlap_unitdata_indication(struct irlap_cb *self, struct sk_buff *skb)
{
	IRDA_DEBUG(1, "%s()\n", __FUNCTION__);

	IRDA_ASSERT(self != NULL, return;);
	IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
	IRDA_ASSERT(skb != NULL, return;);

	/* Hide LAP header from IrLMP layer */
	skb_pull(skb, LAP_ADDR_HEADER+LAP_CTRL_HEADER);

	irlmp_link_unitdata_indication(self->notify.instance, skb);
}
#endif /* CONFIG_IRDA_ULTRA */

/*
 * Function irlap_disconnect_request (void)
 *
 *    Request to disconnect connection by service user
 */
void irlap_disconnect_request(struct irlap_cb *self)
{
	IRDA_DEBUG(3, "%s()\n", __FUNCTION__);

	IRDA_ASSERT(self != NULL, return;);
	IRDA_ASSERT(self->magic == LAP_MAGIC, return;);

	/* Don't disconnect until all data frames are successfully sent */
	if (!skb_queue_empty(&self->txq)) {
		self->disconnect_pending = TRUE;
		return;
	}

	/* Check if we are in the right state for disconnecting */
	switch (self->state) {
	case LAP_XMIT_P:        /* FALLTROUGH */
	case LAP_XMIT_S:        /* FALLTROUGH */
	case LAP_CONN:          /* FALLTROUGH */
	case LAP_RESET_WAIT:    /* FALLTROUGH */
	case LAP_RESET_CHECK:
		irlap_do_event(self, DISCONNECT_REQUEST, NULL, NULL);
		break;
	default:
		IRDA_DEBUG(2, "%s(), disconnect pending!\n", __FUNCTION__);
		self->disconnect_pending = TRUE;
		break;
	}
}

/*
 * Function irlap_disconnect_indication (void)
 *
 *    Disconnect request from other device
 *
 */
void irlap_disconnect_indication(struct irlap_cb *self, LAP_REASON reason)
{
	IRDA_DEBUG(1, "%s(), reason=%s\n", __FUNCTION__, lap_reasons[reason]);

	IRDA_ASSERT(self != NULL, return;);
	IRDA_ASSERT(self->magic == LAP_MAGIC, return;);

	/* Flush queues */
	irlap_flush_all_queues(self);

	switch (reason) {
	case LAP_RESET_INDICATION:
		IRDA_DEBUG(1, "%s(), Sending reset request!\n", __FUNCTION__);
		irlap_do_event(self, RESET_REQUEST, NULL, NULL);
		break;
	case LAP_NO_RESPONSE:	   /* FALLTROUGH */
	case LAP_DISC_INDICATION:  /* FALLTROUGH */
	case LAP_FOUND_NONE:       /* FALLTROUGH */
	case LAP_MEDIA_BUSY:
		irlmp_link_disconnect_indication(self->notify.instance, self,
						 reason, NULL);
		break;
	default:
		IRDA_ERROR("%s: Unknown reason %d\n", __FUNCTION__, reason);
	}
}

/*
 * Function irlap_discovery_request (gen_addr_bit)
 *
 *    Start one single discovery operation.
 *
 */
void irlap_discovery_request(struct irlap_cb *self, discovery_t *discovery)
{
	struct irlap_info info;

	IRDA_ASSERT(self != NULL, return;);
	IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
	IRDA_ASSERT(discovery != NULL, return;);

	IRDA_DEBUG(4, "%s(), nslots = %d\n", __FUNCTION__, discovery->nslots);

	IRDA_ASSERT((discovery->nslots == 1) || (discovery->nslots == 6) ||
		    (discovery->nslots == 8) || (discovery->nslots == 16),
		    return;);

	/* Discovery is only possible in NDM mode */
	if (self->state != LAP_NDM) {
		IRDA_DEBUG(4, "%s(), discovery only possible in NDM mode\n",
			   __FUNCTION__);
		irlap_discovery_confirm(self, NULL);
		/* Note : in theory, if we are not in NDM, we could postpone
		 * the discovery like we do for connection request.
		 * In practice, it's not worth it. If the media was busy,
		 * it's likely next time around it won't be busy. If we are
		 * in REPLY state, we will get passive discovery info & event.
		 * Jean II */
		return;
	}

	/* Check if last discovery request finished in time, or if
	 * it was aborted due to the media busy flag. */
	if (self->discovery_log != NULL) {
		hashbin_delete(self->discovery_log, (FREE_FUNC) kfree);
		self->discovery_log = NULL;
	}

	/* All operations will occur at predictable time, no need to lock */
	self->discovery_log = hashbin_new(HB_NOLOCK);

	if (self->discovery_log == NULL) {
		IRDA_WARNING("%s(), Unable to allocate discovery log!\n",
			     __FUNCTION__);
		return;
	}

	info.S = discovery->nslots; /* Number of slots */
	info.s = 0; /* Current slot */

	self->discovery_cmd = discovery;
	info.discovery = discovery;

	/* sysctl_slot_timeout bounds are checked in irsysctl.c - Jean II */
	self->slot_timeout = sysctl_slot_timeout * HZ / 1000;

	irlap_do_event(self, DISCOVERY_REQUEST, NULL, &info);
}

/*
 * Function irlap_discovery_confirm (log)
 *
 *    A device has been discovered in front of this station, we
 *    report directly to LMP.
 */
void irlap_discovery_confirm(struct irlap_cb *self, hashbin_t *discovery_log)
{
	IRDA_ASSERT(self != NULL, return;);
	IRDA_ASSERT(self->magic == LAP_MAGIC, return;);

	IRDA_ASSERT(self->notify.instance != NULL, return;);

	/*
	 * Check for successful discovery, since we are then allowed to clear
	 * the media busy condition (IrLAP 6.13.4 - p.94). This should allow
	 * us to make connection attempts much faster and easier (i.e. no
	 * collisions).
	 * Setting media busy to false will also generate an event allowing
	 * to process pending events in NDM state machine.
	 * Note : the spec doesn't define what's a successful discovery is.
	 * If we want Ultra to work, it's successful even if there is
	 * nobody discovered - Jean II
	 */
	if (discovery_log)
		irda_device_set_media_busy(self->netdev, FALSE);

	/* Inform IrLMP */
	irlmp_link_discovery_confirm(self->notify.instance, discovery_log);
}

/*
 * Function irlap_discovery_indication (log)
 *
 *    Somebody is trying to discover us!
 *
 */
void irlap_discovery_indication(struct irlap_cb *self, discovery_t *discovery)
{
	IRDA_DEBUG(4, "%s()\n", __FUNCTION__);

	IRDA_ASSERT(self != NULL, return;);
	IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
	IRDA_ASSERT(discovery != NULL, return;);

	IRDA_ASSERT(self->notify.instance != NULL, return;);

	/* A device is very likely to connect immediately after it performs
	 * a successful discovery. This means that in our case, we are much
	 * more likely to receive a connection request over the medium.
	 * So, we backoff to avoid collisions.
	 * IrLAP spec 6.13.4 suggest 100ms...
	 * Note : this little trick actually make a *BIG* difference. If I set
	 * my Linux box with discovery enabled and one Ultra frame sent every
	 * second, my Palm has no trouble connecting to it every time !
	 * Jean II */
	irda_device_set_media_busy(self->netdev, SMALL);

	irlmp_link_discovery_indication(self->notify.instance, discovery);
}

/*
 * Function irlap_status_indication (quality_of_link)
 */
void irlap_status_indication(struct irlap_cb *self, int quality_of_link)
{
	switch (quality_of_link) {
	case STATUS_NO_ACTIVITY:
		IRDA_MESSAGE("IrLAP, no activity on link!\n");
		break;
	case STATUS_NOISY:
		IRDA_MESSAGE("IrLAP, noisy link!\n");
		break;
	default:
		break;
	}
	irlmp_status_indication(self->notify.instance,
				quality_of_link, LOCK_NO_CHANGE);
}

/*
 * Function irlap_reset_indication (void)
 */
void irlap_reset_indication(struct irlap_cb *self)
{
	IRDA_DEBUG(1, "%s()\n", __FUNCTION__);

	IRDA_ASSERT(self != NULL, return;);
	IRDA_ASSERT(self->magic == LAP_MAGIC, return;);

	if (self->state == LAP_RESET_WAIT)
		irlap_do_event(self, RESET_REQUEST, NULL, NULL);
	else
		irlap_do_event(self, RESET_RESPONSE, NULL, NULL);
}

/*
 * Function irlap_reset_confirm (void)
 */
void irlap_reset_confirm(void)
{
	IRDA_DEBUG(1, "%s()\n", __FUNCTION__);
}

/*
 * Function irlap_generate_rand_time_slot (S, s)
 *
 *    Generate a random time slot between s and S-1 where
 *    S = Number of slots (0 -> S-1)
 *    s = Current slot
 */
int irlap_generate_rand_time_slot(int S, int s)
{
	static int rand;
	int slot;

	IRDA_ASSERT((S - s) > 0, return 0;);

	rand += jiffies;
	rand ^= (rand << 12);
	rand ^= (rand >> 20);

	slot = s + rand % (S-s);

	IRDA_ASSERT((slot >= s) || (slot < S), return 0;);

	return slot;
}

/*
 * Function irlap_update_nr_received (nr)
 *
 *    Remove all acknowledged frames in current window queue. This code is
 *    not intuitive and you should not try to change it. If you think it
 *    contains bugs, please mail a patch to the author instead.
 */
void irlap_update_nr_received(struct irlap_cb *self, int nr)
{
	struct sk_buff *skb = NULL;
	int count = 0;

	/*
         * Remove all the ack-ed frames from the window queue.
         */

	/*
	 *  Optimize for the common case. It is most likely that the receiver
	 *  will acknowledge all the frames we have sent! So in that case we
	 *  delete all frames stored in window.
	 */
	if (nr == self->vs) {
		while ((skb = skb_dequeue(&self->wx_list)) != NULL) {
			dev_kfree_skb(skb);
		}
		/* The last acked frame is the next to send minus one */
		self->va = nr - 1;
	} else {
		/* Remove all acknowledged frames in current window */
		while ((skb_peek(&self->wx_list) != NULL) &&
		       (((self->va+1) % 8) != nr))
		{
			skb = skb_dequeue(&self->wx_list);
			dev_kfree_skb(skb);

			self->va = (self->va + 1) % 8;
			count++;
		}
	}

	/* Advance window */
	self->window = self->window_size - skb_queue_len(&self->wx_list);
}

/*
 * Function irlap_validate_ns_received (ns)
 *
 *    Validate the next to send (ns) field from received frame.
 */
int irlap_validate_ns_received(struct irlap_cb *self, int ns)
{
	/*  ns as expected?  */
	if (ns == self->vr)
		return NS_EXPECTED;
	/*
	 *  Stations are allowed to treat invalid NS as unexpected NS
	 *  IrLAP, Recv ... with-invalid-Ns. p. 84
	 */
	return NS_UNEXPECTED;

	/* return NR_INVALID; */
}
/*
 * Function irlap_validate_nr_received (nr)
 *
 *    Validate the next to receive (nr) field from received frame.
 *
 */
int irlap_validate_nr_received(struct irlap_cb *self, int nr)
{
	/*  nr as expected?  */
	if (nr == self->vs) {
		IRDA_DEBUG(4, "%s(), expected!\n", __FUNCTION__);
		return NR_EXPECTED;
	}

	/*
	 *  unexpected nr? (but within current window), first we check if the
	 *  ns numbers of the frames in the current window wrap.
	 */
	if (self->va < self->vs) {
		if ((nr >= self->va) && (nr <= self->vs))
			return NR_UNEXPECTED;
	} else {
		if ((nr >= self->va) || (nr <= self->vs))
			return NR_UNEXPECTED;
	}

	/* Invalid nr!  */
	return NR_INVALID;
}

/*
 * Function irlap_initiate_connection_state ()
 *
 *    Initialize the connection state parameters
 *
 */
void irlap_initiate_connection_state(struct irlap_cb *self)
{
	IRDA_DEBUG(4, "%s()\n", __FUNCTION__);

	IRDA_ASSERT(self != NULL, return;);
	IRDA_ASSERT(self->magic == LAP_MAGIC, return;);

	/* Next to send and next to receive */
	self->vs = self->vr = 0;

	/* Last frame which got acked (0 - 1) % 8 */
	self->va = 7;

	self->window = 1;

	self->remote_busy = FALSE;
	self->retry_count = 0;
}

/*
 * Function irlap_wait_min_turn_around (self, qos)
 *
 *    Wait negotiated minimum turn around time, this function actually sets
 *    the number of BOS's that must be sent before the next transmitted
 *    frame in order to delay for the specified amount of time. This is
 *    done to avoid using timers, and the forbidden udelay!
 */
void irlap_wait_min_turn_around(struct irlap_cb *self, struct qos_info *qos)
{
	__u32 min_turn_time;
	__u32 speed;

	/* Get QoS values.  */
	speed = qos->baud_rate.value;
	min_turn_time = qos->min_turn_time.value;

	/* No need to calculate XBOFs for speeds over 115200 bps */
	if (speed > 115200) {
		self->mtt_required = min_turn_time;
		return;
	}

	/*
	 *  Send additional BOF's for the next frame for the requested
	 *  min turn time, so now we must calculate how many chars (XBOF's) we
	 *  must send for the requested time period (min turn time)
	 */
	self->xbofs_delay = irlap_min_turn_time_in_bytes(speed, min_turn_time);
}

/*
 * Function irlap_flush_all_queues (void)
 *
 *    Flush all queues
 *
 */
void irlap_flush_all_queues(struct irlap_cb *self)
{
	struct sk_buff* skb;

	IRDA_ASSERT(self != NULL, return;);
	IRDA_ASSERT(self->magic == LAP_MAGIC, return;);

	/* Free transmission queue */
	while ((skb = skb_dequeue(&self->txq)) != NULL)
		dev_kfree_skb(skb);

	while ((skb = skb_dequeue(&self->txq_ultra)) != NULL)
		dev_kfree_skb(skb);

	/* Free sliding window buffered packets */
	while ((skb = skb_dequeue(&self->wx_list)) != NULL)
		dev_kfree_skb(skb);
}

/*
 * Function irlap_setspeed (self, speed)
 *
 *    Change the speed of the IrDA port
 *
 */
static void irlap_change_speed(struct irlap_cb *self, __u32 speed, int now)
{
	struct sk_buff *skb;

	IRDA_DEBUG(0, "%s(), setting speed to %d\n", __FUNCTION__, speed);

	IRDA_ASSERT(self != NULL, return;);
	IRDA_ASSERT(self->magic == LAP_MAGIC, return;);

	self->speed = speed;

	/* Change speed now, or just piggyback speed on frames */
	if (now) {
		/* Send down empty frame to trigger speed change */
		skb = dev_alloc_skb(0);
		irlap_queue_xmit(self, skb);
	}
}

/*
 * Function irlap_init_qos_capabilities (self, qos)
 *
 *    Initialize QoS for this IrLAP session, What we do is to compute the
 *    intersection of the QoS capabilities for the user, driver and for
 *    IrLAP itself. Normally, IrLAP will not specify any values, but it can
 *    be used to restrict certain values.
 */
static void irlap_init_qos_capabilities(struct irlap_cb *self,
					struct qos_info *qos_user)
{
	IRDA_ASSERT(self != NULL, return;);
	IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
	IRDA_ASSERT(self->netdev != NULL, return;);

	/* Start out with the maximum QoS support possible */
	irda_init_max_qos_capabilies(&self->qos_rx);

	/* Apply drivers QoS capabilities */
	irda_qos_compute_intersection(&self->qos_rx, self->qos_dev);

	/*
	 *  Check for user supplied QoS parameters. The service user is only
	 *  allowed to supply these values. We check each parameter since the
	 *  user may not have set all of them.
	 */
	if (qos_user) {
		IRDA_DEBUG(1, "%s(), Found user specified QoS!\n", __FUNCTION__);

		if (qos_user->baud_rate.bits)
			self->qos_rx.baud_rate.bits &= qos_user->baud_rate.bits;

		if (qos_user->max_turn_time.bits)
			self->qos_rx.max_turn_time.bits &= qos_user->max_turn_time.bits;
		if (qos_user->data_size.bits)
			self->qos_rx.data_size.bits &= qos_user->data_size.bits;

		if (qos_user->link_disc_time.bits)
			self->qos_rx.link_disc_time.bits &= qos_user->link_disc_time.bits;
	}

	/* Use 500ms in IrLAP for now */
	self->qos_rx.max_turn_time.bits &= 0x01;

	/* Set data size */
	/*self->qos_rx.data_size.bits &= 0x03;*/

	irda_qos_bits_to_value(&self->qos_rx);
}

/*
 * Function irlap_apply_default_connection_parameters (void, now)
 *
 *    Use the default connection and transmission parameters
 */
void irlap_apply_default_connection_parameters(struct irlap_cb *self)
{
	IRDA_DEBUG(4, "%s()\n", __FUNCTION__);

	IRDA_ASSERT(self != NULL, return;);
	IRDA_ASSERT(self->magic == LAP_MAGIC, return;);

	/* xbofs : Default value in NDM */
	self->next_bofs   = 12;
	self->bofs_count  = 12;

	/* NDM Speed is 9600 */
	irlap_change_speed(self, 9600, TRUE);

	/* Set mbusy when going to NDM state */
	irda_device_set_media_busy(self->netdev, TRUE);

	/*
	 * Generate random connection address for this session, which must
	 * be 7 bits wide and different from 0x00 and 0xfe
	 */
	while ((self->caddr == 0x00) || (self->caddr == 0xfe)) {
		get_random_bytes(&self->caddr, sizeof(self->caddr));
		self->caddr &= 0xfe;
	}

	/* Use default values until connection has been negitiated */
	self->slot_timeout = sysctl_slot_timeout;
	self->final_timeout = FINAL_TIMEOUT;
	self->poll_timeout = POLL_TIMEOUT;
	self->wd_timeout = WD_TIMEOUT;

	/* Set some default values */
	self->qos_tx.baud_rate.value = 9600;
	self->qos_rx.baud_rate.value = 9600;
	self->qos_tx.max_turn_time.value = 0;
	self->qos_rx.max_turn_time.value = 0;
	self->qos_tx.min_turn_time.value = 0;
	self->qos_rx.min_turn_time.value = 0;
	self->qos_tx.data_size.value = 64;
	self->qos_rx.data_size.value = 64;
	self->qos_tx.window_size.value = 1;
	self->qos_rx.window_size.value = 1;
	self->qos_tx.additional_bofs.value = 12;
	self->qos_rx.additional_bofs.value = 12;
	self->qos_tx.link_disc_time.value = 0;
	self->qos_rx.link_disc_time.value = 0;

	irlap_flush_all_queues(self);

	self->disconnect_pending = FALSE;
	self->connect_pending = FALSE;
}

/*
 * Function irlap_apply_connection_parameters (qos, now)
 *
 *    Initialize IrLAP with the negotiated QoS values
 *
 * If 'now' is false, the speed and xbofs will be changed after the next
 * frame is sent.
 * If 'now' is true, the speed and xbofs is changed immediately
 */
void irlap_apply_connection_parameters(struct irlap_cb *self, int now)
{
	IRDA_DEBUG(4, "%s()\n", __FUNCTION__);

	IRDA_ASSERT(self != NULL, return;);
	IRDA_ASSERT(self->magic == LAP_MAGIC, return;);

	/* Set the negotiated xbofs value */
	self->next_bofs   = self->qos_tx.additional_bofs.value;
	if (now)
		self->bofs_count = self->next_bofs;

	/* Set the negotiated link speed (may need the new xbofs value) */
	irlap_change_speed(self, self->qos_tx.baud_rate.value, now);

	self->window_size = self->qos_tx.window_size.value;
	self->window      = self->qos_tx.window_size.value;

#ifdef CONFIG_IRDA_DYNAMIC_WINDOW
	/*
	 *  Calculate how many bytes it is possible to transmit before the
	 *  link must be turned around
	 */
	self->line_capacity =
		irlap_max_line_capacity(self->qos_tx.baud_rate.value,
					self->qos_tx.max_turn_time.value);
	self->bytes_left = self->line_capacity;
#endif /* CONFIG_IRDA_DYNAMIC_WINDOW */

	/*
	 *  Initialize timeout values, some of the rules are listed on
	 *  page 92 in IrLAP.
	 */
	IRDA_ASSERT(self->qos_tx.max_turn_time.value != 0, return;);
	IRDA_ASSERT(self->qos_rx.max_turn_time.value != 0, return;);
	/* The poll timeout applies only to the primary station.
	 * It defines the maximum time the primary stay in XMIT mode
	 * before timeout and turning the link around (sending a RR).
	 * Or, this is how much we can keep the pf bit in primary mode.
	 * Therefore, it must be lower or equal than our *OWN* max turn around.
	 * Jean II */
	self->poll_timeout = self->qos_tx.max_turn_time.value * HZ / 1000;
	/* The Final timeout applies only to the primary station.
	 * It defines the maximum time the primary wait (mostly in RECV mode)
	 * for an answer from the secondary station before polling it again.
	 * Therefore, it must be greater or equal than our *PARTNER*
	 * max turn around time - Jean II */
	self->final_timeout = self->qos_rx.max_turn_time.value * HZ / 1000;
	/* The Watchdog Bit timeout applies only to the secondary station.
	 * It defines the maximum time the secondary wait (mostly in RECV mode)
	 * for poll from the primary station before getting annoyed.
	 * Therefore, it must be greater or equal than our *PARTNER*
	 * max turn around time - Jean II */
	self->wd_timeout = self->final_timeout * 2;

	/*
	 * N1 and N2 are maximum retry count for *both* the final timer
	 * and the wd timer (with a factor 2) as defined above.
	 * After N1 retry of a timer, we give a warning to the user.
	 * After N2 retry, we consider the link dead and disconnect it.
	 * Jean II
	 */

	/*
	 *  Set N1 to 0 if Link Disconnect/Threshold Time = 3 and set it to
	 *  3 seconds otherwise. See page 71 in IrLAP for more details.
	 *  Actually, it's not always 3 seconds, as we allow to set
	 *  it via sysctl... Max maxtt is 500ms, and N1 need to be multiple
	 *  of 2, so 1 second is minimum we can allow. - Jean II
	 */
	if (self->qos_tx.link_disc_time.value == sysctl_warn_noreply_time)
		/*
		 * If we set N1 to 0, it will trigger immediately, which is
		 * not what we want. What we really want is to disable it,
		 * Jean II
		 */
		self->N1 = -2; /* Disable - Need to be multiple of 2*/
	else
		self->N1 = sysctl_warn_noreply_time * 1000 /
		  self->qos_rx.max_turn_time.value;

	IRDA_DEBUG(4, "Setting N1 = %d\n", self->N1);

	/* Set N2 to match our own disconnect time */
	self->N2 = self->qos_tx.link_disc_time.value * 1000 /
		self->qos_rx.max_turn_time.value;
	IRDA_DEBUG(4, "Setting N2 = %d\n", self->N2);
}

#ifdef CONFIG_PROC_FS
struct irlap_iter_state {
	int id;
};

static void *irlap_seq_start(struct seq_file *seq, loff_t *pos)
{
	struct irlap_iter_state *iter = seq->private;
	struct irlap_cb *self;

	/* Protect our access to the tsap list */
	spin_lock_irq(&irlap->hb_spinlock);
	iter->id = 0;

	for (self = (struct irlap_cb *) hashbin_get_first(irlap);
	     self; self = (struct irlap_cb *) hashbin_get_next(irlap)) {
		if (iter->id == *pos)
			break;
		++iter->id;
	}

	return self;
}

static void *irlap_seq_next(struct seq_file *seq, void *v, loff_t *pos)
{
	struct irlap_iter_state *iter = seq->private;

	++*pos;
	++iter->id;
	return (void *) hashbin_get_next(irlap);
}

static void irlap_seq_stop(struct seq_file *seq, void *v)
{
	spin_unlock_irq(&irlap->hb_spinlock);
}

static int irlap_seq_show(struct seq_file *seq, void *v)
{
	const struct irlap_iter_state *iter = seq->private;
	const struct irlap_cb *self = v;

	IRDA_ASSERT(self->magic == LAP_MAGIC, return -EINVAL;);

	seq_printf(seq, "irlap%d ", iter->id);
	seq_printf(seq, "state: %s\n",
		   irlap_state[self->state]);

	seq_printf(seq, "  device name: %s, ",
		   (self->netdev) ? self->netdev->name : "bug");
	seq_printf(seq, "hardware name: %s\n", self->hw_name);

	seq_printf(seq, "  caddr: %#02x, ", self->caddr);
	seq_printf(seq, "saddr: %#08x, ", self->saddr);
	seq_printf(seq, "daddr: %#08x\n", self->daddr);

	seq_printf(seq, "  win size: %d, ",
		   self->window_size);
	seq_printf(seq, "win: %d, ", self->window);
#ifdef CONFIG_IRDA_DYNAMIC_WINDOW
	seq_printf(seq, "line capacity: %d, ",
		   self->line_capacity);
	seq_printf(seq, "bytes left: %d\n", self->bytes_left);
#endif /* CONFIG_IRDA_DYNAMIC_WINDOW */
	seq_printf(seq, "  tx queue len: %d ",
		   skb_queue_len(&self->txq));
	seq_printf(seq, "win queue len: %d ",
		   skb_queue_len(&self->wx_list));
	seq_printf(seq, "rbusy: %s", self->remote_busy ?
		   "TRUE" : "FALSE");
	seq_printf(seq, " mbusy: %s\n", self->media_busy ?
		   "TRUE" : "FALSE");

	seq_printf(seq, "  retrans: %d ", self->retry_count);
	seq_printf(seq, "vs: %d ", self->vs);
	seq_printf(seq, "vr: %d ", self->vr);
	seq_printf(seq, "va: %d\n", self->va);

	seq_printf(seq, "  qos\tbps\tmaxtt\tdsize\twinsize\taddbofs\tmintt\tldisc\tcomp\n");

	seq_printf(seq, "  tx\t%d\t",
		   self->qos_tx.baud_rate.value);
	seq_printf(seq, "%d\t",
		   self->qos_tx.max_turn_time.value);
	seq_printf(seq, "%d\t",
		   self->qos_tx.data_size.value);
	seq_printf(seq, "%d\t",
		   self->qos_tx.window_size.value);
	seq_printf(seq, "%d\t",
		   self->qos_tx.additional_bofs.value);
	seq_printf(seq, "%d\t",
		   self->qos_tx.min_turn_time.value);
	seq_printf(seq, "%d\t",
		   self->qos_tx.link_disc_time.value);
	seq_printf(seq, "\n");

	seq_printf(seq, "  rx\t%d\t",
		   self->qos_rx.baud_rate.value);
	seq_printf(seq, "%d\t",
		   self->qos_rx.max_turn_time.value);
	seq_printf(seq, "%d\t",
		   self->qos_rx.data_size.value);
	seq_printf(seq, "%d\t",
		   self->qos_rx.window_size.value);
	seq_printf(seq, "%d\t",
		   self->qos_rx.additional_bofs.value);
	seq_printf(seq, "%d\t",
		   self->qos_rx.min_turn_time.value);
	seq_printf(seq, "%d\n",
		   self->qos_rx.link_disc_time.value);

	return 0;
}

static struct seq_operations irlap_seq_ops = {
	.start  = irlap_seq_start,
	.next   = irlap_seq_next,
	.stop   = irlap_seq_stop,
	.show   = irlap_seq_show,
};

static int irlap_seq_open(struct inode *inode, struct file *file)
{
	struct seq_file *seq;
	int rc = -ENOMEM;
	struct irlap_iter_state *s = kmalloc(sizeof(*s), GFP_KERNEL);

	if (!s)
		goto out;

	if (irlap == NULL) {
		rc = -EINVAL;
		goto out_kfree;
	}

	rc = seq_open(file, &irlap_seq_ops);
	if (rc)
		goto out_kfree;

	seq	     = file->private_data;
	seq->private = s;
	memset(s, 0, sizeof(*s));
out:
	return rc;
out_kfree:
	kfree(s);
	goto out;
}

struct file_operations irlap_seq_fops = {
	.owner		= THIS_MODULE,
	.open           = irlap_seq_open,
	.read           = seq_read,
	.llseek         = seq_lseek,
	.release	= seq_release_private,
};

#endif /* CONFIG_PROC_FS */


text:
using System;
using System.Collections.Generic;

// -----===== autogenerated code =====-----
// ReSharper disable All
// generator: FractionUnitGenerator, DerivedUnitGenerator

namespace iSukces.UnitedValues
{
    public sealed partial class LinearDensityUnit : IFractionalUnit<MassUnit, LengthUnit>, IEquatable<LinearDensityUnit>, IDecomposableUnit
    {
        /// <summary>
        /// creates instance of LinearDensityUnit
        /// </summary>
        /// <param name="counterUnit">counter unit</param>
        /// <param name="denominatorUnit">denominator unit</param>
        public LinearDensityUnit(MassUnit counterUnit, LengthUnit denominatorUnit)
        {
            CounterUnit = counterUnit;
            DenominatorUnit = denominatorUnit;
        }

        public IReadOnlyList<DecomposableUnitItem> Decompose()
        {
            // generator : FractionUnitGenerator.Add_Decompose
            return new []
            {
                new DecomposableUnitItem(CounterUnit, 1),
                new DecomposableUnitItem(DenominatorUnit, -1)
            };
            /*
            var decomposer = new UnitDecomposer();
            decomposer.Add(CounterUnit, 1);
            decomposer.Add(DenominatorUnit, -1);
            return decomposer.Items;
            */
        }

        public bool Equals(LinearDensityUnit other)
        {
            return CounterUnit.Equals(other.CounterUnit) && DenominatorUnit.Equals(other.DenominatorUnit);
        }

        public override bool Equals(object other)
        {
            return other is LinearDensityUnit unitedValue ? Equals(unitedValue) : false;
        }

        public override int GetHashCode()
        {
            unchecked
            {
                return (CounterUnit.GetHashCode() * 397) ^ DenominatorUnit.GetHashCode();
            }
        }

        /// <summary>
        /// Returns unit name
        /// </summary>
        public override string ToString()
        {
            return UnitName;
        }

        public LinearDensityUnit WithCounterUnit(MassUnit newUnit)
        {
            // generator : FractionUnitGenerator.Add_WithSecond
            return new LinearDensityUnit(newUnit, DenominatorUnit);
        }

        public LinearDensityUnit WithDenominatorUnit(LengthUnit newUnit)
        {
            // generator : FractionUnitGenerator.Add_WithFirst
            return new LinearDensityUnit(CounterUnit, newUnit);
        }

        /// <summary>
        /// Inequality operator
        /// </summary>
        /// <param name="left">first value to compare</param>
        /// <param name="right">second value to compare</param>
        public static bool operator !=(LinearDensityUnit left, LinearDensityUnit right)
        {
            return !left.Equals(right);
        }

        /// <summary>
        /// Equality operator
        /// </summary>
        /// <param name="left">first value to compare</param>
        /// <param name="right">second value to compare</param>
        public static bool operator ==(LinearDensityUnit left, LinearDensityUnit right)
        {
            return left.Equals(right);
        }

        /// <summary>
        /// counter unit
        /// </summary>
        public MassUnit CounterUnit { get; }

        /// <summary>
        /// denominator unit
        /// </summary>
        public LengthUnit DenominatorUnit { get; }

        public string UnitName
        {
            get { return CounterUnit.UnitName + "/" + DenominatorUnit.UnitName; }
        }

    }

    [UnitsContainer]
    public static partial class LinearDensityUnits
    {
        public static void RegisterUnitExchangeFactors(UnitExchangeFactors factors)
        {
            factors.RegisterMany(All);
        }

        public static LinearDensityUnit TryRecoverUnitFromName([JetBrains.Annotations.NotNull] string unitName)
        {
            // generator : DerivedUnitGenerator.Add_TryRecoverUnitFromName
            if (unitName is null)
                throw new NullReferenceException(nameof(unitName));
            unitName = unitName.Trim();
            if (unitName.Length == 0)
                throw new ArgumentException(nameof(unitName));
            foreach (var i in All)
            {
                if (unitName == i.UnitName)
                    return i.Unit;
            }
            // try to split
            var parts = unitName.Split('/');
            if (parts.Length == 2)
            {
                var counterUnit = MassUnits.TryRecoverUnitFromName(parts[0]);
                var denominatorUnit = LengthUnits.TryRecoverUnitFromName(parts[1]);
                return new LinearDensityUnit(counterUnit, denominatorUnit);
            }
            throw new ArgumentException(nameof(unitName));
        }

        /// <summary>
        /// All known linearDensity units
        /// </summary>
        public static IReadOnlyList<UnitDefinition<LinearDensityUnit>> All
        {
            get
            {
                return new []
                {
                    KgPerMeter
                };
            }
        }

        internal static readonly LinearDensityUnit KgPerMeterLinearDensityUnit = new LinearDensityUnit(MassUnits.Kg, LengthUnits.Meter);

        public static readonly UnitDefinition<LinearDensityUnit> KgPerMeter = new UnitDefinition<LinearDensityUnit>(KgPerMeterLinearDensityUnit, 1m);

    }
}

redpajama_set_name: RedPajamaGithub


text:
from __future__ import absolute_import, division, print_function
import opsimsummary as oss
import opsimsummary.summarize_opsim as so
from sqlalchemy import create_engine
import pandas as pd
import os

def test_writeSimlib():
    pkgDir = os.path.split(oss.__file__)[0]
    dbname = os.path.join(pkgDir, 'example_data', 'enigma_1189_micro.db')
    template_simlib = os.path.join(pkgDir, 'example_data',
                                   'Enigma_1189_micro_main.simlib')

    engineFile = 'sqlite:///' + dbname
    engine = create_engine(engineFile)

    # read the database into a `pd.DataFrame`
    Summary = pd.read_sql_table('Summary', engine)

    EnigmaMain = Summary.query('propID == [364]')
    EnigmaMainSummary = so.SummaryOpsim(EnigmaMain, calculateSNANASimlibs=True,
                                        user='rbiswas', host='time')
    simlibfilename = './Enigma_1189_micro_main.simlib'
    EnigmaMainSummary.writeSimlib(simlibfilename)

    with open(template_simlib) as f:
        template_data = f.read()
    with open(simlibfilename) as f:
        new_data = f.read()
    assert new_data == template_data
    if new_data == template_data :
        os.remove(simlibfilename)

if __name__ == '__main__':
    test_writeSimlib()


text:
package org.openengsb.core.xmlmapping;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

@XmlRootElement(name = "XMLReturnValue")
@XmlType(name = "XMLReturnValue")
public class XMLReturnValue
{
    private XMLTypedValue value;

    @XmlElement(required = true)
    public XMLTypedValue getValue() {
        return value;
    }

    public void setValue(XMLTypedValue value) {
        this.value = value;
    }
}


text:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.6"/>
<title>Open SCAP Library: route_info Struct Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>

<link href="doxygen.css" rel="stylesheet" type="text/css" />

Open SCAP Library

Main Page

Related Pages

Modules

Data Structures

Files

Data Structures

Data Structure Index

Data Fields

Data Fields

route_info Struct Reference

Data Fields

SEXP_t * 	ip_dst_ent

char 	ip_dst [INET6_ADDRSTRLEN+1]

char 	ip_gw [INET6_ADDRSTRLEN+1]

char * 	rt_flags [RT_FLAGS_MAX+1]

char 	if_name [IF_NAME_MAXLEN+1]

int 	ip_version

The documentation for this struct was generated from the following file:

routingtable.c

<address class="footer">
Generated by

 1.8.6
</address>


text:
layout: book
section: documentation
category: tutorials
title: Ubuntu service
permalink: /docs/tutorials/ubuntu-service
---
By default, TileMill runs as a desktop-style application on Ubuntu, but it can also run as a system-wide service managed by [upstart](http://upstart.ubuntu.com/).

- **Start** TileMill by running `sudo start tilemill`
- **Stop** TileMill by running `sudo stop tilemill`
- **Restart** TileMill by running `sudo restart tilemill`
- **Files** used by TileMill are in `/usr/share/mapbox`
- **Logs** are written to `/var/log/tilemill`
- **Preferences** can be changed by editing `/etc/tilemill/tilemill.config`

Once TileMill has started you can access the interface in your web browser at `http://localhost:8889`.


text:
import unittest
from graphtheory.structures.edges import Edge
from graphtheory.structures.graphs import Graph
from graphtheory.planarity.planarfactory import PlanarGraphFactory
from graphtheory.planarity.wheels import is_wheel

class TestPlanarGraphFactory(unittest.TestCase):

    def setUp(self):
        self.N = 4           # number of nodes
        self.graph_factory = PlanarGraphFactory(Graph)

    def test_cyclic(self):
        G = self.graph_factory.make_cyclic(n=self.N)
        self.assertFalse(G.is_directed())
        self.assertEqual(G.v(), self.N)
        self.assertEqual(G.e(), self.N)
        aset = set(edge.weight for edge in G.iteredges())
        self.assertEqual(G.e(), len(aset))
        faces = list(G.iterfaces())
        self.assertEqual(G.f(), 2)
        self.assertEqual(len(faces), 2)
        #print ( "faces {}".format(faces) )
        edge1 = next(G.iteredges())
        #print ( edge1 )
        #print ( list(G.iterface(edge1)) )
        #print ( list(G.iterface(~edge1)) )
        self.assertEqual(len(list(G.iterface(edge1))), self.N)
        self.assertEqual(len(list(G.iterface(~edge1))), self.N)
        self.assertRaises(ValueError, self.graph_factory.make_cyclic, 1)
        # For n=1 and the Graph class we have
        # ValueError("loops are forbidden")
        self.assertRaises(ValueError, self.graph_factory.make_cyclic, 2)
        # For n=2 and the Graph class we have
        # ValueError("parallel edges are forbidden")
        #print ( G.edge2face )
        #print ( G.face2edge )
        self.assertEqual(len(G.edge2face), 2 * self.N)
        self.assertEqual(len(G.face2edge), 2)

    def test_wheel(self):
        G = self.graph_factory.make_wheel(n=self.N)
        self.assertFalse(G.is_directed())
        self.assertEqual(G.v(), self.N)
        self.assertEqual(G.e(), 2 * (self.N - 1))
        self.assertTrue(is_wheel(G))
        faces = list(G.iterfaces())
        self.assertEqual(G.f(), self.N)
        self.assertEqual(len(faces), self.N)
        #print ( "faces {}".format(faces) )
        self.assertRaises(ValueError, self.graph_factory.make_wheel, 1)
        self.assertRaises(ValueError, self.graph_factory.make_wheel, 2)
        self.assertRaises(ValueError, self.graph_factory.make_wheel, 3)
        #print ( G.edge2face )
        #print ( G.face2edge )
        self.assertEqual(len(G.edge2face), 4 * (self.N - 1))
        self.assertEqual(len(G.face2edge), self.N)

    def tearDown(self): pass

if __name__ == "__main__":

    unittest.main()

# EOF


text:
/* TEMPLATE GENERATED TESTCASE FILE
Filename: CWE23_Relative_Path_Traversal__wchar_t_environment_ifstream_82_bad.cpp
Label Definition File: CWE23_Relative_Path_Traversal.label.xml
Template File: sources-sink-82_bad.tmpl.cpp
*/
/*
 * @description
 * CWE: 23 Relative Path Traversal
 * BadSource: environment Read input from an environment variable
 * GoodSource: Use a fixed file name
 * Sinks: ifstream
 *    BadSink : Open the file named in data using ifstream::open()
 * Flow Variant: 82 Data flow: data passed in a parameter to a virtual method called via a pointer
 *
 * */
#ifndef OMITBAD

#include "std_testcase.h"
#include "CWE23_Relative_Path_Traversal__wchar_t_environment_ifstream_82.h"

#include <fstream>
using namespace std;

namespace CWE23_Relative_Path_Traversal__wchar_t_environment_ifstream_82
{

void CWE23_Relative_Path_Traversal__wchar_t_environment_ifstream_82_bad::action(wchar_t * data)
{
    {
        ifstream inputFile;
        /* POTENTIAL FLAW: Possibly opening a file without validating the file name or path */
        inputFile.open((char *)data);
        inputFile.close();
    }
}

}
#endif /* OMITBAD */


text:
/**
 * @file 静态资源管理
 * @author mj(zouamiaojiang@gmail.com)
 */

'use strict';

const Router = require('koa-router');
const router = new Router();
const validate = require('../common/middlewares/validator.js');
const Model = require('../model/Static.js');
const fs = require('fs-extra');
const conf = require('../common/conf.js').get('app');

const re = /^(.*?)(\((\d*?)\))?(\.(png|gif|psd|jpg|jpeg))?$/i;

router.prefix('/static');

const EXT_NAME_MAP = {
    'image/jpeg': '.jpg',
    'image/png': '.png',
    'image/gif': '.gif'
};

router.post('/upload', function* () {

    const files = this.request.body.files;
    const fields = this.request.body.fields;
    const dbModels = yield this.getDBModels();
    const model = Model.getInstance(dbModels);
    try {
        const imageFile = files.image;
        const sourcePath = imageFile.path;
        const type = imageFile.type;
        const name = imageFile.name;
        const parent = fields.parent;
        const size = parseInt(imageFile.size / 1000, 10) + 'K';
        let alreadyHasName = yield model.alreadyHasName({ parent, name });
        let num = 0;
        let originName = '';
        let abspath = yield model.fetchPath(parent);
        let storePath;
        let extname = EXT_NAME_MAP[type];
        while (alreadyHasName) {
            let arr = name.match(re);
            originName = arr[1] || '';
            num = arr[3] || 0;
            extname = arr[4] || extname;
            num++;
            name = `${originName}(${num})${extname}`;
            alreadyHasName = yield model.alreadyHasName({ parent, name });
        }
        yield model.unfold(parent);
        yield model.addFile({ name, size, type, comments: '文件描述', parent });
        storePath = `${conf.rootPath}/data/resources/${abspath}${name}`;
        fs.copy(sourcePath, storePath);
        const data = yield model.fetchStatics();

        this.body = {
            status: 0,
            data
        };

    }
    catch (e) {
        this.logger.warning(e.message);
        this.status = 500;
        this.body = {
            status: 500,
            statusInfo: '上传出错'
        };
    }
});

router.post('/addFold', function* () {
    const dbModels = yield this.getDBModels();
    const model = Model.getInstance(dbModels);
    const params = this.request.body;
    const parent = params.parent || '';

    try {
        let name = '文件夹';
        let alreadyHasName = yield model.alreadyHasName({ parent, name });
        let num = 0;
        let originName = '';
        let abspath = yield model.fetchPath(parent);
        let storePath;
        while (alreadyHasName) {
            let arr = name.match(re);
            originName = arr[1] || '';
            num = arr[3] || 0;
            num++;
            name = `${originName}(${num})`;
            alreadyHasName = yield model.alreadyHasName({ parent, name });
        }
        storePath = `${conf.rootPath}/data/resources/${abspath}${name}`;
        yield model.unfold(parent);
        yield model.addFold({
            name,
            comments: '文件夹描述',
            parent,
            open: false
        });

        fs.mkdirs(storePath);
        const data = yield model.fetchStatics();
        this.body = {
            status: 0,
            data
        }
    }
    catch (e) {
        this.logger.warning(e.message);
        this.status = 500;
        this.body = {
            status: 500,
            statusInfo: '添加文件夹出错'
        };
    }
});

router.post('/update', function* () {
    const dbModels = yield this.getDBModels();
    const model = Model.getInstance(dbModels);
    const params = this.request.body;
    const parent = params.parent || '';

    if (params.field == 'name') {
        let name = params.value;
        let abspath = params.abspath;
        let alreadyHasName = yield model.alreadyHasName({ parent, name });
        let num = 0;
        let extname = params.extname || '';
        let originName = '';
        let newAbspath = yield model.fetchPath(parent);
        let oldStorePath;
        let newStorePath;
        while (alreadyHasName) {
            let arr = name.match(re);
            originName = arr[1] || '';
            num = arr[3] || 0;
            extname = arr[4] || extname;
            num++;
            params.value = name = `${originName}(${num})${extname}`;
            alreadyHasName = yield model.alreadyHasName({ parent, name });
        }

        oldStorePath = `${conf.rootPath}/data/resources/${abspath}`;
        newStorePath = `${conf.rootPath}/data/resources/${newAbspath}${name}`;
        fs.move(
            oldStorePath,
            newStorePath,
            {
                clobber: true,
            },
            err => {}
        );
    }

    yield model.update(params);
    const statics = yield model.fetchStatics();

    this.body = {
        status: 0,
        data: {
            statics,
            info: params
        }
    }
});

router.post('/remove', function* () {
    const dbModels = yield this.getDBModels();
    const model = Model.getInstance(dbModels);
    const params = this.request.body;
    const id = params.id;
    const abspath = params.abspath;

    yield model.remove(id);
    const statics = yield model.fetchStatics();
    const storePath = `${conf.rootPath}/data/resources/${abspath}`;
    fs.remove(storePath)

    this.body = {
        status: 0,
        data: {
            statics
        }
    };
});

module.exports = router;


text:
tools
=====

Contains random tools that might be fun to use.

Use for research and don't be evil.


text:
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Postgres on whatsgood.io</title>
    <link>http://whatsgood.io/tags/postgres/index.xml</link>
    <description>Recent content in Postgres on whatsgood.io</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <atom:link href="http://whatsgood.io/tags/postgres/index.xml" rel="self" type="application/rss+xml" />

    <item>
      <title>Map R objects to PostgreSQL - a premature ORM draft for R and PG</title>
      <link>http://whatsgood.io/post/idea-for-a-basic-R-Postgres-ORM/</link>
      <pubDate>Tue, 19 Dec 2017 11:11:05 +0100</pubDate>

      <guid>http://whatsgood.io/post/idea-for-a-basic-R-Postgres-ORM/</guid>
      <description>
Lately some of the rstats developer community&rsquo;s heavyweights have been busy to get  RPostgres, a DBI compliant R - PostgreSQL interface, to CRAN ready status. This remarkable effort and resulting github bustle, has motivated me as a long time R and PostgreSQL user to scratch some of my own much simpler, DB related itches: How about transforming R objects to PostgreSQL relations generically?

How about some kind of Object Relational Mapping for R objects? Yep, I know the database should lead the way, not some quirky non-type safe language. But, &hellip; maybe ORM is just too be big (or too exploited) of a word. Let&rsquo;s say: How about some SQL code generator written in R. Why?

Assume you have a data.frame (or data_frame as @Hadley would say.).
Assume you decide to store it somewhere more persistent than in memory.
Assume you want to share it with others, some of whom are not R users.
Assume you want build a REST based web interface to access to the data.

You&rsquo;d still tweak the data.frame before making it create tables.
Wouldn&rsquo;t it be great to magically have a create table statement like so:

library(dplyr)
create_table_sql &lt;- function(df,
                         tbl_name,
                         schema,
                         pk = NULL){
  # some examples mapping, of course we could
  # add more types here
  sql_dplyr_map &lt;- data_frame(
    dplyr_type = c(&quot;chr&quot;,&quot;int&quot;,&quot;lgl&quot;,&quot;list&quot;),
    pg_type = c(&quot;text&quot;,&quot;integer&quot;,&quot;boolean&quot;,&quot;json&quot;)
  )
  type_v &lt;- df %&gt;%
    lapply(type_sum)

  type_df &lt;- data_frame(col_names = names(type_v),
                        dplyr_type = unlist(type_v)) %&gt;%
    inner_join(sql_dplyr_map)

  cols &lt;- paste(type_df$col_names,
                type_df$pg_type,
                collapse=&quot;, &quot;)

  if(is.null(pk)) pk &lt;- type_df$col_names[1]

  sql &lt;- sprintf(&quot;CREATE TABLE %s.%s (%s,
                 PRIMARY KEY (%s));&quot;,
                 schema, tbl_name, cols,
                 pk)
  sql
}

And then simply call it like this to obtain the sql statement to be passed to the database?

create_table_sql(starwars,&quot;starwars&quot;,&quot;movies&quot;)

Personally I&rsquo;ve been using a less general, time series specific mapping
for quite some time. Over time I&rsquo;ve improved performance and r/w processes
got more complex than just SELECT or INSERT. UPSERT kind of operations as well as &lsquo;\copy&rsquo; can do much more but require much more coding. So maybe, just maybe I could extend the above idea to a function factory creating
statements for bulk INSERT and/or UPSERT. Hmmm&hellip; what do you think?

</description>
    </item>

  </channel>
</rss>


text:
namespace OpenTTD.SaveManager.DATA.Model
{
    public class DroppedFile
    {
        public string Name { get; set; }
        public string LocalPath { get; set; }
    }
}


text:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using JSIL.Ast;
using JSIL.Internal;
using Mono.Cecil;

namespace JSIL.Transforms {
    class OptimizePropertyMutationAssignments : JSAstVisitor {
        public readonly TypeSystem TypeSystem;
        public readonly ITypeInfoSource TypeInfo;

        public OptimizePropertyMutationAssignments (TypeSystem typeSystem, ITypeInfoSource typeInfo) {
            TypeSystem = typeSystem;
            TypeInfo = typeInfo;
        }

        public bool IsPropertyAccess (
            JSBinaryOperatorExpression boe, out JSPropertyAccess pa
        ) {
            pa = boe.Left as JSPropertyAccess;
            return pa != null;
        }

        public void VisitNode (JSBinaryOperatorExpression boe) {
            JSPropertyAccess pa;
            JSAssignmentOperator assignmentOperator;
            JSBinaryOperator newOperator;

            if (
                IsPropertyAccess(boe, out pa) &&
                ((assignmentOperator = boe.Operator as JSAssignmentOperator) != null) &&
                IntroduceEnumCasts.ReverseCompoundAssignments.TryGetValue(assignmentOperator, out newOperator)
            ) {
                // FIXME: Terrible hack
                var type = pa.GetActualType(TypeSystem);
                var tempVariable = TemporaryVariable.ForFunction(
                    Stack.Last() as JSFunctionExpression, type
                );
                var replacement = new JSCommaExpression(
                    new JSBinaryOperatorExpression(
                        JSOperator.Assignment, tempVariable,
                        new JSBinaryOperatorExpression(
                            newOperator,
                            new JSPropertyAccess(
                                pa.ThisReference, pa.Property, false,
                                pa.TypeQualified,
                                pa.OriginalType, pa.OriginalMethod,
                                pa.IsVirtualCall
                            ),
                            boe.Right, boe.GetActualType(TypeSystem)
                        ), type
                    ),
                    new JSBinaryOperatorExpression(
                        JSOperator.Assignment,
                        new JSPropertyAccess(
                            pa.ThisReference, pa.Property, true,
                            pa.TypeQualified,
                            pa.OriginalType, pa.OriginalMethod,
                            pa.IsVirtualCall
                        ), tempVariable, type
                    ),
                    tempVariable
                );

                ParentNode.ReplaceChild(boe, replacement);
                VisitReplacement(replacement);
            } else {
                VisitChildren(boe);
            }
        }
    }
}


text:
package org.cloudfoundry.client.v2.spaces;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.immutables.value.Value;

/**
 * The request payload for the Associate Developer with the Space operation
 */
@Value.Immutable
abstract class _AssociateSpaceDeveloperRequest {

    /**
     * The developer id
     */
    @JsonIgnore
    abstract String getDeveloperId();

    /**
     * The space id
     */
    @JsonIgnore
    abstract String getSpaceId();

}


text:
ACCEPTED

#### According to
Index Fungorum

#### Published in
null

#### Original name
Agaricus mundulus Lasch, 1829

### Remarks
null


text:
module CustomerInfosHelper
end


text:
var expect = require('chai').expect;
var path = require('path');
var fs = require('fs');
var _ = require('lodash');
var engineFactory = require('../temply-core');

describe('A plugin', function() {

  var readFileOptions = {
    encoding: 'utf8',
    flag: 'r'
  }

  describe('of type data', function() {

    it('should take a callback and call it', function(done) {
      var plugin = require('./plugins/proto/cms-data-plugin');
      plugin(null, null, function() {
        done();
      });
    });

    it('should take no data and a callback and call it passing some data', function(done) {
      var plugin = require('./plugins/proto/cms-data-plugin');
      plugin(null, null, function(data) {
        expect(data).to.be.ok;
        done();
      });
    });

    it('should take some data and pass it to the callback', function(done) {
      var plugin = require('./plugins/proto/cms-data-plugin');
      var pluginData = [];
      plugin(pluginData, null, function(data) {
        expect(data).to.equal(pluginData);
        done();
      });
    });

    it('should chain two plugin calls adding two item to data array', function(done) {
      var plugin = require('./plugins/proto/cms-data-plugin');
      plugin([], null, function(data) {
        plugin(data, null, function(data) {
          expect(data).to.have.length(2);
          done();
        });
      });
    });

  });

  describe('of type render', function() {
    // TODO
  });

});


text:
#ifndef SVGLayoutSupport_h
#define SVGLayoutSupport_h

#include "core/layout/LayoutObject.h"
#include "core/style/SVGComputedStyleDefs.h"
#include "platform/graphics/DashArray.h"
#include "platform/transforms/AffineTransform.h"
#include "wtf/Allocator.h"

namespace blink {

class AffineTransform;
class FloatPoint;
class FloatRect;
class PaintInvalidationState;
class LayoutRect;
class LayoutGeometryMap;
class LayoutBoxModelObject;
class LayoutObject;
class ComputedStyle;
class LayoutSVGRoot;
class SVGLengthContext;
class StrokeData;
class TransformState;

class CORE_EXPORT SVGLayoutSupport {
  STATIC_ONLY(SVGLayoutSupport);

 public:
  // Shares child layouting code between
  // LayoutSVGRoot/LayoutSVG(Hidden)Container
  static void layoutChildren(LayoutObject*,
                             bool forceLayout,
                             bool screenScalingFactorChanged,
                             bool layoutSizeChanged);

  // Layout resources used by this node.
  static void layoutResourcesIfNeeded(const LayoutObject*);

  // Helper function determining whether overflow is hidden.
  static bool isOverflowHidden(const LayoutObject*);

  // Calculates the paintInvalidationRect in combination with filter, clipper
  // and masker in local coordinates.
  static void intersectPaintInvalidationRectWithResources(const LayoutObject*,
                                                          FloatRect&);

  // Determine if the LayoutObject references a filter resource object.
  static bool hasFilterResource(const LayoutObject&);

  // Determines whether the passed point lies in a clipping area
  static bool pointInClippingArea(const LayoutObject&, const FloatPoint&);

  // Transform |pointInParent| to |object|'s user-space and check if it is
  // within the clipping area. Returns false if the transform is singular or
  // the point is outside the clipping area.
  static bool transformToUserSpaceAndCheckClipping(
      const LayoutObject&,
      const AffineTransform& localTransform,
      const FloatPoint& pointInParent,
      FloatPoint& localPoint);

  static void computeContainerBoundingBoxes(
      const LayoutObject* container,
      FloatRect& objectBoundingBox,
      bool& objectBoundingBoxValid,
      FloatRect& strokeBoundingBox,
      FloatRect& paintInvalidationBoundingBox);

  // Important functions used by nearly all SVG layoutObjects centralizing
  // coordinate transformations / paint invalidation rect calculations
  static FloatRect localOverflowRectForPaintInvalidation(const LayoutObject&);
  static LayoutRect clippedOverflowRectForPaintInvalidation(
      const LayoutObject&,
      const LayoutBoxModelObject& paintInvalidationContainer);
  static LayoutRect transformPaintInvalidationRect(const LayoutObject&,
                                                   const AffineTransform&,
                                                   const FloatRect&);
  static bool mapToVisualRectInAncestorSpace(
      const LayoutObject&,
      const LayoutBoxModelObject* ancestor,
      const FloatRect& localPaintInvalidationRect,
      LayoutRect& resultRect,
      VisualRectFlags = DefaultVisualRectFlags);
  static void mapLocalToAncestor(const LayoutObject*,
                                 const LayoutBoxModelObject* ancestor,
                                 TransformState&,
                                 MapCoordinatesFlags);
  static void mapAncestorToLocal(const LayoutObject&,
                                 const LayoutBoxModelObject* ancestor,
                                 TransformState&);
  static const LayoutObject* pushMappingToContainer(
      const LayoutObject*,
      const LayoutBoxModelObject* ancestorToStopAt,
      LayoutGeometryMap&);

  // Shared between SVG layoutObjects and resources.
  static void applyStrokeStyleToStrokeData(StrokeData&,
                                           const ComputedStyle&,
                                           const LayoutObject&,
                                           float dashScaleFactor);

  static DashArray resolveSVGDashArray(const SVGDashArray&,
                                       const ComputedStyle&,
                                       const SVGLengthContext&);

  // Determines if any ancestor has adjusted the scale factor.
  static bool screenScaleFactorChanged(const LayoutObject*);

  // Determines if any ancestor's layout size has changed.
  static bool layoutSizeOfNearestViewportChanged(const LayoutObject*);

  // FIXME: These methods do not belong here.
  static const LayoutSVGRoot* findTreeRootObject(const LayoutObject*);

  // Helper method for determining if a LayoutObject marked as text (isText()==
  // true) can/will be laid out as part of a <text>.
  static bool isLayoutableTextNode(const LayoutObject*);

  // Determines whether a svg node should isolate or not based on ComputedStyle.
  static bool willIsolateBlendingDescendantsForStyle(const ComputedStyle&);
  static bool willIsolateBlendingDescendantsForObject(const LayoutObject*);
  template <typename LayoutObjectType>
  static bool computeHasNonIsolatedBlendingDescendants(const LayoutObjectType*);
  static bool isIsolationRequired(const LayoutObject*);

  static AffineTransform deprecatedCalculateTransformToLayer(
      const LayoutObject*);
  static float calculateScreenFontSizeScalingFactor(const LayoutObject*);

  static LayoutObject* findClosestLayoutSVGText(LayoutObject*,
                                                const FloatPoint&);

 private:
  static void updateObjectBoundingBox(FloatRect& objectBoundingBox,
                                      bool& objectBoundingBoxValid,
                                      LayoutObject* other,
                                      FloatRect otherBoundingBox);
};

class SubtreeContentTransformScope {
  STACK_ALLOCATED();

 public:
  SubtreeContentTransformScope(const AffineTransform&);
  ~SubtreeContentTransformScope();

  static AffineTransform currentContentTransformation() {
    return AffineTransform(s_currentContentTransformation);
  }

 private:
  static AffineTransform::Transform s_currentContentTransformation;
  AffineTransform m_savedContentTransformation;
};

// The following enumeration is used to optimize cases where the scale is known
// to be invariant (see: LayoutSVGContainer::layout and LayoutSVGroot). The
// value 'Full' can be used in the general case when the scale change is
// unknown, or known to change.
enum class SVGTransformChange {
  None,
  ScaleInvariant,
  Full,
};

// Helper for computing ("classifying") a change to a transform using the
// categoies defined above.
class SVGTransformChangeDetector {
  STACK_ALLOCATED();

 public:
  explicit SVGTransformChangeDetector(const AffineTransform& previous)
      : m_previousTransform(previous) {}

  SVGTransformChange computeChange(const AffineTransform& current) {
    if (m_previousTransform == current)
      return SVGTransformChange::None;
    if (scaleReference(m_previousTransform) == scaleReference(current))
      return SVGTransformChange::ScaleInvariant;
    return SVGTransformChange::Full;
  }

 private:
  static std::pair<double, double> scaleReference(
      const AffineTransform& transform) {
    return std::make_pair(transform.xScaleSquared(), transform.yScaleSquared());
  }
  AffineTransform m_previousTransform;
};

template <typename LayoutObjectType>
bool SVGLayoutSupport::computeHasNonIsolatedBlendingDescendants(
    const LayoutObjectType* object) {
  for (LayoutObject* child = object->firstChild(); child;
       child = child->nextSibling()) {
    if (child->isBlendingAllowed() && child->style()->hasBlendMode())
      return true;
    if (child->hasNonIsolatedBlendingDescendants() &&
        !willIsolateBlendingDescendantsForObject(child))
      return true;
  }
  return false;
}

}  // namespace blink

#endif  // SVGLayoutSupport_h


text:
package net.i2p.sam;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Properties;
import java.util.StringTokenizer;

import net.i2p.util.Log;

public class TestDatagramTransfer {
    private static Log _log = new Log(TestCreateSessionDatagram.class);

    private static void runTest(String samHost, int samPort, String conOptions) {
        testTransfer(samHost, samPort, conOptions);
    }

    private static void testTransfer(String host, int port, String conOptions) {
        String destName = "TRANSIENT";
        _log.info("\n\nTesting creating a new destination (should come back with 'SESSION STATUS RESULT=OK DESTINATION=someName)\n\n\n");
        try {
            Socket s = new Socket(host, port);
            OutputStream out = s.getOutputStream();
            out.write("HELLO VERSION MIN=1.0 MAX=1.0\n".getBytes());
            BufferedReader reader = new BufferedReader(new InputStreamReader(s.getInputStream()));
            String line = reader.readLine();
            _log.debug("line read for valid version: " + line);
            String req = "SESSION CREATE STYLE=DATAGRAM DESTINATION=" + destName + " " + conOptions + "\n";
            out.write(req.getBytes());
            line = reader.readLine();
            _log.info("Response to creating the session with destination " + destName + ": " + line);
            _log.debug("The above should contain SESSION STATUS RESULT=OK\n\n\n");
            String lookup = "NAMING LOOKUP NAME=ME\n";
            out.write(lookup.getBytes());
            line = reader.readLine();
            _log.info("Response from the lookup for ME: " + line);
            _log.debug("The above should be a NAMING REPLY");

            StringTokenizer tok = new StringTokenizer(line);
            String maj = tok.nextToken();
            String min = tok.nextToken();
            Properties props = SAMUtils.parseParams(tok);
            String value = props.getProperty("VALUE");
            if (value == null) {
                _log.error("No value for ME found!  [" + line + "]");
                return;
            } else {
                _log.info("Alice is located at " + value);
            }

            String send = "DATAGRAM SEND DESTINATION=" + value + " SIZE=3\nYo!";
            out.write(send.getBytes());
            line = reader.readLine();
            tok = new StringTokenizer(line);
            maj = tok.nextToken();
            min = tok.nextToken();
            props = SAMUtils.parseParams(tok);
            String size = props.getProperty("SIZE");
            String from = props.getProperty("DESTINATION");
            if ( (value == null) || (size == null) ||
                 (!from.equals(value)) || (!size.equals("3")) ) {
                _log.error("Reply of the datagram is incorrect: [" + line + "]");
                return;
            }

            char buf[] = new char[3];
            int read = reader.read(buf);
            if (read != 3) {
                _log.error("Unable to read the full datagram");
                return;
            }
            if (new String(buf).equals("Yo!")) {
                _log.info("Received payload successfully");
            } else {
                _log.error("Payload is incorrect!  [" + new String(buf) + "]");
            }

            try { Thread.sleep(5*1000); } catch (InterruptedException ie) {}
            s.close();
        } catch (Exception e) {
            _log.error("Error testing for valid version", e);
        }
    }

    public static void main(String args[]) {
        // "i2cp.tcp.host=www.i2p.net i2cp.tcp.port=7765";
        // "i2cp.tcp.host=localhost i2cp.tcp.port=7654 tunnels.inboundDepth=0";
        String conOptions = "i2cp.tcp.host=localhost i2cp.tcp.port=7654 tunnels.inboundDepth=0"; // "i2cp.tcp.host=dev.i2p.net i2cp.tcp.port=7002 tunnels.inboundDepth=0";
        if (args.length > 0) {
            conOptions = "";
            for (int i = 0; i < args.length; i++)
                conOptions = conOptions + " " + args[i];
        }
        try {
            TestUtil.startupBridge(6000);
            runTest("localhost", 6000, conOptions);
        } catch (Throwable t) {
            _log.error("Error running test", t);
        }
        try { Thread.sleep(5*1000); } catch (InterruptedException ie) {}
        System.exit(0);
    }
}


text:
import unittest
from sqlalchemy import *
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker

Base = declarative_base()
engine = create_engine('mysql://root:keen@localhost/logsss')

class DB():
    session = sessionmaker(bind=engine)()

class M_Logsss(Base):
    __tablename__ = 'logsss'
    id = Column(Integer, primary_key = True)
    id_code = Column(String(50), nullable = False)
    update_at = Column(DateTime(), nullable = False)
    create_at = Column(DateTime(), nullable = False)
    tags = Column(String(100), nullable = True)
    status = Column(Integer, nullable = False)
    content = Column(Text)

def init_db():
    Base.metadata.create_all(engine)

if __name__ == '__main__':
    init_db()


text:
FOUNDATION_EXPORT double RxTestVersionNumber;
FOUNDATION_EXPORT const unsigned char RxTestVersionString[];