Skip to content

Commit a861ff5

Browse files
authored
Merge branch 'master' into local-no-dialplan
2 parents 6fd6f67 + 3b6f9e5 commit a861ff5

File tree

10 files changed

+224
-24
lines changed

10 files changed

+224
-24
lines changed

apps/app_rpt.c

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,24 +1062,25 @@ static void *perform_statpost(void *data)
10621062
struct ast_str *response_msg;
10631063
struct statpost *sp = (struct statpost *) data;
10641064
struct rpt *myrpt = sp->myrpt;
1065+
char *url = ast_str_buffer(sp->stats_url);
10651066

10661067
if (!curl) {
10671068
ast_free(sp->stats_url);
10681069
ast_free(sp);
10691070
return NULL;
10701071
}
10711072

1072-
response_msg = ast_str_create(50);
1073+
response_msg = ast_str_create(RPT_AST_STR_INIT_SIZE);
10731074
if (!response_msg) {
10741075
ast_free(sp->stats_url);
10751076
ast_free(sp);
10761077
curl_easy_cleanup(curl);
10771078
return NULL;
10781079
}
10791080
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunction);
1080-
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *) &response_msg);
1081+
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response_msg);
10811082
curl_easy_setopt(curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
1082-
curl_easy_setopt(curl, CURLOPT_URL, sp->stats_url);
1083+
curl_easy_setopt(curl, CURLOPT_URL, url);
10831084
curl_easy_setopt(curl, CURLOPT_USERAGENT, AST_CURL_USER_AGENT);
10841085
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, error_buffer);
10851086

@@ -1088,20 +1089,20 @@ static void *perform_statpost(void *data)
10881089
if (*error_buffer) { /* Anything in the error buffer? */
10891090
failed = 1;
10901091
if (!myrpt->last_statpost_failed) {
1091-
ast_log(LOG_WARNING, "statpost to URL '%s' failed with error: %s\n", sp->stats_url, error_buffer);
1092+
ast_log(LOG_WARNING, "statpost to URL '%s' failed with error: %s\n", url, error_buffer);
10921093
}
10931094
} else {
10941095
failed = 1;
10951096
if (!myrpt->last_statpost_failed) {
1096-
ast_log(LOG_WARNING, "statpost to URL '%s' failed with error: %s\n", sp->stats_url, curl_easy_strerror(res));
1097+
ast_log(LOG_WARNING, "statpost to URL '%s' failed with error: %s\n", url, curl_easy_strerror(res));
10971098
}
10981099
}
10991100
} else {
11001101
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &rescode);
11011102
if (!is_http_success(rescode)) {
11021103
failed = 1;
11031104
if (!myrpt->last_statpost_failed) {
1104-
ast_log(LOG_WARNING, "statpost to URL '%s' failed with code %ld: %s\n", sp->stats_url, rescode, http_status_text(rescode));
1105+
ast_log(LOG_WARNING, "statpost to URL '%s' failed with code %ld: %s\n", url, rescode, http_status_text(rescode));
11051106
}
11061107
}
11071108
}
@@ -1115,11 +1116,11 @@ static void *perform_statpost(void *data)
11151116
return NULL;
11161117
}
11171118

1118-
static void statpost(struct rpt *myrpt, char *pairs)
1119+
static void statpost(struct rpt *myrpt, struct ast_str *pairs)
11191120
{
11201121
time_t now;
11211122
unsigned int seq;
1122-
int res, len;
1123+
int res;
11231124
pthread_t statpost_thread;
11241125
struct statpost *sp;
11251126

@@ -1131,17 +1132,19 @@ static void statpost(struct rpt *myrpt, char *pairs)
11311132
return;
11321133
}
11331134

1134-
len = strlen(pairs) + strlen(myrpt->p.statpost_url) + 200;
1135-
sp->stats_url = ast_malloc(len);
1136-
1135+
sp->stats_url = ast_str_create(RPT_AST_STR_INIT_SIZE);
1136+
if (!sp->stats_url) {
1137+
ast_free(sp);
1138+
return;
1139+
}
11371140
ast_mutex_lock(&myrpt->statpost_lock);
11381141
seq = ++myrpt->statpost_seqno;
11391142
ast_mutex_unlock(&myrpt->statpost_lock);
11401143

11411144
time(&now);
11421145
sp->myrpt = myrpt;
1143-
snprintf(sp->stats_url, len, "%s?node=%s&time=%u&seqno=%u%s%s", myrpt->p.statpost_url, myrpt->name, (unsigned int) now, seq,
1144-
pairs ? "&" : "", S_OR(pairs, ""));
1146+
ast_str_set(&sp->stats_url, 0, "%s?node=%s&time=%u&seqno=%u%s", myrpt->p.statpost_url, myrpt->name, (unsigned int) now, seq,
1147+
ast_str_buffer(pairs));
11451148

