@@ -182,8 +182,12 @@ static switch_status_t process_originate_message(mosquitto_mosq_userdata_t *user
182182 aleg = argv [1 ];
183183 bleg = argv [2 ];
184184
185- //status = switch_ivr_originate(session, NULL, &cause, NULL, timeout, NULL, cid_name, cid_number, NULL, originate_vars, SOF_NONE, NULL);
186- status = switch_ivr_originate (NULL , & session , & cause , aleg , timeout , NULL , NULL , NULL , NULL , originate_vars , SOF_NONE , NULL , NULL );
185+ #if SWITCH_API_VERSION < 5
186+ status = switch_ivr_originate (session , NULL , & cause , NULL , timeout , NULL , cid_name , cid_number , NULL , originate_vars , SOF_NONE , NULL );
187+ #else
188+ status = switch_ivr_originate (NULL , & session , & cause , aleg , timeout , NULL , NULL , NULL , NULL , originate_vars , SOF_NONE , NULL , NULL );
189+ #endif
190+
187191 if (status != SWITCH_STATUS_SUCCESS || !session ) {
188192 log (SWITCH_LOG_WARNING , "Originate to [%s] failed, cause: %s\n" , aleg , switch_channel_cause2str (cause ));
189193 return status ;
@@ -586,20 +590,23 @@ switch_status_t mosq_int_option(mosquitto_connection_t *connection)
586590{
587591 switch_status_t status = SWITCH_STATUS_SUCCESS ;
588592 int rc ;
593+ int protocol_version = MQTT_PROTOCOL_V31 ;
589594
590- /*
591595 if (!strncasecmp (connection -> protocol_version , "V311" , 4 )) {
592596 protocol_version = MQTT_PROTOCOL_V311 ;
593597 }
594- */
595598
596599 /*
597600 * mosq A valid mosquitto instance.
598601 * option The option to set.
599602 * value The option specific value.
600603 */
601- rc = mosquitto_int_option (connection -> mosq , MOSQ_OPT_PROTOCOL_VERSION , MQTT_PROTOCOL_V311 );
602- log (SWITCH_LOG_DEBUG , "mosquitto_init_option() for Profile %s connection %s protocol version %s rc %d\n" , connection -> profile_name , connection -> name , connection -> protocol_version , rc );
604+ #if LIBMOSQUITTO_VERSION_NUMBER < 1006008
605+ rc = mosquitto_opts_set (connection -> mosq , MOSQ_OPT_PROTOCOL_VERSION , & protocol_version );
606+ #else
607+ rc = mosquitto_int_option (connection -> mosq , MOSQ_OPT_PROTOCOL_VERSION , protocol_version );
608+ #endif
609+ log (SWITCH_LOG_DEBUG , "Options set for Profile %s connection %s protocol version %s rc %d\n" , connection -> profile_name , connection -> name , connection -> protocol_version , rc );
603610
604611 /*
605612 rc = mosquitto_init_option(connection->mosq, MOSQ_OPT_RECEIVE_MAXIMUM, connection->receive_maximum);
@@ -1239,18 +1246,12 @@ switch_status_t mosq_new(mosquitto_profile_t *profile, mosquitto_connection_t *c
12391246 return SWITCH_STATUS_SUCCESS ;
12401247 }
12411248
1242- /*
12431249 if (!(userdata = (mosquitto_mosq_userdata_t * )switch_core_alloc (profile -> pool , sizeof (mosquitto_mosq_userdata_t )))) {
12441250 log (SWITCH_LOG_CRIT , "mosq_new() Failed to allocate memory for mosquitto_new() userdata structure profile %s connection %s\n" , profile -> name , connection -> name );
12451251 return SWITCH_STATUS_GENERR ;
1246- } else {
1247- connection->userdata = userdata;
1248- userdata->profile = profile;
1249- userdata->connection = connection;
12501252 }
1251- */
1253+ //switch_malloc(userdata, sizeof(mosquitto_mosq_userdata_t));
12521254
1253- switch_malloc (userdata , sizeof (mosquitto_mosq_userdata_t ));
12541255 connection -> userdata = userdata ;
12551256 userdata -> profile = profile ;
12561257 userdata -> connection = connection ;
@@ -1320,17 +1321,17 @@ switch_status_t mosq_destroy(mosquitto_connection_t *connection)
13201321 return SWITCH_STATUS_GENERR ;
13211322 }
13221323
1323- userdata = mosquitto_userdata (connection -> mosq );
1324- if (!userdata ) {
1325- log (SWITCH_LOG_ERROR , "mosq_destroy() called with NULL userdata pointer\n" );
1326- return SWITCH_STATUS_GENERR ;
1327- }
1328-
1329- profile = (mosquitto_profile_t * )userdata -> profile ;
1330-
1331- log (SWITCH_LOG_DEBUG , "mosq_destroy(): profile %s connection %s\n" , profile -> name , connection -> name );
1324+ #if LIBMOSQUITTO_VERSION_NUMBER >= 1006008
1325+ userdata = mosquitto_userdata (connection -> mosq );
1326+ if (!userdata ) {
1327+ log (SWITCH_LOG_ERROR , "mosq_destroy() called with NULL userdata pointer\n" );
1328+ return SWITCH_STATUS_GENERR ;
1329+ }
1330+ profile = (mosquitto_profile_t * )userdata -> profile ;
1331+ log (SWITCH_LOG_DEBUG , "mosq_destroy(): profile %s connection %s\n" , profile -> name , connection -> name );
1332+ // switch_safe_free(connection->userdata);
1333+ #endif
13321334
1333- switch_safe_free (connection -> userdata );
13341335 mosquitto_destroy (connection -> mosq );
13351336 connection -> mosq = NULL ;
13361337 connection -> connected = SWITCH_FALSE ;
@@ -1427,11 +1428,13 @@ switch_status_t mosq_subscribe(mosquitto_profile_t *profile, mosquitto_subscribe
14271428 topic -> subscribed = SWITCH_FALSE ;
14281429 return SWITCH_STATUS_GENERR ;
14291430 break ;
1431+ #if LIBMOSQUITTO_VERSION_NUMBER >= 1006008
14301432 case MOSQ_ERR_OVERSIZE_PACKET :
14311433 log (SWITCH_LOG_ERROR , "Profile %s subscriber %s connection %s topic %s pattern %s the pattern larger than the MQTT broker can support\n" , profile -> name , subscriber -> name , connection -> name , topic -> name , topic -> pattern );
14321434 topic -> subscribed = SWITCH_FALSE ;
14331435 return SWITCH_STATUS_GENERR ;
14341436 break ;
1437+ #endif
14351438 }
14361439
14371440 return status ;
0 commit comments