Upgrade 3CX to v18 and get it hosted free!

STS Template Engine

Author image

Using the STS Template Engine to generate Asterisk configuration files

The STS Template Engine, developed by Sunrise Telephone Systems is a universal template engine for Cocoa featuring its own macro language for conditional template expansion. Although it can be used for any kind of template expansion requirement, it was developed for the purpose of generating Asterisk configuration files from templates.

The STS Template Engine is released under the GPL version 2 as Objective-C source code for embedding into Cocoa or GNUstep applications.

Overview


Methods provided

  • stringByExpandingTemplate:usingDictionary:errorsReturned:
  • stringByExpandingTemplate:withStartTag:andEndTag:usingDictionary:errorsReturned:
  • stringByExpandingTemplateAtPath:usingDictionary:encoding:errorsReturned:
  • stringByExpandingTemplateAtPath:withStartTag:andEndTag:usingDictionary:encoding:errorsReturned:

Macros supported

%IF, %IFNOT, %IFEQ, %IFNEQ, %IFDEF, %IFNDEF, %ELSIF, %ELSIFNOT, %ELSIFEQ, %ELSIFNEQ, %ELSIFDEF, %ELSIFNDEF, %ELSE, %ENDIF, %DEFINE, %UNDEF, %LOG, %ECHO and %DEBUG.

Predefined Placeholder Variables

_timestamp, _uniqueID, _hostname, _userCountryCode, _userLanguage, _systemCountryCode, _systemLanguage

Example template

%% Configuration template to generate X-Lite SIP profile for Asterisk
%% created 06-JUL-2005 by Sunrise Telephone Systems Ltd.
%% version 1.00
%%
%% The generated configlet must be included in /etc/asterisk/sip.conf
%%
%%
; THIS FILE HAS BEEN AUTOGENERATED % «_timestamp »
; DO NOT EDIT THIS FILE – MODIFICATIONS MAY BE OVERRIDDEN
;
;
[xlite] ; SIP profile for local X-Lite on % «_hostname »
port=5061
host=127.0.0.1
type=friend
qualify=no
reinvite=no
canreinvite=no
disallow=all
%IF allowUlaw
allow=ulaw
%ENDIF
%IF allowAlaw
allow=alaw
%ENDIF
%IF allowGSM
allow=gsm
%ENDIF
%IF allowILBC
allow=ilbc
%ENDIF
context=autocontext
callerid=”% «username »“<% «callerid »>
;
%% END OF TEMPLATE

 

Example code

– (IBAction)createConfiglet:(id)sender {
NSString *configlet;
NSDictionary *userInput;
NSArray *errorLog = [[NSArray alloc] init];

// initialise the dicitionary with the user input
userInput = [NSDictionary dictionaryWithObjectsAndKeys:
[usernameField stringValue], @”username”,
[cidnumberField stringValue], @”callerid”,
[ringtimerField stringValue], @”ringtimer”,
[ulawCheckbox stringValue], @”allowUlaw”,
[alawCheckbox stringValue], @”allowAlaw”,
[gsmCheckbox stringValue], @”allowGSM”,
[ilbcCheckbox stringValue], @”allowILBC”,
nil];

// expand the template to create the configlet
configlet = [NSString stringByExpandingTemplateAtPath:
@”/Library/Application Support/Asterisk/templates/xlite.template”
usingDictionary:userInput
encoding:NSUTF8StringEncoding
errorsReturned:&errorLog];

// etc


See also

Related Posts:

Get 3CX - Absolutely Free!
Link up your team and customers Phone System Live Chat Video Conferencing

Hosted or Self-managed. Up to 10 users free forever. No credit card. Try risk free.

3CX
A 3CX Account with that email already exists. You will be redirected to the Customer Portal to sign in or reset your password if you've forgotten it.