diff --git a/src/gofaxd/server.go b/src/gofaxd/server.go index 1fe9f2f..ef23824 100644 --- a/src/gofaxd/server.go +++ b/src/gofaxd/server.go @@ -103,10 +103,29 @@ func (e *EventSocketServer) handler(c *eventsocket.Connection) { logger.Logger.Printf("Incoming call to %v from %v <%v>", recipient, cidname, cidnum) + var device *Device + if gofaxlib.Config.Gofaxd.AllocateOutboundDevices { + // Find free device + device, err := devmanager.FindDevice(fmt.Sprintf("Receiving facsimile")) + if err != nil { + logger.Logger.Println(err) + c.Execute("respond", "404", true) + c.Send("exit") + } + defer device.SetReady() + } + + var used_device string + if device != nil { + used_device = device.Name + } else { + used_device = DEFAULT_DEVICE + } + // Query DynamicConfig if dc_cmd := gofaxlib.Config.Gofaxd.DynamicConfig; dc_cmd != "" { logger.Logger.Println("Calling DynamicConfig script", dc_cmd) - dc, err := gofaxlib.DynamicConfig(dc_cmd, cidnum, cidname, recipient) + dc, err := gofaxlib.DynamicConfig(dc_cmd, used_device, cidnum, cidname, recipient) if err != nil { logger.Logger.Println("Error calling DynamicConfig:", err) } else { @@ -127,18 +146,6 @@ func (e *EventSocketServer) handler(c *eventsocket.Connection) { } - var device *Device - if gofaxlib.Config.Gofaxd.AllocateOutboundDevices { - // Find free device - device, err := devmanager.FindDevice(fmt.Sprintf("Receiving facsimile")) - if err != nil { - logger.Logger.Println(err) - c.Execute("respond", "404", true) - c.Send("exit") - } - defer device.SetReady() - } - sessionlog, err := gofaxlib.NewSessionLogger() if err != nil { c.Send("exit") @@ -235,13 +242,6 @@ EventLoop: } sessionlog.Log(fmt.Sprintf("Success: %v, Hangup Cause: %v, Result: %v", result.Success, result.Hangupcause, result.ResultText)) - var used_device string - if device != nil { - used_device = device.Name - } else { - used_device = DEFAULT_DEVICE - } - xfl := gofaxlib.NewXFRecord(result) xfl.Modem = used_device xfl.Filename = filename diff --git a/src/gofaxlib/dynamicconfig.go b/src/gofaxlib/dynamicconfig.go index 2506fd4..e4b0193 100644 --- a/src/gofaxlib/dynamicconfig.go +++ b/src/gofaxlib/dynamicconfig.go @@ -53,12 +53,12 @@ func (h *HylaConfig) GetFirst(tag string) string { return "" } -func DynamicConfig(command string, cidnum string, cidname string, recipient string) (*HylaConfig, error) { +func DynamicConfig(command string, device string, cidnum string, cidname string, recipient string) (*HylaConfig, error) { if Config.Gofaxd.DynamicConfig == "" { return nil, errors.New("No DynamicConfig command provided") } - cmd := exec.Command(Config.Gofaxd.DynamicConfig, cidnum, cidname, recipient) + cmd := exec.Command(Config.Gofaxd.DynamicConfig, device, cidnum, cidname, recipient) out, err := cmd.Output() if err != nil { return nil, err