Skip to content

Instantly share code, notes, and snippets.

View philshafer's full-sized avatar

Phil Shafer philshafer

  • Juniper Networks
  • Raleigh NC
View GitHub Profile
I'm wondering if the ntp community would be open to incorporating my libxo into ntp source code.
libxo is a library I wrote for FreeBSD that makes text, HTML, XML, JSON, CSV, CBOR, and other formats using a single code path. It's be added to the base OS for FreeBSD, and allows normal command line utilities to produce these alternative structured output formats (see below). Documentation is available at https://libxo.readthedocs.io/en/latest/ and source code is on GitHub https://github.com/Juniper/libxo
For embedded platforms that want to expose an API (like Juniper Networks' JUNOS software), this is an important feature. JUNOS currently exposes only text output from nap-related commands, but we would like to do better. This would involve making patches for ntp source code that would allow the same code to emit these structured formats.
I'd be signing up for the following work:
- publish linux packages for libxo (which I should be doing anyway)
- create an acceptable patch
@philshafer
philshafer / xo42
Created April 2, 2019 05:02
libxo_text_only patch
diff --git a/libxo/libxo.c b/libxo/libxo.c
index c45ed49..1df5114 100644
--- a/libxo/libxo.c
+++ b/libxo/libxo.c
@@ -258,8 +258,8 @@ struct xo_handle_s {
ssize_t xo_units_offset; /* Start of units insertion point */
ssize_t xo_columns; /* Columns emitted during this xo_emit call */
#ifndef LIBXO_TEXT_ONLY
- uint8_t xo_color_map_fg[XO_NUM_COLORS]; /* Foreground color mappings */
- uint8_t xo_color_map_bg[XO_NUM_COLORS]; /* Background color mappings */
@philshafer
philshafer / huge-string.c
Created April 2, 2019 02:03
huge-string.c
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/sysctl.h>
#include <libxo/xo.h>
#include <stdio.h>
[edit interfaces xe-1/1/1]
phil@dent# set unit 0 disable
[edit interfaces xe-1/1/1]
phil@dent# commit confirmed 2
commit confirmed will be automatically rolled back in 2 minutes unless confirmed
commit complete
# commit confirmed will be rolled back in 2 minutes
[edit interfaces xe-1/1/1]
@philshafer
philshafer / gist:b15f89062759abb24c42
Created September 21, 2015 19:59
apply-macro data
vcpe {
interfaces {
fe-0/2/0 {
unit 1 {
apply-macro vcpe {
customer test;
address 3.3.3.3;
vlan-id 345;
security default;
}
@philshafer
philshafer / gist:32e8b9cd2868e010603b
Created September 21, 2015 19:45
Early config group documentation
The apply-groups statement can be given at any level of the
configuration hierarchy, listing group names in priority
order. Groups listed in nested apply-groups statements take priority
over groups in outer statements:
apply-groups [ eight nine ten ];
protocols {
apply-groups seven;
bgp {
apply-groups [ five six ];