bool Client::parseLogin(const rapidjson::Value &result, int *code) { if (!m_rpcId.setId(result["id"].GetString())) { *code = 1; return false; } # ifndef XMRIG_PROXY_PROJECT m_nicehash = m_url.isNicehash(); # endif if (result.HasMember("extensions")) { parseExtensions(result["extensions"]); } const bool rc = parseJob(result["job"], code); m_jobs = 0; return rc; }
void Client::parseNotification(const char *method, const rapidjson::Value ¶ms, const rapidjson::Value &error) { if (error.IsObject()) { if (!m_quiet) { LOG_ERR("[%s:%u] error: \"%s\", code: %d", m_url.host(), m_url.port(), error["message"].GetString(), error["code"].GetInt()); } return; } if (!method) { return; } if (strcmp(method, "job") == 0) { int code = -1; if (parseJob(params, &code)) { m_listener->onJobReceived(this, m_job); } return; } LOG_WARN("[%s:%u] unsupported method: \"%s\"", m_url.host(), m_url.port(), method); }
static gJobPtr parseGjobFile(char *filename) { xmlDocPtr doc; gJobPtr ret; jobPtr curjob; xmlNsPtr ns; xmlNodePtr cur; #ifdef LIBXML_SAX1_ENABLED /* * build an XML tree from a the file; */ doc = xmlParseFile(filename); if (doc == NULL) return(NULL); #else /* * the library has been compiled without some of the old interfaces */ return(NULL); #endif /* LIBXML_SAX1_ENABLED */ /* * Check the document is of the right kind */ cur = xmlDocGetRootElement(doc); if (cur == NULL) { fprintf(stderr,"empty document\n"); xmlFreeDoc(doc); return(NULL); } ns = xmlSearchNsByHref(doc, cur, (const xmlChar *) "http://www.gnome.org/some-location"); if (ns == NULL) { fprintf(stderr, "document of the wrong type, GJob Namespace not found\n"); xmlFreeDoc(doc); return(NULL); } if (xmlStrcmp(cur->name, (const xmlChar *) "Helping")) { fprintf(stderr,"document of the wrong type, root node != Helping"); xmlFreeDoc(doc); return(NULL); } /* * Allocate the structure to be returned. */ ret = (gJobPtr) malloc(sizeof(gJob)); if (ret == NULL) { fprintf(stderr,"out of memory\n"); xmlFreeDoc(doc); return(NULL); } memset(ret, 0, sizeof(gJob)); /* * Now, walk the tree. */ /* First level we expect just Jobs */ cur = cur->xmlChildrenNode; while ( cur && xmlIsBlankNode ( cur ) ) { cur = cur -> next; } if ( cur == 0 ) { xmlFreeDoc(doc); free(ret); return ( NULL ); } if ((xmlStrcmp(cur->name, (const xmlChar *) "Jobs")) || (cur->ns != ns)) { fprintf(stderr,"document of the wrong type, was '%s', Jobs expected", cur->name); fprintf(stderr,"xmlDocDump follows\n"); #ifdef LIBXML_OUTPUT_ENABLED xmlDocDump ( stderr, doc ); fprintf(stderr,"xmlDocDump finished\n"); #endif /* LIBXML_OUTPUT_ENABLED */ xmlFreeDoc(doc); free(ret); return(NULL); } /* Second level is a list of Job, but be laxist */ cur = cur->xmlChildrenNode; while (cur != NULL) { if ((!xmlStrcmp(cur->name, (const xmlChar *) "Job")) && (cur->ns == ns)) { curjob = parseJob(doc, ns, cur); if (curjob != NULL) ret->jobs[ret->nbJobs++] = curjob; if (ret->nbJobs >= 500) break; } cur = cur->next; } return(ret); }
gJobPtr parseGjobFile(char *filename) { xmlDocPtr doc; gJobPtr ret; jobPtr job; xmlNsPtr ns; xmlNodePtr cur; /* * build an XML tree from a the file; */ doc = xmlParseFile(filename); if (doc == NULL) return(NULL); /* * Check the document is of the right kind */ // cur = doc->root; // cur = doc->children; cur = xmlDocGetRootElement(doc); if (cur == NULL) { fprintf(stderr,"empty document\n"); xmlFreeDoc(doc); return(NULL); } ns = xmlSearchNsByHref(doc, cur, "http://www.gnome.org/some-location"); if (ns == NULL) { fprintf(stderr, "document of the wrong type, GJob Namespace not found\n"); xmlFreeDoc(doc); return(NULL); } if (strcmp(cur->name, "Helping")) { fprintf(stderr,"document of the wrong type, root node != Helping"); xmlFreeDoc(doc); return(NULL); } /* * Allocate the structure to be returned. */ ret = (gJobPtr) malloc(sizeof(gJob)); if (ret == NULL) { fprintf(stderr,"out of memory\n"); xmlFreeDoc(doc); return(NULL); } memset(ret, 0, sizeof(gJob)); /* * Now, walk the tree. */ /* First level we expect just Jobs */ // cur = cur->children; cur = cur -> children; while ( cur && xmlIsBlankNode ( cur ) ) { cur = cur -> next; } if ( cur == 0 ) return ( NULL ); if ((strcmp(cur->name, "Jobs")) || (cur->ns != ns)) { fprintf(stderr,"document of the wrong type, was '%s', Jobs expected", cur->name); fprintf(stderr,"xmlDocDump follows\n"); xmlDocDump ( stderr, doc ); fprintf(stderr,"xmlDocDump finished\n"); xmlFreeDoc(doc); free(ret); return(NULL); } /* Second level is a list of Job, but be laxist */ cur = cur->children; while (cur != NULL) { if ((!strcmp(cur->name, "Job")) && (cur->ns == ns)) { job = parseJob(doc, ns, cur); if (job != NULL) ret->jobs[ret->nbJobs++] = job; if (ret->nbJobs >= 500) break; } cur = cur->next; } return(ret); }