// NewUNIXDomainSocketServer instantiates a new POSIX domain soecket server
// instance.
//
// No resources are actually created until methods are called on the returned
// server.
481717
func NewUNIXDomainSocketServer(ctx context.Context, path string) (StreamServer, error) {
	switch l := len(path); {
	case l == 0:
		return nil, errors.New("cannot have empty path")
	case l > maxPOSIXNamedSocketLength:
		return nil, errors.Reason("path exceeds maximum length %d", maxPOSIXNamedSocketLength).
			InternalReason("path(%s)", path).Err()
	}

	abs, err := filepath.Abs(path)
	if err != nil {
		return nil, errors.Annotate(err, "could not get absolute path of [%s]", path).Err()
	}
	path = abs

	ctx = log.SetField(ctx, "namedPipePath", path)
	return &listenerStreamServer{
		Context: ctx,
		gen: func() (net.Listener, string, error) {
			log.Infof(ctx, "Creating POSIX server socket Listener.")

			// Cleanup any previous named pipe. We don't bother checking for the file
			// first since the remove is atomic. We also ignore any error here, since
			// it's probably related to the file not being found.
			//
			// If there was an actual error removing the file, we'll catch it shortly
			// when we try to create it.
			os.Remove(path)

			// Create a UNIX listener
			l, err := net.Listen("unix", path)
			if err != nil {
				return nil, "", err
			}

			addr := "unix:" + path
			ul := selfCleaningUNIXListener{
				Context:  ctx,
				Listener: l,
				path:     path,
			}
			return &ul, addr, nil
		},
	}, nil
}
282182
func (r Dns_Domain_Registration) AddNameserversToDomain(nameservers []string) (resp bool, err error) {
	params := []interface{}{
		nameservers,
	}
	err = r.Session.DoRequest("SoftLayer_Dns_Domain_Registration", "addNameserversToDomain", params, &r.Options, &resp)
	return
}
196686
func newLogDogStreamServerForPlatform(ctx context.Context, workDir string) (streamserver.StreamServer, error) {
	// POSIX, use UNIX domain socket.
	return streamserver.NewUNIXDomainSocketServer(ctx, filepath.Join(workDir, "ld.sock"))
}
342807
func NewTServerSocketFromAddrTimeout(addr net.Addr, clientTimeout time.Duration) *TServerSocket {
	return &TServerSocket{addr: addr, clientTimeout: clientTimeout}
}
55275
func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
	if config == nil {
		return nil, errors.New("digitalocean: the configuration of the DNS provider is nil")
	}

	if config.AuthToken == "" {
		return nil, fmt.Errorf("digitalocean: credentials missing")
	}

	if config.BaseURL == "" {
		config.BaseURL = defaultBaseURL
	}

	return &DNSProvider{
		config:    config,
		recordIDs: make(map[string]int),
	}, nil
}
470964
func DialUnixFn(addr string) SocketDialer {
	return func() (net.Conn, error) {
		unixAddr := &net.UnixAddr{Name: addr, Net: "unix"}
		return net.DialUnix("unix", nil, unixAddr)
	}
}
398135
func NewRepSocket() (*RepSocket, error) {
	s, err := NewSocket(AF_SP, REP)
	return &RepSocket{s}, err
}
110615
func NewPubSocket() (*PubSocket, error) {
	s, err := NewSocket(AF_SP, PUB)
	return &PubSocket{s}, err
}
51802
func NewWebSocketServer(listener net.Listener) *WebSocketServer {
	// create server
	ws := &WebSocketServer{
		listener: listener,
		upgrader: &websocket.Upgrader{
			HandshakeTimeout: 60 * time.Second,
			Subprotocols:     []string{"mqtt", "mqttv3.1"},
		},
		incoming: make(chan *WebSocketConn),
	}

	// add check origin method that uses the optional check origin function
	ws.upgrader.CheckOrigin = func(r *http.Request) bool {
		if ws.originChecker != nil {
			return ws.originChecker(r)
		}

		return true
	}

	// create http server
	h := &http.Server{
		Handler: http.HandlerFunc(ws.requestHandler),
	}

	// serve http traffic in background
	ws.tomb.Go(func() error {
		return h.Serve(ws.listener)
	})

	return ws
}
208401
func NewServer(kind, name, addr, namespace string) *services.ServerV2 {
	return &services.ServerV2{
		Kind:    kind,
		Version: services.V2,
		Metadata: services.Metadata{
			Name:      name,
			Namespace: namespace,
		},
		Spec: services.ServerSpecV2{
			Addr:       addr,
			PublicAddr: addr,
		},
	}
}
772296
func New(clientKey, secret, callbackURL string, scopes ...string) *Provider {
	domain := os.Getenv(domainEnvKey)
	if domain == "" {
		domain = defaultDomain
	}
	tokenURL := fmt.Sprintf("https://%s%s", domain, tokenPath)
	authURL := fmt.Sprintf("https://%s%s", domain, authPath)
	userAPIEndpoint := fmt.Sprintf("https://%s%s", domain, userAPIPath)

	return NewCustomisedURL(clientKey, secret, callbackURL, authURL, tokenURL, userAPIEndpoint, scopes...)
}
1053798
func NewUnixClient(addr string) *Client {
	return &Client{
		Addr: addr,
		Dial: unixDial,

		// There is little sense in compressing rpc data passed
		// over local unix sockets.
		DisableCompression: true,

		// Sacrifice the number of Write() calls to the smallest
		// possible latency, since it has higher priority in local IPC.
		FlushDelay: -1,
	}
}
832648
func NewDomain(p domainParams) (Domain, error) {
	if err := p.ValidateDomainParams(); err != nil {
		return Domain{}, errors.Trace(err)
	}

	d := Domain{
		Type:          "kvm",
		Name:          p.Host(),
		VCPU:          p.CPUs(),
		CurrentMemory: Memory{Unit: "MiB", Text: p.RAM()},
		Memory:        Memory{Unit: "MiB", Text: p.RAM()},
		OS:            generateOSElement(p),
		Features:      generateFeaturesElement(p),
		CPU:           generateCPU(p),
		Disk:          []Disk{},
		Interface:     []Interface{},
		Serial: Serial{
			Type: "pty",
			Source: SerialSource{
				Path: "/dev/pts/2",
			},
			Target: SerialTarget{
				Port: 0,
			},
		},
		Console: []Console{
			{
				Type: "pty",
				TTY:  "/dev/pts/2",
				Target: ConsoleTarget{
					Port: 0,
				},
				Source: ConsoleSource{
					Path: "/dev/pts/2",
				},
			},
		},
	}
	for i, diskInfo := range p.DiskInfo() {
		devID, err := deviceID(i)
		if err != nil {
			return Domain{}, errors.Trace(err)
		}
		switch diskInfo.Driver() {
		case "raw":
			d.Disk = append(d.Disk, Disk{
				Device: "disk",
				Type:   "file",
				Driver: DiskDriver{Type: diskInfo.Driver(), Name: "qemu"},
				Source: DiskSource{File: diskInfo.Source()},
				Target: DiskTarget{Dev: devID},
			})
		case "qcow2":
			d.Disk = append(d.Disk, Disk{
				Device: "disk",
				Type:   "file",
				Driver: DiskDriver{Type: diskInfo.Driver(), Name: "qemu"},
				Source: DiskSource{File: diskInfo.Source()},
				Target: DiskTarget{Dev: devID},
			})
		default:
			return Domain{}, errors.Errorf(
				"unsupported disk type %q", diskInfo.Driver())
		}
	}
	for _, iface := range p.NetworkInfo() {
		d.Interface = append(d.Interface, Interface{
			Type:   "bridge",
			MAC:    InterfaceMAC{Address: iface.MACAddress()},
			Model:  Model{Type: "virtio"},
			Source: InterfaceSource{Bridge: iface.ParentInterfaceName()},
			Guest:  InterfaceGuest{Dev: iface.InterfaceName()},
		})
	}
	return d, nil
}
469998
func NewWebsocket(config Config, conn *websocket.Conn) *Websocket {
	return makeWebsocket(config, makeChain(config.Reporter), conn)
}
479248
func (g *rfc4122Generator) NewV2(domain byte) (UUID, error) {
	u, err := g.NewV1()
	if err != nil {
		return Nil, err
	}

	switch domain {
	case DomainPerson:
		binary.BigEndian.PutUint32(u[:], posixUID)
	case DomainGroup:
		binary.BigEndian.PutUint32(u[:], posixGID)
	}

	u[9] = domain

	u.SetVersion(V2)
	u.SetVariant(VariantRFC4122)

	return u, nil
}
1138086
func NewWebSocketService() (service *WebSocketService) {
	service = new(WebSocketService)
	service.InitHTTPService()
	service.contextPool = sync.Pool{
		New: func() interface{} { return new(WebSocketContext) },
	}
	service.FixArguments = websocketFixArguments
	service.CheckOrigin = func(request *http.Request) bool {
		origin := request.Header.Get("origin")
		if origin != "" && origin != "null" {
			if len(service.AccessControlAllowOrigins) == 0 ||
				service.AccessControlAllowOrigins[origin] {
				return true
			}
			return false
		}
		return true
	}
	return
}
1060738
func NewExtensionManagerServer(name string, sockPath string, opts ...ServerOption) (*ExtensionManagerServer, error) {
	// Initialize nested registry maps
	registry := make(map[string](map[string]OsqueryPlugin))
	for reg, _ := range validRegistryNames {
		registry[reg] = make(map[string]OsqueryPlugin)
	}

	manager := &ExtensionManagerServer{
		name:         name,
		sockPath:     sockPath,
		registry:     registry,
		timeout:      defaultTimeout,
		pingInterval: defaultPingInterval,
	}

	for _, opt := range opts {
		opt(manager)
	}

	serverClient, err := NewClient(sockPath, manager.timeout)
	if err != nil {
		return nil, err
	}
	manager.serverClient = serverClient

	return manager, nil
}