Skip to content

Commit 8b864b1

Browse files
InterLinked1gtjoseph
authored andcommitted
callerid: Allow specifying timezone for date/time.
The Caller ID generation routine currently is hardcoded to always use the system time zone. This makes it possible to optionally specify any TZ-format time zone. Resolves: #98 ASTERISK-30330
1 parent 2159ec8 commit 8b864b1

File tree

2 files changed

+77
-13
lines changed

2 files changed

+77
-13
lines changed

include/asterisk/callerid.h

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,26 @@ int callerid_generate(unsigned char *buf, const char *number, const char *name,
129129
int callerid_full_generate(unsigned char *buf, const char *number, const char *name, const char *ddn, int redirecting,
130130
int flags, int format, int callwaiting, struct ast_format *codec);
131131

132+
/*! \brief Generates a CallerID FSK stream in ulaw format suitable for transmission.
133+
* \param buf Buffer to use. If "buf" is supplied, it will use that buffer instead of allocating its own.
134+
* "buf" must be at least 32000 bytes in size of you want to be sure you don't have an overrun.
135+
* \param number Use NULL for no number or "P" for "private"
136+
* \param name name to be used
137+
* \param ddn Dialable Directory Number (or NULL)
138+
* \param redirecting Redirecting reason
139+
* \param flags passed flags
140+
* \param format Message format
141+
* \param callwaiting callwaiting flag
142+
* \param codec -- either AST_FORMAT_ULAW or AST_FORMAT_ALAW
143+
* \param tz TZ-format time zone to use for date/time (NULL for system default)
144+
* \details
145+
* This function creates a stream of callerid (a callerid spill) data in ulaw format.
146+
* \return It returns the size
147+
* (in bytes) of the data (if it returns a size of 0, there is probably an error)
148+
*/
149+
int callerid_full_tz_generate(unsigned char *buf, const char *number, const char *name, const char *ddn, int redirecting,
150+
int flags, int format, int callwaiting, struct ast_format *codec, const char *tz);
151+
132152
/*! \brief Create a callerID state machine
133153
* \param cid_signalling Type of signalling in use
134154
*
@@ -220,6 +240,24 @@ int ast_callerid_generate(unsigned char *buf, const char *name, const char *numb
220240
int ast_callerid_full_generate(unsigned char *buf, const char *name, const char *number,
221241
const char *ddn, int redirecting, int pres, int qualifier, int format, struct ast_format *codec);
222242

243+
/*! \brief Generate Caller-ID spill from the "callerid" field of asterisk (in e-mail address like format)
244+
* \param buf buffer for output samples. See callerid_generate() for details regarding buffer.
245+
* \param name Caller-ID Name
246+
* \param number Caller-ID Number
247+
* \param ddn Dialable Directory Number (or NULL)
248+
* \param redirecting Redirecting Reason (-1 if N/A)
249+
* \param pres Presentation (0 for default)
250+
* \param qualifier Call Qualifier (0 for no, 1 for yes)
251+
* \param format Message Format
252+
* \param codec Asterisk codec (either AST_FORMAT_ALAW or AST_FORMAT_ULAW)
253+
* \param tz TZ-format time zone name to use for date/time (NULL for system default)
254+
*
255+
* \details
256+
* Like ast_callerid_generate but with additional parameters.
257+
*/
258+
int ast_callerid_full_tz_generate(unsigned char *buf, const char *name, const char *number,
259+
const char *ddn, int redirecting, int pres, int qualifier, int format, struct ast_format *codec, const char *tz);
260+
223261
/*!
224262
* \brief Generate message waiting indicator
225263
* \param buf
@@ -247,6 +285,13 @@ int ast_callerid_callwaiting_generate(unsigned char *buf, const char *name, cons
247285
int ast_callerid_callwaiting_full_generate(unsigned char *buf, const char *name, const char *number,
248286
const char *ddn, int redirecting, int pres, int qualifier, struct ast_format *codec);
249287

288+
/*! \brief Generate Caller-ID spill but in a format suitable for Call Waiting(tm)'s Caller*ID(tm)
289+
* \param tz TZ-format time zone for date/time (NULL for system default)
290+
* \see ast_callerid_generate() for other details
291+
*/
292+
int ast_callerid_callwaiting_full_tz_generate(unsigned char *buf, const char *name, const char *number,
293+
const char *ddn, int redirecting, int pres, int qualifier, struct ast_format *codec, const char *tz);
294+
250295
/*! \brief Destructively parse inbuf into name and location (or number)
251296
* \details
252297
* Parses callerid stream from inbuf and changes into useable form, outputted in name and location.

main/callerid.c

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ void callerid_free(struct callerid_state *cid)
737737
}
738738

739739
static int callerid_genmsg(char *msg, int size, const char *number, const char *name, int flags, int format,
740-
const char *ddn, int redirecting)
740+
const char *ddn, int redirecting, const char *tz)
741741
{
742742
struct timeval now = ast_tvnow();
743743
struct ast_tm tm;
@@ -746,7 +746,7 @@ static int callerid_genmsg(char *msg, int size, const char *number, const char *
746746
int i, x;
747747

748748
/* Get the time */
749-
ast_localtime(&now, &tm, NULL);
749+
ast_localtime(&now, &tm, tz);
750750

751751
ptr = msg;
752752

@@ -850,8 +850,7 @@ static int callerid_genmsg(char *msg, int size, const char *number, const char *
850850
return (ptr - msg);
851851
}
852852

853-
int ast_callerid_vmwi_generate(unsigned char *buf, int active, int type, struct ast_format *codec,
854-
const char* name, const char* number, int flags)
853+
int ast_callerid_vmwi_generate(unsigned char *buf, int active, int type, struct ast_format *codec, const char* name, const char* number, int flags)
855854
{
856855
char msg[256];
857856
int len = 0;
@@ -867,7 +866,7 @@ int ast_callerid_vmwi_generate(unsigned char *buf, int active, int type, struct
867866
msg[0] = 0x82;
868867

869868
/* put date, number info at the right place */
870-
len = callerid_genmsg(msg+2, sizeof(msg)-2, number, name, flags, CID_TYPE_MDMF, "", -1);
869+
len = callerid_genmsg(msg+2, sizeof(msg)-2, number, name, flags, CID_TYPE_MDMF, "", -1, NULL);
871870

872871
/* length of MDMF CLI plus Message Waiting Structure */
873872
msg[1] = len+3;
@@ -945,6 +944,13 @@ int callerid_generate(unsigned char *buf, const char *number, const char *name,
945944

946945
int callerid_full_generate(unsigned char *buf, const char *number, const char *name, const char *ddn, int redirecting,
947946
int flags, int format, int callwaiting, struct ast_format *codec)
947+
{
948+
/* Default time zone is NULL (system time zone) */
949+
return callerid_full_tz_generate(buf, number, name, ddn, redirecting, flags, format, callwaiting, codec, NULL);
950+
}
951+
952+
int callerid_full_tz_generate(unsigned char *buf, const char *number, const char *name, const char *ddn, int redirecting,
953+
int flags, int format, int callwaiting, struct ast_format *codec, const char *tz)
948954
{
949955
int bytes = 0;
950956
int x, sum;
@@ -955,7 +961,7 @@ int callerid_full_generate(unsigned char *buf, const char *number, const char *n
955961
float ci = 0.0;
956962
float scont = 0.0;
957963
char msg[256];
958-
len = callerid_genmsg(msg, sizeof(msg), number, name, flags, format, ddn, redirecting);
964+
len = callerid_genmsg(msg, sizeof(msg), number, name, flags, format, ddn, redirecting, tz);
959965
if (!callwaiting) {
960966
/* Wait a half a second */
961967
for (x = 0; x < 4000; x++)
@@ -1101,11 +1107,11 @@ int ast_callerid_parse(char *input_str, char **name, char **location)
11011107
}
11021108

11031109
static int __ast_callerid_generate(unsigned char *buf, const char *name, const char *number,
1104-
const char *ddn, int redirecting, int pres, int qualifier, int format, int callwaiting, struct ast_format *codec)
1110+
const char *ddn, int redirecting, int pres, int qualifier, int format, int callwaiting, struct ast_format *codec, const char *tz)
11051111
{
11061112
int flags = 0;
11071113

1108-
ast_debug(1, "Caller ID Type %s: Number: %s, Name: %s, Redirecting No: %s, Redirecting Reason: %s, Pres: %s, Qualifier: %s, Format: %s\n",
1114+
ast_debug(1, "Caller ID Type %s: Number: %s, Name: %s, DDN: %s, Redirecting Reason: %s, Pres: %s, Qualifier: %s, Format: %s\n",
11091115
callwaiting ? "II" : "I", number, name, ddn, ast_redirecting_reason_describe(redirecting),
11101116
ast_named_caller_presentation(pres), qualifier ? "LDC" : "None", format == CID_TYPE_MDMF ? "MDMF" : "SDMF");
11111117

@@ -1126,30 +1132,43 @@ static int __ast_callerid_generate(unsigned char *buf, const char *name, const c
11261132
flags |= CID_QUALIFIER;
11271133
}
11281134

1129-
return callerid_full_generate(buf, number, name, ddn, redirecting, flags, format, callwaiting, codec);
1135+
return callerid_full_tz_generate(buf, number, name, ddn, redirecting, flags, format, callwaiting, codec, tz);
11301136
}
11311137

11321138
int ast_callerid_generate(unsigned char *buf, const char *name, const char *number, struct ast_format *codec)
11331139
{
1134-
return __ast_callerid_generate(buf, name, number, "", -1, 0, 0, CID_TYPE_MDMF, 0, codec);
1140+
return __ast_callerid_generate(buf, name, number, "", -1, 0, 0, CID_TYPE_MDMF, 0, codec, NULL);
11351141
}
11361142

11371143
int ast_callerid_callwaiting_generate(unsigned char *buf, const char *name, const char *number, struct ast_format *codec)
11381144
{
1139-
return __ast_callerid_generate(buf, name, number, "", -1, 0, 0, CID_TYPE_MDMF, 1, codec);
1145+
return __ast_callerid_generate(buf, name, number, "", -1, 0, 0, CID_TYPE_MDMF, 1, codec, NULL);
11401146
}
11411147

11421148
int ast_callerid_full_generate(unsigned char *buf, const char *name, const char *number,
11431149
const char *ddn, int redirecting, int pres, int qualifier, int format, struct ast_format *codec)
11441150
{
1145-
return __ast_callerid_generate(buf, name, number, ddn, redirecting, pres, qualifier, format, 0, codec);
1151+
return __ast_callerid_generate(buf, name, number, ddn, redirecting, pres, qualifier, format, 0, codec, NULL);
11461152
}
11471153

11481154
int ast_callerid_callwaiting_full_generate(unsigned char *buf, const char *name, const char *number,
11491155
const char *ddn, int redirecting, int pres, int qualifier, struct ast_format *codec)
11501156
{
11511157
/* Type II Caller ID (CWCID) only uses MDMF, so format isn't an argument */
1152-
return __ast_callerid_generate(buf, name, number, ddn, redirecting, pres, qualifier, CID_TYPE_MDMF, 1, codec);
1158+
return __ast_callerid_generate(buf, name, number, ddn, redirecting, pres, qualifier, CID_TYPE_MDMF, 1, codec, NULL);
1159+
}
1160+
1161+
int ast_callerid_full_tz_generate(unsigned char *buf, const char *name, const char *number,
1162+
const char *ddn, int redirecting, int pres, int qualifier, int format, struct ast_format *codec, const char *tz)
1163+
{
1164+
return __ast_callerid_generate(buf, name, number, ddn, redirecting, pres, qualifier, format, 0, codec, tz);
1165+
}
1166+
1167+
int ast_callerid_callwaiting_full_tz_generate(unsigned char *buf, const char *name, const char *number,
1168+
const char *ddn, int redirecting, int pres, int qualifier, struct ast_format *codec, const char *tz)
1169+
{
1170+
/* Type II Caller ID (CWCID) only uses MDMF, so format isn't an argument */
1171+
return __ast_callerid_generate(buf, name, number, ddn, redirecting, pres, qualifier, CID_TYPE_MDMF, 1, codec, tz);
11531172
}
11541173

11551174
char *ast_callerid_merge(char *buf, int bufsiz, const char *name, const char *num, const char *unknown)

0 commit comments

Comments
 (0)