11461149
/* Make the actual cURL call in a separate thread, so we can continue without blocking. */
11471150
ast_debug(5, "Making statpost to %s\n", sp->stats_url);
@@ -3448,13 +3451,17 @@ static inline void periodic_process_links(struct rpt *myrpt, const int elap)
34483451
*/
34493452
static inline void do_key_post(struct rpt *myrpt)
34503453
{
3451-
char str[100];
3454+
struct ast_str *str = ast_str_create(RPT_AST_STR_INIT_SIZE);
34523455
time_t now;
34533456

3457+
if (!str) {
3458+
return;
3459+
}
34543460
time(&now);
3455-
snprintf(str, sizeof(str), "keyed=%d&keytime=%d", myrpt->keyed, myrpt->lastkeyedtime ? ((int) (now - myrpt->lastkeyedtime)) : 0);
3461+
ast_str_set(&str, 0, "&keyed=%d&keytime=%d", myrpt->keyed, myrpt->lastkeyedtime ? ((int) (now - myrpt->lastkeyedtime)) : 0);
34563462
rpt_mutex_unlock(&myrpt->lock);
34573463
statpost(myrpt, str);
3464+
ast_free(str);
34583465
rpt_mutex_lock(&myrpt->lock);
34593466
}
34603467

@@ -3479,7 +3486,7 @@ static inline int do_link_post(struct rpt *myrpt)
34793486
return -1;
34803487
}
34813488
nstr = 0;
3482-
ast_str_set(&str, 0, "%s", "nodes=");
3489+
ast_str_set(&str, 0, "%s", "&nodes=");
34833490
RPT_LIST_TRAVERSE(myrpt->links, l, l_it) {
34843491
/* if is not a real link, ignore it */
34853492
if (l->name[0] == '0') {
@@ -3507,7 +3514,7 @@ static inline int do_link_post(struct rpt *myrpt)
35073514
(int) myrpt->totaltxtime / 1000, myrpt->timeouts, myrpt->totalexecdcommands, myrpt->keyed,
35083515
myrpt->lastkeyedtime ? ((int) (now - myrpt->lastkeyedtime)) : 0);
35093516
rpt_mutex_unlock(&myrpt->lock);
3510-
statpost(myrpt, ast_str_buffer(str));
3517+
statpost(myrpt, str);
35113518
rpt_mutex_lock(&myrpt->lock);
35123519
ast_free(str);
35133520
return 0;

apps/app_rpt/app_rpt.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1105,7 +1105,7 @@ struct nodelog {
11051105

11061106
struct statpost {
11071107
struct rpt *myrpt;
1108-
char *stats_url;
1108+
struct ast_str *stats_url;
11091109
};
11101110

11111111
/*! \brief Whether a channel is using a specified technology */

channels/chan_simpleusb.c

Lines changed: 76 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ struct chan_simpleusb_pvt {
187187

188188
char devicenum;
189189
char devstr[128];
190+
char serial[128];
190191
int spkrmax;
191192
int micmax;
192193
int micplaymax;
@@ -791,14 +792,17 @@ static int load_tune_config(struct chan_simpleusb_pvt *o, const struct ast_confi
791792
int opened = 0;
792793
int configured = 0;
793794
char devstr[sizeof(o->devstr)];
795+
char serial[sizeof(o->serial)];
794796

795797
o->rxmixerset = 500;
796798
o->txmixaset = 500;
797799
o->txmixbset = 500;
798800

799801
devstr[0] = '\0';
802+
serial[0] = '\0';
800803
if (!reload) {
801-
o->devstr[0] = 0;
804+
o->devstr[0] = '\0';
805+
o->serial[0] = '\0';
802806
}
803807

804808
if (!cfg) {
@@ -819,11 +823,13 @@ static int load_tune_config(struct chan_simpleusb_pvt *o, const struct ast_confi
819823
CV_UINT("txmixaset", o->txmixaset);
820824
CV_UINT("txmixbset", o->txmixbset);
821825
CV_STR("devstr", devstr);
826+
CV_STR("serial", serial);
822827
CV_END;
823828
}
824829
if (!reload) {
825830
/* Using the ternary operator in CV_STR won't work, due to butchering the sizeof, so copy after if needed */
826831
strcpy(o->devstr, devstr); /* Safe */
832+
strcpy(o->serial, serial); /* Safe */
827833
}
828834
if (opened) {
829835
ast_config_destroy(cfg2);
@@ -893,6 +899,8 @@ static void *hidthread(void *arg)
893899
* with the usb hid device
894900
*/
895901
while (!o->stophid) {
902+
char serial[sizeof(o->serial)] = { '\0' };
903+
896904
ast_radio_time(&o->lasthidtime);
897905
ast_mutex_lock(&usb_dev_lock);
898906
o->hasusb = 0;
@@ -913,7 +921,37 @@ static void *hidthread(void *arg)
913921
* found device.
914922
*/
915923
ast_radio_time(&o->lasthidtime);
916-
924+
925+
/* If configuration has a serial number defined, find the device */
926+
if (!ast_strlen_zero(o->serial)) {
927+
int index;
928+
char *index_devstr = NULL;
929+
930+
for (index = 0;; index++) {
931+
index_devstr = ast_radio_usb_get_devstr(index);
932+
if (ast_strlen_zero(index_devstr)) {
933+
/* if no more devices */
934+
break;
935+
}
936+
937+
/* get the device serial number */
938+
if (ast_radio_usb_get_serial(index_devstr, serial, sizeof(serial)) == 0) {
939+
/* if no serial number */
940+
continue;
941+
}
942+
943+
if (strcmp(o->serial, serial) == 0) {
944+
/*
945+
* We found a device with the matching serial number, set
946+
* the devstr to the matching device.
947+
*/
948+
ast_log(LOG_NOTICE, "Matched device serial %s to %s\n", o->serial, o->name);
949+
ast_copy_string(o->devstr, index_devstr, sizeof(o->devstr));
950+
break;
951+
}
952+
}
953+
}
954+
917955
/* Automatically assign a devstr if one was not specified in the configuration. */
918956
if (ast_strlen_zero(o->devstr)) {
919957
int index = 0;
@@ -943,6 +981,9 @@ static void *hidthread(void *arg)
943981
/* We found an unused device assign it to our node */
944982
ast_copy_string(o->devstr, index_devstr, sizeof(o->devstr));
945983
ast_log(LOG_NOTICE, "Channel %s: Automatically assigned USB device %s to SimpleUSB channel\n", o->name, o->devstr);
984+
if (ast_radio_usb_get_serial(index_devstr, serial, sizeof(serial)) > 0) {
985+
ast_copy_string(o->serial, serial, sizeof(o->serial));
986+
}
946987
break;
947988
}
948989
if (ast_strlen_zero(o->devstr)) {
@@ -3118,6 +3159,9 @@ static void _menu_print(int fd, struct chan_simpleusb_pvt *o)
31183159
ast_cli(fd, "Active radio interface is [%s]\n", simpleusb_active);
31193160
ast_mutex_lock(&usb_dev_lock);
31203161
ast_cli(fd, "Device String is %s\n", o->devstr);
3162+
if (!ast_strlen_zero(o->serial)) {
3163+
ast_cli(fd, "Device Serial is %s\n", o->serial);
3164+
}
31213165
ast_mutex_unlock(&usb_dev_lock);
31223166
ast_cli(fd, "Card is %i\n", ast_radio_usb_get_usbdev(o->devstr));
31233167
ast_cli(fd, "Rx Level currently set to %d\n", o->rxmixerset);
@@ -3320,7 +3364,36 @@ static void tune_write(struct chan_simpleusb_pvt *o)
33203364
if (!category) {
33213365
ast_log(LOG_ERROR, "No category '%s' exists?\n", o->name);
33223366
} else {
3323-
CONFIG_UPDATE_STR(devstr);
3367+
/*
3368+
* To simplify channel driver setup we allow the "devstr=" value
3369+
* to be empty/blank indicating that we should match the first
3370+
* available interface.
3371+
*
3372+
* This works (and will continue to work) well as long as the
3373+
* "devstr=" value in the configuration file remains empty/blank.
3374+
* But, if the value is ever provided then we only match interfaces
3375+
* with the specified string. Moving the interface (accidentally
3376+
* or intentionally) to a different "port" will result in not
3377+
* finding/matching the interface.
3378+
*
3379+
* To minimize conflicts, we want to avoid writing out the specific
3380+
* "devstr=" value to the configuration file unless needed. Here,
3381+
* we check if the current "devstr=" value is empty/blank and
3382+
* that there is only a single audio interface connected to the
3383+
* system. If so, we leave the value empty/blank.
3384+
*/
3385+
const char *val;
3386+
char *dev;
3387+
3388+
val = ast_variable_retrieve(cfg, o->name, "devstr");
3389+
dev = ast_radio_usb_get_devstr(1);
3390+
if (!ast_strlen_zero(val) || !ast_strlen_zero(dev)) {
3391+
/* if the "devstr=" value exists or there is more than 1 sound device */
3392+
CONFIG_UPDATE_STR(devstr);
3393+
if (!ast_strlen_zero(o->serial)) {
3394+
CONFIG_UPDATE_STR(serial);
3395+
}
3396+
}
33243397
CONFIG_UPDATE_INT(rxmixerset);
33253398
CONFIG_UPDATE_INT(txmixaset);
33263399
CONFIG_UPDATE_INT(txmixbset);

0 commit comments

Comments
 (0)