in source/mqtt_client_connection.c [284:328]
bool s_set_will(struct aws_mqtt_client_connection *connection, PyObject *will) {
assert(will && (will != Py_None));
bool success = false;
/* These references all need to be cleaned up before function returns */
PyObject *py_topic = NULL;
PyObject *py_payload = NULL;
py_topic = PyObject_GetAttrString(will, "topic");
struct aws_byte_cursor topic = aws_byte_cursor_from_pyunicode(py_topic);
if (!topic.ptr) {
PyErr_SetString(PyExc_TypeError, "Will.topic must be str type");
goto done;
}
enum aws_mqtt_qos qos = PyObject_GetAttrAsIntEnum(will, "Will", "qos");
if (PyErr_Occurred()) {
goto done;
}
py_payload = PyObject_GetAttrString(will, "payload");
struct aws_byte_cursor payload = aws_byte_cursor_from_pybytes(py_payload);
if (!payload.ptr) {
PyErr_SetString(PyExc_TypeError, "Will.payload must be bytes type");
goto done;
}
bool retain = PyObject_GetAttrAsBool(will, "Will", "retain");
if (PyErr_Occurred()) {
goto done;
}
if (aws_mqtt_client_connection_set_will(connection, &topic, qos, retain, &payload)) {
PyErr_SetAwsLastError();
goto done;
}
success = true;
done:
Py_XDECREF(py_topic);
Py_XDECREF(py_payload);
return success;
}