diff options
Diffstat (limited to 'protocols/Tlen/src/tlen_xml.cpp')
-rw-r--r-- | protocols/Tlen/src/tlen_xml.cpp | 114 |
1 files changed, 57 insertions, 57 deletions
diff --git a/protocols/Tlen/src/tlen_xml.cpp b/protocols/Tlen/src/tlen_xml.cpp index 28e3ca07c6..68ddc29145 100644 --- a/protocols/Tlen/src/tlen_xml.cpp +++ b/protocols/Tlen/src/tlen_xml.cpp @@ -29,25 +29,25 @@ static void TlenXmlRemoveChild(XmlNode *node, XmlNode *child); void TlenXmlInitState(XmlState *xmlState) { - if (xmlState == NULL) return; - xmlState->root.name = NULL; + if (xmlState == nullptr) return; + xmlState->root.name = nullptr; xmlState->root.depth = 0; xmlState->root.numAttr = 0; xmlState->root.maxNumAttr = 0; - xmlState->root.attr = NULL; + xmlState->root.attr = nullptr; xmlState->root.numChild = 0; xmlState->root.maxNumChild = 0; - xmlState->root.child = NULL; - xmlState->root.text = NULL; + xmlState->root.child = nullptr; + xmlState->root.text = nullptr; xmlState->root.state = NODE_OPEN; - xmlState->callback1_open = NULL; - xmlState->callback1_close = NULL; - xmlState->callback2_open = NULL; - xmlState->callback2_close = NULL; - xmlState->userdata1_open = NULL; - xmlState->userdata1_close = NULL; - xmlState->userdata2_open = NULL; - xmlState->userdata2_close = NULL; + xmlState->callback1_open = nullptr; + xmlState->callback1_close = nullptr; + xmlState->callback2_open = nullptr; + xmlState->callback2_close = nullptr; + xmlState->userdata1_open = nullptr; + xmlState->userdata1_close = nullptr; + xmlState->userdata2_open = nullptr; + xmlState->userdata2_close = nullptr; } void TlenXmlDestroyState(XmlState *xmlState) @@ -55,7 +55,7 @@ void TlenXmlDestroyState(XmlState *xmlState) int i; XmlNode *node; - if (xmlState == NULL) + if (xmlState == nullptr) return; // Note: cannot use TlenXmlFreeNode() to free xmlState->root // because it will do mir_free(xmlState->root) which is not freeable. @@ -173,7 +173,7 @@ int TlenXmlParse(XmlState *xmlState, char *buffer, int datalen) str = (char *) mir_alloc(q-p+1); strncpy(str, p, q-p); str[q-p] = '\0'; - TlenXmlProcessElem(xmlState, ELEM_TEXT, str, NULL); + TlenXmlProcessElem(xmlState, ELEM_TEXT, str, nullptr); mir_free(str); num += (q-p); p = q; @@ -193,7 +193,7 @@ static void TlenXmlParseAttr(XmlNode *node, char *text) char *p; XmlAttr *a; - if (node == NULL || text == NULL || mir_strlen(text) <= 0) + if (node == nullptr || text == nullptr || mir_strlen(text) <= 0) return; for (p=text;;) { @@ -277,7 +277,7 @@ static BOOL TlenXmlProcessElem(XmlState *xmlState, XmlElemType elemType, char *e //BOOL activateCallback = FALSE; char *text, *attr; - if (elemText == NULL) return FALSE; + if (elemText == nullptr) return FALSE; if (elemType == ELEM_OPEN && !mir_strcmp(elemText, "?xml")) { // TlenLog("XML: skip <?xml> tag"); @@ -286,7 +286,7 @@ static BOOL TlenXmlProcessElem(XmlState *xmlState, XmlElemType elemType, char *e // Find active node node = &(xmlState->root); - parentNode = NULL; + parentNode = nullptr; while (node->numChild>0 && node->child[node->numChild-1]->state == NODE_OPEN) { parentNode = node; node = node->child[node->numChild-1]; @@ -299,7 +299,7 @@ static BOOL TlenXmlProcessElem(XmlState *xmlState, XmlElemType elemType, char *e if (elemAttr) attr = mir_strdup(elemAttr); else - attr = NULL; + attr = nullptr; switch (elemType) { case ELEM_OPEN: @@ -313,14 +313,14 @@ static BOOL TlenXmlProcessElem(XmlState *xmlState, XmlElemType elemType, char *e n->depth = node->depth + 1; n->state = NODE_OPEN; n->numChild = n->maxNumChild = 0; - n->child = NULL; + n->child = nullptr; n->numAttr = n->maxNumAttr = 0; - n->attr = NULL; + n->attr = nullptr; TlenXmlParseAttr(n, attr); - n->text = NULL; - if (n->depth == 1 && xmlState->callback1_open != NULL) + n->text = nullptr; + if (n->depth == 1 && xmlState->callback1_open != nullptr) (*(xmlState->callback1_open))(n, xmlState->userdata1_open); - if (n->depth == 2 && xmlState->callback2_open != NULL) + if (n->depth == 2 && xmlState->callback2_open != nullptr) (*xmlState->callback2_open)(n, xmlState->userdata2_open); break; case ELEM_OPENCLOSE: @@ -334,29 +334,29 @@ static BOOL TlenXmlProcessElem(XmlState *xmlState, XmlElemType elemType, char *e n->depth = node->depth + 1; n->state = NODE_CLOSE; n->numChild = n->maxNumAttr = 0; - n->child = NULL; + n->child = nullptr; n->numAttr = n->maxNumAttr = 0; - n->attr = NULL; + n->attr = nullptr; TlenXmlParseAttr(n, attr); - n->text = NULL; - if (n->depth == 1 && xmlState->callback1_close != NULL) { + n->text = nullptr; + if (n->depth == 1 && xmlState->callback1_close != nullptr) { (*(xmlState->callback1_close))(n, xmlState->userdata1_close); TlenXmlRemoveChild(node, n); } - if (n->depth == 2 && xmlState->callback2_close != NULL) { + if (n->depth == 2 && xmlState->callback2_close != nullptr) { (*xmlState->callback2_close)(n, xmlState->userdata2_close); TlenXmlRemoveChild(node, n); } break; case ELEM_CLOSE: - if (node->name != NULL && !mir_strcmp(node->name, text)) { + if (node->name != nullptr && !mir_strcmp(node->name, text)) { node->state = NODE_CLOSE; int nodeDepth = node->depth; - if (nodeDepth == 1 && xmlState->callback1_close != NULL) { + if (nodeDepth == 1 && xmlState->callback1_close != nullptr) { (*(xmlState->callback1_close))(node, xmlState->userdata1_close); TlenXmlRemoveChild(parentNode, node); } - if (nodeDepth == 2 && xmlState->callback2_close != NULL) { + if (nodeDepth == 2 && xmlState->callback2_close != nullptr) { (*xmlState->callback2_close)(node, xmlState->userdata2_close); TlenXmlRemoveChild(parentNode, node); } @@ -387,13 +387,13 @@ char *TlenXmlGetAttrValue(XmlNode *node, char *key) { int i; - if (node == NULL || node->numAttr <= 0 || key == NULL || mir_strlen(key) <= 0) - return NULL; + if (node == nullptr || node->numAttr <= 0 || key == nullptr || mir_strlen(key) <= 0) + return nullptr; for (i=0; i<node->numAttr; i++) { if (node->attr[i]->name && !mir_strcmp(key, node->attr[i]->name)) return node->attr[i]->value; } - return NULL; + return nullptr; } XmlNode *TlenXmlGetChild(XmlNode *node, char *tag) @@ -405,8 +405,8 @@ XmlNode *TlenXmlGetNthChild(XmlNode *node, char *tag, int nth) { int i, num; - if (node == NULL || node->numChild <= 0 || tag == NULL || mir_strlen(tag) <= 0 || nth < 1) - return NULL; + if (node == nullptr || node->numChild <= 0 || tag == nullptr || mir_strlen(tag) <= 0 || nth < 1) + return nullptr; num = 1; for (i=0; i<node->numChild; i++) { if (node->child[i]->name && !mir_strcmp(tag, node->child[i]->name)) { @@ -416,7 +416,7 @@ XmlNode *TlenXmlGetNthChild(XmlNode *node, char *tag, int nth) num++; } } - return NULL; + return nullptr; } XmlNode *TlenXmlGetChildWithGivenAttrValue(XmlNode *node, char *tag, char *attrKey, char *attrValue) @@ -424,23 +424,23 @@ XmlNode *TlenXmlGetChildWithGivenAttrValue(XmlNode *node, char *tag, char *attrK int i; char *str; - if (node == NULL || node->numChild <= 0 || tag == NULL || mir_strlen(tag) <= 0 || attrKey == NULL || mir_strlen(attrKey) <= 0 || attrValue == NULL || mir_strlen(attrValue) <= 0) - return NULL; + if (node == nullptr || node->numChild <= 0 || tag == nullptr || mir_strlen(tag) <= 0 || attrKey == nullptr || mir_strlen(attrKey) <= 0 || attrValue == nullptr || mir_strlen(attrValue) <= 0) + return nullptr; for (i=0; i<node->numChild; i++) { if (node->child[i]->name && !mir_strcmp(tag, node->child[i]->name)) { - if ((str=TlenXmlGetAttrValue(node->child[i], attrKey)) != NULL) + if ((str=TlenXmlGetAttrValue(node->child[i], attrKey)) != nullptr) if (!mir_strcmp(str, attrValue)) return node->child[i]; } } - return NULL; + return nullptr; } static void TlenXmlRemoveChild(XmlNode *node, XmlNode *child) { int i; - if (node == NULL || child == NULL || node->numChild <= 0) return; + if (node == nullptr || child == nullptr || node->numChild <= 0) return; for (i=0; i<node->numChild; i++) { if (node->child[i] == child) break; @@ -457,7 +457,7 @@ void TlenXmlFreeNode(XmlNode *node) { int i; - if (node == NULL) + if (node == nullptr) return; // Free all children first for (i=0; i<node->numChild; i++) @@ -482,7 +482,7 @@ XmlNode *TlenXmlCopyNode(XmlNode *node) XmlNode *n; int i; - if (node == NULL) return NULL; + if (node == nullptr) return nullptr; n = (XmlNode *) mir_alloc(sizeof(XmlNode)); // Copy attributes if (node->numAttr > 0) { @@ -490,13 +490,13 @@ XmlNode *TlenXmlCopyNode(XmlNode *node) for (i=0; i<node->numAttr; i++) { n->attr[i] = (XmlAttr *) mir_alloc(sizeof(XmlAttr)); if (node->attr[i]->name) n->attr[i]->name = mir_strdup(node->attr[i]->name); - else n->attr[i]->name = NULL; + else n->attr[i]->name = nullptr; if (node->attr[i]->value) n->attr[i]->value = mir_strdup(node->attr[i]->value); - else n->attr[i]->value = NULL; + else n->attr[i]->value = nullptr; } } else - n->attr = NULL; + n->attr = nullptr; // Recursively copy children if (node->numChild > 0) { n->child = (XmlNode **) mir_alloc(node->numChild*sizeof(XmlNode *)); @@ -504,7 +504,7 @@ XmlNode *TlenXmlCopyNode(XmlNode *node) n->child[i] = TlenXmlCopyNode(node->child[i]); } else - n->child = NULL; + n->child = nullptr; // Copy other fields n->numAttr = node->numAttr; n->maxNumAttr = node->numAttr; @@ -512,8 +512,8 @@ XmlNode *TlenXmlCopyNode(XmlNode *node) n->maxNumChild = node->numChild; n->depth = node->depth; n->state = node->state; - n->name = (node->name)?mir_strdup(node->name):NULL; - n->text = (node->text)?mir_strdup(node->text):NULL; + n->name = (node->name)?mir_strdup(node->name):nullptr; + n->text = (node->text)?mir_strdup(node->text):nullptr; return n; } @@ -522,8 +522,8 @@ XmlNode *TlenXmlCreateNode(char *name) { XmlNode *n; - if (name == NULL) - return NULL; + if (name == nullptr) + return nullptr; n = (XmlNode *) mir_alloc(sizeof(XmlNode)); memset(n, 0, sizeof(XmlNode)); @@ -535,7 +535,7 @@ void TlenXmlAddAttr(XmlNode *n, char *name, char *value) { int i; - if (n == NULL || name == NULL || value == NULL) + if (n == nullptr || name == nullptr || value == nullptr) return; i = n->numAttr; @@ -550,8 +550,8 @@ XmlNode *TlenXmlAddChild(XmlNode *n, char *name) { int i; - if (n == NULL || name == NULL) - return NULL; + if (n == nullptr || name == nullptr) + return nullptr; i = n->numChild; n->numChild++; @@ -564,7 +564,7 @@ XmlNode *TlenXmlAddChild(XmlNode *n, char *name) void TlenXmlAddText(XmlNode *n, char *text) { - if (n != NULL && text != NULL) { + if (n != nullptr && text != nullptr) { if (n->text) mir_free(n->text); n->text = mir_strdup(text); } |