📄 py_pjsua.c
字号:
};
/*
* config_Object
* attribute list for config object
*/
typedef struct
{
PyObject_HEAD
/* Type-specific fields go here. */
unsigned max_calls;
unsigned thread_cnt;
unsigned outbound_proxy_cnt;
pj_str_t outbound_proxy[4];
unsigned cred_count;
pjsip_cred_info cred_info[PJSUA_ACC_MAX_PROXIES];
callback_Object * cb;
PyObject * user_agent;
} config_Object;
/*
* config_dealloc
* deallocates a config object
*/
static void config_dealloc(config_Object* self)
{
Py_XDECREF(self->cb);
Py_XDECREF(self->user_agent);
self->ob_type->tp_free((PyObject*)self);
}
/*
* config_new
* config object constructor
*/
static PyObject *config_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
config_Object *self;
self = (config_Object *)type->tp_alloc(type, 0);
if (self != NULL)
{
self->user_agent = PyString_FromString("");
if (self->user_agent == NULL)
{
Py_DECREF(self);
return NULL;
}
self->cb = (callback_Object *)PyType_GenericNew(
&callback_Type, NULL, NULL
);
if (self->cb == NULL)
{
Py_DECREF(Py_None);
return NULL;
}
}
return (PyObject *)self;
}
/*
* config_members
* attribute list accessible from Python/C
*/
static PyMemberDef config_members[] =
{
{
"max_calls", T_INT, offsetof(config_Object, max_calls), 0,
"Maximum calls to support (default: 4) "
},
{
"thread_cnt", T_INT, offsetof(config_Object, thread_cnt), 0,
"Number of worker threads. Normally application will want to have at "
"least one worker thread, unless when it wants to poll the library "
"periodically, which in this case the worker thread can be set to "
"zero."
},
{
"outbound_proxy_cnt", T_INT,
offsetof(config_Object, outbound_proxy_cnt), 0,
"Number of outbound proxies in the array."
},
{
"cred_count", T_INT, offsetof(config_Object, cred_count), 0,
"Number of credentials in the credential array."
},
{
"user_agent", T_OBJECT_EX, offsetof(config_Object, user_agent), 0,
"User agent string (default empty)"
},
{
"cb", T_OBJECT_EX, offsetof(config_Object, cb), 0,
"Application callback."
},
{NULL} /* Sentinel */
};
/*
* config_Type
* type wrapper for config class
*/
static PyTypeObject config_Type =
{
PyObject_HEAD_INIT(NULL)
0, /*ob_size*/
"py_pjsua.Config", /*tp_name*/
sizeof(config_Object), /*tp_basicsize*/
0, /*tp_itemsize*/
(destructor)config_dealloc,/*tp_dealloc*/
0, /*tp_print*/
0, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_compare*/
0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
0, /*tp_hash */
0, /*tp_call*/
0, /*tp_str*/
0, /*tp_getattro*/
0, /*tp_setattro*/
0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT, /*tp_flags*/
"Config objects", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
0, /* tp_methods */
config_members, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
config_new, /* tp_new */
};
/*
* logging_config_Object
* configuration class for logging_config object
*/
typedef struct
{
PyObject_HEAD
/* Type-specific fields go here. */
int msg_logging;
unsigned level;
unsigned console_level;
unsigned decor;
PyObject * log_filename;
PyObject * cb;
} logging_config_Object;
/*
* logging_config_dealloc
* deletes a logging config from memory
*/
static void logging_config_dealloc(logging_config_Object* self)
{
Py_XDECREF(self->log_filename);
Py_XDECREF(self->cb);
self->ob_type->tp_free((PyObject*)self);
}
/*
* logging_config_new
* constructor for logging_config object
*/
static PyObject * logging_config_new(PyTypeObject *type, PyObject *args,
PyObject *kwds)
{
logging_config_Object *self;
self = (logging_config_Object *)type->tp_alloc(type, 0);
if (self != NULL)
{
self->log_filename = PyString_FromString("");
if (self->log_filename == NULL)
{
Py_DECREF(self);
return NULL;
}
Py_INCREF(Py_None);
self->cb = Py_None;
if (self->cb == NULL)
{
Py_DECREF(Py_None);
return NULL;
}
}
return (PyObject *)self;
}
/*
* logging_config_members
*/
static PyMemberDef logging_config_members[] =
{
{
"msg_logging", T_INT, offsetof(logging_config_Object, msg_logging), 0,
"Log incoming and outgoing SIP message? Yes!"
},
{
"level", T_INT, offsetof(logging_config_Object, level), 0,
"Input verbosity level. Value 5 is reasonable."
},
{
"console_level", T_INT, offsetof(logging_config_Object, console_level),
0, "Verbosity level for console. Value 4 is reasonable."
},
{
"decor", T_INT, offsetof(logging_config_Object, decor), 0,
"Log decoration"
},
{
"log_filename", T_OBJECT_EX,
offsetof(logging_config_Object, log_filename), 0,
"Optional log filename"
},
{
"cb", T_OBJECT_EX, offsetof(logging_config_Object, cb), 0,
"Optional callback function to be called to write log to application "
"specific device. This function will be called forlog messages on "
"input verbosity level."
},
{NULL} /* Sentinel */
};
/*
* logging_config_Type
*/
static PyTypeObject logging_config_Type =
{
PyObject_HEAD_INIT(NULL)
0, /*ob_size*/
"py_pjsua.Logging_Config", /*tp_name*/
sizeof(logging_config_Object), /*tp_basicsize*/
0, /*tp_itemsize*/
(destructor)logging_config_dealloc,/*tp_dealloc*/
0, /*tp_print*/
0, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_compare*/
0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
0, /*tp_hash */
0, /*tp_call*/
0, /*tp_str*/
0, /*tp_getattro*/
0, /*tp_setattro*/
0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT, /*tp_flags*/
"Logging Config objects", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
0, /* tp_methods */
logging_config_members, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
logging_config_new, /* tp_new */
};
/*
* msg_data_Object
* typewrapper for MessageData class
* !modified @ 061206
*/
typedef struct
{
PyObject_HEAD
/* Type-specific fields go here. */
/*pjsip_hdr hdr_list;*/
PyObject * hdr_list;
PyObject * content_type;
PyObject * msg_body;
} msg_data_Object;
/*
* msg_data_dealloc
* deletes a msg_data
* !modified @ 061206
*/
static void msg_data_dealloc(msg_data_Object* self)
{
Py_XDECREF(self->hdr_list);
Py_XDECREF(self->content_type);
Py_XDECREF(self->msg_body);
self->ob_type->tp_free((PyObject*)self);
}
/*
* msg_data_new
* constructor for msg_data object
* !modified @ 061206
*/
static PyObject * msg_data_new(PyTypeObject *type, PyObject *args,
PyObject *kwds)
{
msg_data_Object *self;
self = (msg_data_Object *)type->tp_alloc(type, 0);
if (self != NULL)
{
Py_INCREF(Py_None);
self->hdr_list = Py_None;
if (self->hdr_list == NULL)
{
Py_DECREF(self);
return NULL;
}
self->content_type = PyString_FromString("");
if (self->content_type == NULL)
{
Py_DECREF(self);
return NULL;
}
self->msg_body = PyString_FromString("");
if (self->msg_body == NULL)
{
Py_DECREF(self);
return NULL;
}
}
return (PyObject *)self;
}
/*
* msg_data_members
* !modified @ 061206
*/
static PyMemberDef msg_data_members[] =
{
{
"hdr_list", T_OBJECT_EX, offsetof(msg_data_Object, hdr_list),
0, "Additional message headers as linked list."
},
{
"content_type", T_OBJECT_EX, offsetof(msg_data_Object, content_type),
0, "MIME type of optional message body."
},
{
"msg_body", T_OBJECT_EX, offsetof(msg_data_Object, msg_body), 0,
"Optional message body."
},
{NULL} /* Sentinel */
};
/*
* msg_data_Type
*/
static PyTypeObject msg_data_Type =
{
PyObject_HEAD_INIT(NULL)
0, /*ob_size*/
"py_pjsua.Msg_Data", /*tp_name*/
sizeof(msg_data_Object), /*tp_basicsize*/
0, /*tp_itemsize*/
(destructor)msg_data_dealloc,/*tp_dealloc*/
0, /*tp_print*/
0, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_compare*/
0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
0, /*tp_hash */
0, /*tp_call*/
0, /*tp_str*/
0, /*tp_getattro*/
0, /*tp_setattro*/
0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT, /*tp_flags*/
"msg_data objects", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
0, /* tp_methods */
msg_data_members, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
msg_data_new, /* tp_new */
};
/*
* translate_hdr
* internal function
* translate from hdr_list to pjsip_generic_string_hdr
*/
void translate_hdr(pj_pool_t *pool, pjsip_hdr *hdr, PyObject *py_hdr_list)
{
pj_list_init(hdr);
if (PyList_Check(py_hdr_list)) {
int i;
for (i = 0; i < PyList_Size(py_hdr_list); i++)
{
pj_str_t hname, hvalue;
pjsip_generic_string_hdr * new_hdr;
PyObject * tuple = PyList_GetItem(py_hdr_list, i);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -