#!/usr/local/bin/csi -s (module snom-phone (snom-phone snom-phone-settings set-snom-phone-settings!) (import scheme chicken data-structures utils extras srfi-1 srfi-18 uri-common http-client regex snom-event-server) (define (snom-phone ip-address) (let* ((snom-phone '((ip-address . ,ip-address) (current-settings . ()) (original-settings . ()))) (settings (snom-phone-settings snom-phone))) (set! (alist-ref 'current-settings snom-phone) settings) (set! (alist-ref 'original-settings snom-phone) settings) snom-phone)) (define (snom-phone-settings snom-phone) (with-input-from-request (format "http://~A/settings.cfg" (alist-ref 'ip-address snom-phone)) #f (lambda () (let settings-loop ((current-setting (read-line))) (if (eof-object? current-setting) '() (let ((current-setting (string-split-fields "!:\\s" current-setting #:infix))) (alist-cons (string->symbol (car current-setting)) (cdr current-setting) (settings-loop (read-line))))))))) (define (set-snom-phone-setting! snom-phone setting) (with-input-from-request (format "http://~A/dummy.htm?settings=save~A" (alist-ref 'ip-address snom-phone) (string-append "&" (symbol->string (car setting)) "=" (uri-encode-string (cdr setting))))) (set! (alist-ref 'current-settings snom-phone) (snom-phone-settings snom-phone)) (if (equal? (alist-ref (car setting) (alist-ref 'current-settings snom-phone)) (cdr setting)) #t #f)) (define (set-snom-phone-settings! snom-phone settings) (for-each (lambda (setting) (let set-setting-bug-loop ((current-setting (set-snom-phone-setting! snom-phone setting))) (unless current-setting (thread-sleep! 1) (set-setting-bug-loop (set-snom-phone-setting! snom-phone setting))))) settings)) (define (set-identity-settings! snom-phone identity-index identity-settings) (void)) (define (set-active-identity! snom-phone identity-index) (void)) (define (active-identity snom-phone) (void)) (define (active-identity-settings snom-phone) (void)) (define (active-identity-call-id snom-phone identity-index) (void)) (define (dial from to) (receive-results (lambda () (with-input-from-request (format "http://~A/command.htm?number=~A" (alist-ref 'ip-address from) (active-identity-call-id to (active-identity to))) #f read-all)) '(((type . outgoing) (ip . ,(alist-ref 'ip-address from))) ((type . incomming) (ip . ,(alist-ref 'ip-address to)))))) )