oss_xml.c 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435
  1. #include "aos_string.h"
  2. #include "aos_list.h"
  3. #include "aos_buf.h"
  4. #include "aos_util.h"
  5. #include "aos_log.h"
  6. #include "aos_status.h"
  7. #include "oss_util.h"
  8. #include "oss_auth.h"
  9. #include "oss_xml.h"
  10. #include "oss_define.h"
  11. static int get_truncated_from_xml(aos_pool_t *p, mxml_node_t *xml_node, const char *truncated_xml_path);
  12. int get_truncated_from_xml(aos_pool_t *p, mxml_node_t *xml_node, const char *truncated_xml_path)
  13. {
  14. char *is_truncated;
  15. int truncated = 0;
  16. is_truncated = get_xmlnode_value(p, xml_node, truncated_xml_path);
  17. if (is_truncated) {
  18. truncated = strcasecmp(is_truncated, "false") == 0 ? 0 : 1;
  19. }
  20. return truncated;
  21. }
  22. static char* new_xml_buff(mxml_node_t *doc);
  23. char* new_xml_buff(mxml_node_t *doc)
  24. {
  25. int bytes;
  26. char buffer[8192];
  27. char *s;
  28. bytes = mxmlSaveString(doc, buffer, sizeof(buffer), MXML_NO_CALLBACK);
  29. if (bytes <= 0) {
  30. return (NULL);
  31. }
  32. if (bytes < (int)(sizeof(buffer) - 1)) {
  33. return (strdup(buffer));
  34. }
  35. if ((s = malloc(bytes + 1)) == NULL) {
  36. return (NULL);
  37. }
  38. mxmlSaveString(doc, s, bytes + 1, MXML_NO_CALLBACK);
  39. return (s);
  40. }
  41. int get_xmldoc(aos_list_t *bc, mxml_node_t **root)
  42. {
  43. int res;
  44. if (aos_list_empty(bc)) {
  45. return AOSE_XML_PARSE_ERROR;
  46. }
  47. if ((res = aos_parse_xml_body(bc, root)) != AOSE_OK) {
  48. return AOSE_XML_PARSE_ERROR;
  49. }
  50. return AOSE_OK;
  51. }
  52. char *get_xmlnode_value(aos_pool_t *p, mxml_node_t *xml_node, const char *xml_path)
  53. {
  54. char *value = NULL;
  55. mxml_node_t *node;
  56. char *node_content;
  57. node = mxmlFindElement(xml_node, xml_node, xml_path, NULL, NULL, MXML_DESCEND);
  58. if (NULL != node && node->child != NULL) {
  59. node_content = node->child->value.opaque;
  60. value = apr_pstrdup(p, (char *)node_content);
  61. }
  62. return value;
  63. }
  64. int oss_acl_parse_from_body(aos_pool_t *p, aos_list_t *bc, aos_string_t *oss_acl)
  65. {
  66. int res;
  67. mxml_node_t *doc = NULL;
  68. const char xml_path[] = "Grant";
  69. char *acl;
  70. res = get_xmldoc(bc, &doc);
  71. if (res == AOSE_OK) {
  72. acl = get_xmlnode_value(p, doc, xml_path);
  73. if (acl) {
  74. aos_str_set(oss_acl, acl);
  75. }
  76. mxmlDelete(doc);
  77. }
  78. return res;
  79. }
  80. void oss_list_objects_owner_parse(aos_pool_t *p, mxml_node_t *xml_node, oss_list_object_content_t *content)
  81. {
  82. mxml_node_t *node;
  83. char *node_content;
  84. char *owner_id;
  85. char *owner_display_name;
  86. node = mxmlFindElement(xml_node, xml_node, "ID",NULL, NULL, MXML_DESCEND);
  87. if (NULL != node) {
  88. node_content = node->child->value.opaque;
  89. owner_id = apr_pstrdup(p, node_content);
  90. aos_str_set(&content->owner_id, owner_id);
  91. }
  92. node = mxmlFindElement(xml_node, xml_node, "DisplayName", NULL, NULL, MXML_DESCEND);
  93. if (NULL != node) {
  94. node_content = node->child->value.opaque;
  95. owner_display_name = apr_pstrdup(p, node_content);
  96. aos_str_set(&content->owner_display_name, owner_display_name);
  97. }
  98. }
  99. void oss_list_objects_content_parse(aos_pool_t *p, mxml_node_t *xml_node, oss_list_object_content_t *content)
  100. {
  101. char *key;
  102. char *last_modified;
  103. char *etag;
  104. char *size;
  105. char *node_content;
  106. mxml_node_t *node;
  107. node = mxmlFindElement(xml_node, xml_node, "Key", NULL, NULL, MXML_DESCEND);
  108. if (NULL != node) {
  109. node_content = node->child->value.opaque;
  110. key = apr_pstrdup(p, (char *)node_content);
  111. aos_str_set(&content->key, key);
  112. }
  113. node = mxmlFindElement(xml_node, xml_node, "LastModified", NULL, NULL, MXML_DESCEND);
  114. if (NULL != node) {
  115. node_content = node->child->value.opaque;
  116. last_modified = apr_pstrdup(p, (char *)node_content);
  117. aos_str_set(&content->last_modified, last_modified);
  118. }
  119. node = mxmlFindElement(xml_node, xml_node, "ETag", NULL, NULL, MXML_DESCEND);
  120. if (NULL != node) {
  121. node_content = node->child->value.opaque;
  122. etag = apr_pstrdup(p, (char *)node_content);
  123. aos_str_set(&content->etag, etag);
  124. }
  125. node = mxmlFindElement(xml_node, xml_node, "Size", NULL, NULL, MXML_DESCEND);
  126. if (NULL != node) {
  127. node_content = node->child->value.opaque;
  128. size = apr_pstrdup(p, (char *)node_content);
  129. aos_str_set(&content->size, size);
  130. }
  131. node = mxmlFindElement(xml_node, xml_node, "Owner", NULL, NULL, MXML_DESCEND);
  132. if (NULL != node) {
  133. oss_list_objects_owner_parse(p, node, content);
  134. }
  135. }
  136. void oss_list_objects_contents_parse(aos_pool_t *p, mxml_node_t *root, const char *xml_path,
  137. aos_list_t *object_list)
  138. {
  139. mxml_node_t *content_node;
  140. oss_list_object_content_t *content;
  141. content_node = mxmlFindElement(root, root, xml_path, NULL, NULL, MXML_DESCEND);
  142. for ( ; content_node != NULL; ) {
  143. content = oss_create_list_object_content(p);
  144. oss_list_objects_content_parse(p, content_node, content);
  145. aos_list_add_tail(&content->node, object_list);
  146. content_node = mxmlFindElement(content_node, root, xml_path, NULL, NULL, MXML_DESCEND);
  147. }
  148. }
  149. void oss_list_objects_prefix_parse(aos_pool_t *p, mxml_node_t *xml_node, oss_list_object_common_prefix_t *common_prefix)
  150. {
  151. char *prefix;
  152. mxml_node_t *node;
  153. char *node_content;
  154. node = mxmlFindElement(xml_node, xml_node, "Prefix", NULL, NULL, MXML_DESCEND);
  155. if (NULL != node) {
  156. node_content = node->child->value.opaque;
  157. prefix = apr_pstrdup(p, (char *)node_content);
  158. aos_str_set(&common_prefix->prefix, prefix);
  159. }
  160. }
  161. void oss_list_objects_common_prefix_parse(aos_pool_t *p, mxml_node_t *xml_node, const char *xml_path,
  162. aos_list_t *common_prefix_list)
  163. {
  164. mxml_node_t *node;
  165. oss_list_object_common_prefix_t *common_prefix;
  166. node = mxmlFindElement(xml_node, xml_node, xml_path, NULL, NULL, MXML_DESCEND);
  167. for ( ; node != NULL; ) {
  168. common_prefix = oss_create_list_object_common_prefix(p);
  169. oss_list_objects_prefix_parse(p, node, common_prefix);
  170. aos_list_add_tail(&common_prefix->node, common_prefix_list);
  171. node = mxmlFindElement(node, xml_node, xml_path, NULL, NULL, MXML_DESCEND);
  172. }
  173. }
  174. int oss_list_objects_parse_from_body(aos_pool_t *p, aos_list_t *bc,
  175. aos_list_t *object_list, aos_list_t *common_prefix_list, aos_string_t *marker, int *truncated)
  176. {
  177. int res;
  178. mxml_node_t *root;
  179. const char next_marker_xml_path[] = "NextMarker";
  180. const char truncated_xml_path[] = "IsTruncated";
  181. const char buckets_xml_path[] = "Contents";
  182. const char common_prefix_xml_path[] = "CommonPrefixes";
  183. char* next_marker;
  184. res = get_xmldoc(bc, &root);
  185. if (res == AOSE_OK) {
  186. next_marker = get_xmlnode_value(p, root, next_marker_xml_path);
  187. if (next_marker) {
  188. aos_str_set(marker, next_marker);
  189. }
  190. *truncated = get_truncated_from_xml(p, root, truncated_xml_path);
  191. oss_list_objects_contents_parse(p, root, buckets_xml_path, object_list);
  192. oss_list_objects_common_prefix_parse(p, root, common_prefix_xml_path, common_prefix_list);
  193. mxmlDelete(root);
  194. }
  195. return res;
  196. }
  197. int oss_upload_id_parse_from_body(aos_pool_t *p, aos_list_t *bc, aos_string_t *upload_id)
  198. {
  199. int res;
  200. mxml_node_t *root;
  201. const char xml_path[] = "UploadId";
  202. char *id;
  203. res = get_xmldoc(bc, &root);
  204. if (res == AOSE_OK) {
  205. id = get_xmlnode_value(p, root, xml_path);
  206. if (id) {
  207. aos_str_set(upload_id, id);
  208. }
  209. mxmlDelete(root);
  210. }
  211. return res;
  212. }
  213. void oss_list_parts_contents_parse(aos_pool_t *p, mxml_node_t *root, const char *xml_path,
  214. aos_list_t *part_list)
  215. {
  216. mxml_node_t *content_node;
  217. oss_list_part_content_t *content;
  218. content_node = mxmlFindElement(root, root, xml_path, NULL, NULL, MXML_DESCEND);
  219. for ( ; content_node != NULL; ) {
  220. content = oss_create_list_part_content(p);
  221. oss_list_parts_content_parse(p, content_node, content);
  222. aos_list_add_tail(&content->node, part_list);
  223. content_node = mxmlFindElement(content_node, root, xml_path, NULL, NULL, MXML_DESCEND);
  224. }
  225. }
  226. void oss_list_parts_content_parse(aos_pool_t *p, mxml_node_t *xml_node, oss_list_part_content_t *content)
  227. {
  228. char *part_number;
  229. char *last_modified;
  230. char *etag;
  231. char *size;
  232. char *node_content;
  233. mxml_node_t *node;
  234. node = mxmlFindElement(xml_node, xml_node, "PartNumber", NULL, NULL, MXML_DESCEND);
  235. if (NULL != node) {
  236. node_content = node->child->value.opaque;
  237. part_number = apr_pstrdup(p, (char *)node_content);
  238. aos_str_set(&content->part_number, part_number);
  239. }
  240. node = mxmlFindElement(xml_node, xml_node, "LastModified", NULL, NULL, MXML_DESCEND);
  241. if (NULL != node) {
  242. node_content = node->child->value.opaque;
  243. last_modified = apr_pstrdup(p, (char *)node_content);
  244. aos_str_set(&content->last_modified, last_modified);
  245. }
  246. node = mxmlFindElement(xml_node, xml_node, "ETag", NULL, NULL, MXML_DESCEND);
  247. if (NULL != node) {
  248. node_content = node->child->value.opaque;
  249. etag = apr_pstrdup(p, (char *)node_content);
  250. aos_str_set(&content->etag, etag);
  251. }
  252. node = mxmlFindElement(xml_node, xml_node, "Size", NULL, NULL, MXML_DESCEND);
  253. if (NULL != node) {
  254. node_content = node->child->value.opaque;
  255. size = apr_pstrdup(p, (char *)node_content);
  256. aos_str_set(&content->size, size);
  257. }
  258. }
  259. int oss_list_parts_parse_from_body(aos_pool_t *p, aos_list_t *bc,
  260. aos_list_t *part_list, aos_string_t *partnumber_marker, int *truncated)
  261. {
  262. int res;
  263. mxml_node_t *root;
  264. const char next_partnumber_marker_xml_path[] = "NextPartNumberMarker";
  265. const char truncated_xml_path[] = "IsTruncated";
  266. const char parts_xml_path[] = "Part";
  267. char *next_partnumber_marker;
  268. res = get_xmldoc(bc, &root);
  269. if (res == AOSE_OK) {
  270. next_partnumber_marker = get_xmlnode_value(p, root,
  271. next_partnumber_marker_xml_path);
  272. if (next_partnumber_marker) {
  273. aos_str_set(partnumber_marker, next_partnumber_marker);
  274. }
  275. *truncated = get_truncated_from_xml(p, root, truncated_xml_path);
  276. oss_list_parts_contents_parse(p, root, parts_xml_path, part_list);
  277. mxmlDelete(root);
  278. }
  279. return res;
  280. }
  281. void oss_list_multipart_uploads_contents_parse(aos_pool_t *p, mxml_node_t *root, const char *xml_path,
  282. aos_list_t *upload_list)
  283. {
  284. mxml_node_t *content_node;
  285. oss_list_multipart_upload_content_t *content;
  286. content_node = mxmlFindElement(root, root, xml_path, NULL, NULL, MXML_DESCEND);
  287. for ( ; content_node != NULL; ) {
  288. content = oss_create_list_multipart_upload_content(p);
  289. oss_list_multipart_uploads_content_parse(p, content_node, content);
  290. aos_list_add_tail(&content->node, upload_list);
  291. content_node = mxmlFindElement(content_node, root, xml_path, NULL, NULL, MXML_DESCEND);
  292. }
  293. }
  294. void oss_list_multipart_uploads_content_parse(aos_pool_t *p, mxml_node_t *xml_node,
  295. oss_list_multipart_upload_content_t *content)
  296. {
  297. char *key;
  298. char *upload_id;
  299. char *initiated;
  300. char *node_content;
  301. mxml_node_t *node;
  302. node = mxmlFindElement(xml_node, xml_node, "Key",NULL, NULL, MXML_DESCEND);
  303. if (NULL != node) {
  304. node_content = node->child->value.opaque;
  305. key = apr_pstrdup(p, (char *)node_content);
  306. aos_str_set(&content->key, key);
  307. }
  308. node = mxmlFindElement(xml_node, xml_node, "UploadId",NULL, NULL, MXML_DESCEND);
  309. if (NULL != node) {
  310. node_content = node->child->value.opaque;
  311. upload_id = apr_pstrdup(p, (char *)node_content);
  312. aos_str_set(&content->upload_id, upload_id);
  313. }
  314. node = mxmlFindElement(xml_node, xml_node, "Initiated",NULL, NULL, MXML_DESCEND);
  315. if (NULL != node) {
  316. node_content = node->child->value.opaque;
  317. initiated = apr_pstrdup(p, (char *)node_content);
  318. aos_str_set(&content->initiated, initiated);
  319. }
  320. }
  321. int oss_list_multipart_uploads_parse_from_body(aos_pool_t *p, aos_list_t *bc,
  322. aos_list_t *upload_list, aos_string_t *key_marker,
  323. aos_string_t *upload_id_marker, int *truncated)
  324. {
  325. int res;
  326. mxml_node_t *root;
  327. const char next_key_marker_xml_path[] = "NextKeyMarker";
  328. const char next_upload_id_marker_xml_path[] = "NextUploadIdMarker";
  329. const char truncated_xml_path[] = "IsTruncated";
  330. const char uploads_xml_path[] = "Upload";
  331. char *next_key_marker;
  332. char *next_upload_id_marker;
  333. res = get_xmldoc(bc, &root);
  334. if (res == AOSE_OK) {
  335. next_key_marker = get_xmlnode_value(p, root, next_key_marker_xml_path);
  336. if (next_key_marker) {
  337. aos_str_set(key_marker, next_key_marker);
  338. }
  339. next_upload_id_marker = get_xmlnode_value(p, root, next_upload_id_marker_xml_path);
  340. if (next_upload_id_marker) {
  341. aos_str_set(upload_id_marker, next_upload_id_marker);
  342. }
  343. *truncated = get_truncated_from_xml(p, root, truncated_xml_path);
  344. oss_list_multipart_uploads_contents_parse(p, root, uploads_xml_path, upload_list);
  345. mxmlDelete(root);
  346. }
  347. return res;
  348. }
  349. char *build_complete_multipart_upload_xml(aos_pool_t *p, aos_list_t *bc)
  350. {
  351. char *xml_buff;
  352. char *complete_part_xml;
  353. aos_string_t xml_doc;
  354. mxml_node_t *doc;
  355. mxml_node_t *root_node;
  356. oss_complete_part_content_t *content;
  357. doc = mxmlNewXML("1.0");
  358. root_node = mxmlNewElement(doc, "CompleteMultipartUpload");
  359. aos_list_for_each_entry(oss_complete_part_content_t, content, bc, node) {
  360. mxml_node_t *part_node = mxmlNewElement(root_node, "Part");
  361. mxml_node_t *part_number_node = mxmlNewElement(part_node, "PartNumber");
  362. mxml_node_t *etag_node = mxmlNewElement(part_node, "ETag");
  363. mxmlNewText(part_number_node, 0, content->part_number.data);
  364. mxmlNewText(etag_node, 0, content->etag.data);
  365. }
  366. xml_buff = new_xml_buff(doc);
  367. if (xml_buff == NULL) {
  368. return NULL;
  369. }
  370. aos_str_set(&xml_doc, xml_buff);
  371. complete_part_xml = aos_pstrdup(p, &xml_doc);
  372. free(xml_buff);
  373. mxmlDelete(doc);
  374. return complete_part_xml;
  375. }
  376. void build_complete_multipart_upload_body(aos_pool_t *p, aos_list_t *part_list, aos_list_t *body)
  377. {
  378. char *complete_multipart_upload_xml;
  379. aos_buf_t *b;
  380. complete_multipart_upload_xml = build_complete_multipart_upload_xml(p, part_list);
  381. aos_list_init(body);
  382. b = aos_buf_pack(p, complete_multipart_upload_xml, strlen(complete_multipart_upload_xml));
  383. aos_list_add_tail(&b->node, body);
  384. }
  385. char *build_lifecycle_xml(aos_pool_t *p, aos_list_t *lifecycle_rule_list)
  386. {
  387. char *lifecycle_xml;
  388. char *xml_buff;
  389. aos_string_t xml_doc;
  390. mxml_node_t *doc;
  391. mxml_node_t *root_node;
  392. oss_lifecycle_rule_content_t *content;
  393. doc = mxmlNewXML("1.0");
  394. root_node = mxmlNewElement(doc, "LifecycleConfiguration");
  395. aos_list_for_each_entry(oss_lifecycle_rule_content_t, content, lifecycle_rule_list, node) {
  396. mxml_node_t *rule_node = mxmlNewElement(root_node, "Rule");
  397. mxml_node_t *id_node = mxmlNewElement(rule_node, "ID");
  398. mxml_node_t *prefix_node = mxmlNewElement(rule_node, "Prefix");
  399. mxml_node_t *status_node = mxmlNewElement(rule_node, "Status");
  400. mxml_node_t *expire_node = mxmlNewElement(rule_node, "Expiration");
  401. mxmlNewText(id_node, 0, content->id.data);
  402. mxmlNewText(prefix_node, 0, content->prefix.data);
  403. mxmlNewText(status_node, 0, content->status.data);
  404. if (content->days != INT_MAX) {
  405. char value_str[64];
  406. mxml_node_t *days_node = mxmlNewElement(expire_node, "Days");
  407. apr_snprintf(value_str, sizeof(value_str), "%d", content->days);
  408. mxmlNewText(days_node, 0, value_str);
  409. } else if (content->date.len != 0 && strcmp(content->date.data, "") != 0) {
  410. mxml_node_t *date_node = mxmlNewElement(expire_node, "Date");
  411. mxmlNewText(date_node, 0, content->date.data);
  412. }
  413. }
  414. xml_buff = new_xml_buff(doc);
  415. if (xml_buff == NULL) {
  416. return NULL;
  417. }
  418. aos_str_set(&xml_doc, xml_buff);
  419. lifecycle_xml = aos_pstrdup(p, &xml_doc);
  420. free(xml_buff);
  421. mxmlDelete(doc);
  422. return lifecycle_xml;
  423. }
  424. void build_lifecycle_body(aos_pool_t *p, aos_list_t *lifecycle_rule_list, aos_list_t *body)
  425. {
  426. char *lifecycle_xml;
  427. aos_buf_t *b;
  428. lifecycle_xml = build_lifecycle_xml(p, lifecycle_rule_list);
  429. aos_list_init(body);
  430. b = aos_buf_pack(p, lifecycle_xml, strlen(lifecycle_xml));
  431. aos_list_add_tail(&b->node, body);
  432. }
  433. int oss_lifecycle_rules_parse_from_body(aos_pool_t *p, aos_list_t *bc, aos_list_t *lifecycle_rule_list)
  434. {
  435. int res;
  436. mxml_node_t *root = NULL;
  437. const char rule_xml_path[] = "Rule";
  438. res = get_xmldoc(bc, &root);
  439. if (res == AOSE_OK) {
  440. oss_lifecycle_rule_contents_parse(p, root, rule_xml_path, lifecycle_rule_list);
  441. mxmlDelete(root);
  442. }
  443. return res;
  444. }
  445. void oss_lifecycle_rule_contents_parse(aos_pool_t *p, mxml_node_t *root, const char *xml_path,
  446. aos_list_t *lifecycle_rule_list)
  447. {
  448. mxml_node_t *node;
  449. oss_lifecycle_rule_content_t *content;
  450. node = mxmlFindElement(root, root, xml_path, NULL, NULL, MXML_DESCEND);
  451. for ( ; node != NULL; ) {
  452. content = oss_create_lifecycle_rule_content(p);
  453. oss_lifecycle_rule_content_parse(p, node, content);
  454. aos_list_add_tail(&content->node, lifecycle_rule_list);
  455. node = mxmlFindElement(node, root, xml_path, NULL, NULL, MXML_DESCEND);
  456. }
  457. }
  458. void oss_lifecycle_rule_content_parse(aos_pool_t *p, mxml_node_t * xml_node,
  459. oss_lifecycle_rule_content_t *content)
  460. {
  461. char *id;
  462. char *prefix;
  463. char *status;
  464. char *node_content;
  465. mxml_node_t *node;
  466. node = mxmlFindElement(xml_node, xml_node, "ID",NULL, NULL, MXML_DESCEND);
  467. if (NULL != node) {
  468. node_content = node->child->value.opaque;
  469. id = apr_pstrdup(p, (char *)node_content);
  470. aos_str_set(&content->id, id);
  471. }
  472. node = mxmlFindElement(xml_node, xml_node, "Prefix",NULL, NULL,MXML_DESCEND);
  473. if (NULL != node) {
  474. node_content = node->child->value.opaque;
  475. prefix = apr_pstrdup(p, (char *)node_content);
  476. aos_str_set(&content->prefix, prefix);
  477. }
  478. node = mxmlFindElement(xml_node, xml_node, "Status",NULL, NULL,MXML_DESCEND);
  479. if (NULL != node) {
  480. node_content = node->child->value.opaque;
  481. status = apr_pstrdup(p, (char *)node_content);
  482. aos_str_set(&content->status, status);
  483. }
  484. node = mxmlFindElement(xml_node, xml_node, "Expiration",NULL, NULL,MXML_DESCEND);
  485. if (NULL != node) {
  486. oss_lifecycle_rule_expire_parse(p, node, content);
  487. }
  488. }
  489. void oss_lifecycle_rule_expire_parse(aos_pool_t *p, mxml_node_t * xml_node,
  490. oss_lifecycle_rule_content_t *content)
  491. {
  492. char* days;
  493. char *date;
  494. mxml_node_t *node;
  495. char *node_content;
  496. node = mxmlFindElement(xml_node, xml_node, "Days", NULL, NULL, MXML_DESCEND);
  497. if (NULL != node) {
  498. node_content = node->child->value.opaque;
  499. days = apr_pstrdup(p, (char *)node_content);
  500. content->days = atoi(days);
  501. }
  502. node = mxmlFindElement(xml_node, xml_node, "Date", NULL, NULL, MXML_DESCEND);
  503. if (NULL != node) {
  504. node_content = node->child->value.opaque;
  505. date = apr_pstrdup(p, (char *)node_content);
  506. aos_str_set(&content->date, date);
  507. }
  508. }
  509. void oss_delete_objects_contents_parse(aos_pool_t *p, mxml_node_t *root, const char *xml_path,
  510. aos_list_t *object_list)
  511. {
  512. mxml_node_t *node;
  513. node = mxmlFindElement(root, root, xml_path, NULL, NULL, MXML_DESCEND);
  514. for ( ; node != NULL; ) {
  515. oss_object_key_t *content = oss_create_oss_object_key(p);
  516. oss_object_key_parse(p, node, content);
  517. aos_list_add_tail(&content->node, object_list);
  518. node = mxmlFindElement(node, root, xml_path, NULL, NULL, MXML_DESCEND);
  519. }
  520. }
  521. void oss_object_key_parse(aos_pool_t *p, mxml_node_t * xml_node,
  522. oss_object_key_t *content)
  523. {
  524. char *key;
  525. char *encoded_key;
  526. char *node_content;
  527. mxml_node_t *node;
  528. node = mxmlFindElement(xml_node, xml_node, "Key",NULL, NULL, MXML_DESCEND);
  529. if (NULL != node) {
  530. node_content = node->child->value.opaque;
  531. encoded_key = (char*)node_content;
  532. key = (char *) aos_palloc(p, strlen(encoded_key));
  533. aos_url_decode(encoded_key, key);
  534. aos_str_set(&content->key, key);
  535. }
  536. }
  537. int oss_delete_objects_parse_from_body(aos_pool_t *p, aos_list_t *bc, aos_list_t *object_list)
  538. {
  539. int res;
  540. mxml_node_t *root = NULL;
  541. const char deleted_xml_path[] = "Deleted";
  542. res = get_xmldoc(bc, &root);
  543. if (res == AOSE_OK) {
  544. oss_delete_objects_contents_parse(p, root, deleted_xml_path, object_list);
  545. mxmlDelete(root);
  546. }
  547. return res;
  548. }
  549. void oss_publish_url_parse(aos_pool_t *p, mxml_node_t *node, oss_live_channel_publish_url_t *content)
  550. {
  551. char *url;
  552. char *node_content;
  553. if (NULL != node) {
  554. node_content = node->child->value.opaque;
  555. url = apr_pstrdup(p, node_content);
  556. aos_str_set(&content->publish_url, url);
  557. }
  558. }
  559. void oss_play_url_parse(aos_pool_t *p, mxml_node_t *node, oss_live_channel_play_url_t *content)
  560. {
  561. char *url;
  562. char *node_content;
  563. if (NULL != node) {
  564. node_content = node->child->value.opaque;
  565. url = apr_pstrdup(p, node_content);
  566. aos_str_set(&content->play_url, url);
  567. }
  568. }
  569. void oss_publish_urls_contents_parse(aos_pool_t *p, mxml_node_t *root, const char *xml_path,
  570. aos_list_t *publish_xml_list)
  571. {
  572. mxml_node_t *node;
  573. node = mxmlFindElement(root, root, xml_path, NULL, NULL, MXML_DESCEND);
  574. for ( ; node != NULL; ) {
  575. oss_live_channel_publish_url_t *content = oss_create_live_channel_publish_url(p);
  576. oss_publish_url_parse(p, node, content);
  577. aos_list_add_tail(&content->node, publish_xml_list);
  578. node = mxmlFindElement(node, root, xml_path, NULL, NULL, MXML_DESCEND);
  579. }
  580. }
  581. void oss_play_urls_contents_parse(aos_pool_t *p, mxml_node_t *root, const char *xml_path,
  582. aos_list_t *play_xml_list)
  583. {
  584. mxml_node_t *node;
  585. node = mxmlFindElement(root, root, xml_path, NULL, NULL, MXML_DESCEND);
  586. for ( ; node != NULL; ) {
  587. oss_live_channel_play_url_t *content = oss_create_live_channel_play_url(p);
  588. oss_play_url_parse(p, node, content);
  589. aos_list_add_tail(&content->node, play_xml_list);
  590. node = mxmlFindElement(node, root, xml_path, NULL, NULL, MXML_DESCEND);
  591. }
  592. }
  593. void oss_create_live_channel_content_parse(aos_pool_t *p, mxml_node_t *root,
  594. const char *publish_xml_path, aos_list_t *publish_url_list,
  595. const char *play_xml_path, aos_list_t *play_url_list)
  596. {
  597. mxml_node_t *node;
  598. const char url_xml_path[] = "Url";
  599. node = mxmlFindElement(root, root, publish_xml_path, NULL, NULL, MXML_DESCEND);
  600. if (NULL != node) {
  601. oss_publish_urls_contents_parse(p, node, url_xml_path, publish_url_list);
  602. }
  603. node = mxmlFindElement(root, root, play_xml_path, NULL, NULL, MXML_DESCEND);
  604. if (NULL != node) {
  605. oss_play_urls_contents_parse(p, node, url_xml_path, play_url_list);
  606. }
  607. }
  608. int oss_create_live_channel_parse_from_body(aos_pool_t *p, aos_list_t *bc,
  609. aos_list_t *publish_url_list, aos_list_t *play_url_list)
  610. {
  611. int res;
  612. mxml_node_t *root = NULL;
  613. const char publish_urls_xml_path[] = "PublishUrls";
  614. const char play_urls_xml_path[] = "PlayUrls";
  615. res = get_xmldoc(bc, &root);
  616. if (res == AOSE_OK) {
  617. oss_create_live_channel_content_parse(p, root, publish_urls_xml_path, publish_url_list,
  618. play_urls_xml_path, play_url_list);
  619. mxmlDelete(root);
  620. }
  621. return res;
  622. }
  623. char *build_create_live_channel_xml(aos_pool_t *p, oss_live_channel_configuration_t *config)
  624. {
  625. char *xml_buff;
  626. char *complete_part_xml;
  627. aos_string_t xml_doc;
  628. mxml_node_t *doc;
  629. mxml_node_t *root_node;
  630. char value_str[64];
  631. mxml_node_t *description_node;
  632. mxml_node_t *status_node;
  633. mxml_node_t *target_node;
  634. mxml_node_t *type_node;
  635. mxml_node_t *frag_duration_node;
  636. mxml_node_t *frag_count_node;
  637. mxml_node_t *play_list_node;
  638. doc = mxmlNewXML("1.0");
  639. root_node = mxmlNewElement(doc, "LiveChannelConfiguration");
  640. description_node = mxmlNewElement(root_node, "Description");
  641. mxmlNewText(description_node, 0, config->description.data);
  642. status_node = mxmlNewElement(root_node, "Status");
  643. mxmlNewText(status_node, 0, config->status.data);
  644. // target
  645. target_node = mxmlNewElement(root_node, "Target");
  646. type_node = mxmlNewElement(target_node, "Type");
  647. mxmlNewText(type_node, 0, config->target.type.data);
  648. apr_snprintf(value_str, sizeof(value_str), "%d", config->target.frag_duration);
  649. frag_duration_node = mxmlNewElement(target_node, "FragDuration");
  650. mxmlNewText(frag_duration_node, 0, value_str);
  651. apr_snprintf(value_str, sizeof(value_str), "%d", config->target.frag_count);
  652. frag_count_node = mxmlNewElement(target_node, "FragCount");
  653. mxmlNewText(frag_count_node, 0, value_str);
  654. play_list_node = mxmlNewElement(target_node, "PlaylistName");
  655. mxmlNewText(play_list_node, 0, config->target.play_list_name.data);
  656. // dump
  657. xml_buff = new_xml_buff(doc);
  658. if (xml_buff == NULL) {
  659. return NULL;
  660. }
  661. aos_str_set(&xml_doc, xml_buff);
  662. complete_part_xml = aos_pstrdup(p, &xml_doc);
  663. free(xml_buff);
  664. mxmlDelete(doc);
  665. return complete_part_xml;
  666. }
  667. void build_create_live_channel_body(aos_pool_t *p, oss_live_channel_configuration_t *config, aos_list_t *body)
  668. {
  669. char *live_channel_xml;
  670. aos_buf_t *b;
  671. live_channel_xml = build_create_live_channel_xml(p, config);
  672. aos_list_init(body);
  673. b = aos_buf_pack(p, live_channel_xml, strlen(live_channel_xml));
  674. aos_list_add_tail(&b->node, body);
  675. }
  676. void oss_live_channel_info_target_content_parse(aos_pool_t *p, mxml_node_t *xml_node, oss_live_channel_target_t *target)
  677. {
  678. char *type;
  679. char *frag_duration;
  680. char *frag_count;
  681. char *play_list;
  682. char *node_content;
  683. mxml_node_t *node;
  684. node = mxmlFindElement(xml_node, xml_node, "Type", NULL, NULL, MXML_DESCEND);
  685. if (NULL != node) {
  686. node_content = node->child->value.opaque;
  687. type = apr_pstrdup(p, node_content);
  688. aos_str_set(&target->type, type);
  689. }
  690. node = mxmlFindElement(xml_node, xml_node, "FragDuration", NULL, NULL, MXML_DESCEND);
  691. if (NULL != node) {
  692. node_content = node->child->value.opaque;
  693. frag_duration = apr_pstrdup(p, node_content);
  694. target->frag_duration = atoi(frag_duration);
  695. }
  696. node = mxmlFindElement(xml_node, xml_node, "FragCount", NULL, NULL, MXML_DESCEND);
  697. if (NULL != node) {
  698. node_content = node->child->value.opaque;
  699. frag_count = apr_pstrdup(p, node_content);
  700. target->frag_count = atoi(frag_count);
  701. }
  702. node = mxmlFindElement(xml_node, xml_node, "PlaylistName",NULL, NULL,MXML_DESCEND);
  703. if (NULL != node) {
  704. node_content = node->child->value.opaque;
  705. play_list = apr_pstrdup(p, node_content);
  706. aos_str_set(&target->play_list_name, play_list);
  707. }
  708. }
  709. void oss_live_channel_info_content_parse(aos_pool_t *p, mxml_node_t *root, const char *xml_path,
  710. oss_live_channel_configuration_t *info)
  711. {
  712. mxml_node_t *cofig_node;
  713. mxml_node_t *target_node;
  714. cofig_node = mxmlFindElement(root, root, xml_path, NULL, NULL, MXML_DESCEND);
  715. if (NULL != cofig_node) {
  716. char *description;
  717. char *status;
  718. char *node_content;
  719. mxml_node_t *node;
  720. node = mxmlFindElement(cofig_node, cofig_node, "Description", NULL, NULL, MXML_DESCEND);
  721. if (NULL != node) {
  722. node_content = node->child->value.opaque;
  723. description = apr_pstrdup(p, node_content);
  724. aos_str_set(&info->description, description);
  725. }
  726. node = mxmlFindElement(cofig_node, cofig_node, "Status", NULL, NULL, MXML_DESCEND);
  727. if (NULL != node) {
  728. node_content = node->child->value.opaque;
  729. status = apr_pstrdup(p, node_content);
  730. aos_str_set(&info->status, status);
  731. }
  732. target_node = mxmlFindElement(cofig_node, cofig_node, "Target", NULL, NULL, MXML_DESCEND);
  733. if (NULL != target_node) {
  734. oss_live_channel_info_target_content_parse(p, target_node, &info->target);
  735. }
  736. }
  737. }
  738. int oss_live_channel_info_parse_from_body(aos_pool_t *p, aos_list_t *bc, oss_live_channel_configuration_t *info)
  739. {
  740. int res;
  741. mxml_node_t *root;
  742. const char xml_path[] = "LiveChannelConfiguration";
  743. res = get_xmldoc(bc, &root);
  744. if (res == AOSE_OK) {
  745. oss_live_channel_info_content_parse(p, root, xml_path, info);
  746. mxmlDelete(root);
  747. }
  748. return res;
  749. }
  750. void oss_live_channel_stat_video_content_parse(aos_pool_t *p, mxml_node_t *xml_node, oss_video_stat_t *video_stat)
  751. {
  752. char *width;
  753. char *height;
  754. char *frame_rate;
  755. char *band_width;
  756. char *codec;
  757. char *node_content;
  758. mxml_node_t *node;
  759. node = mxmlFindElement(xml_node, xml_node, "Width", NULL, NULL, MXML_DESCEND);
  760. if (NULL != node) {
  761. node_content = node->child->value.opaque;
  762. width = apr_pstrdup(p, node_content);
  763. video_stat->width = atoi(width);
  764. }
  765. node = mxmlFindElement(xml_node, xml_node, "Height", NULL, NULL, MXML_DESCEND);
  766. if (NULL != node) {
  767. node_content = node->child->value.opaque;
  768. height = apr_pstrdup(p, node_content);
  769. video_stat->height = atoi(height);
  770. }
  771. node = mxmlFindElement(xml_node, xml_node, "FrameRate", NULL, NULL, MXML_DESCEND);
  772. if (NULL != node) {
  773. node_content = node->child->value.opaque;
  774. frame_rate = apr_pstrdup(p, node_content);
  775. video_stat->frame_rate = atoi(frame_rate);
  776. }
  777. node = mxmlFindElement(xml_node, xml_node, "Bandwidth", NULL, NULL, MXML_DESCEND);
  778. if (NULL != node) {
  779. node_content = node->child->value.opaque;
  780. band_width = apr_pstrdup(p, node_content);
  781. video_stat->band_width = atoi(band_width);
  782. }
  783. node = mxmlFindElement(xml_node, xml_node, "Codec", NULL, NULL, MXML_DESCEND);
  784. if (NULL != node) {
  785. node_content = node->child->value.opaque;
  786. codec = apr_pstrdup(p, node_content);
  787. aos_str_set(&video_stat->codec, codec);
  788. }
  789. }
  790. void oss_live_channel_stat_audio_content_parse(aos_pool_t *p, mxml_node_t *xml_node, oss_audio_stat_t *audio_stat)
  791. {
  792. char *band_width;
  793. char *sample_rate;
  794. char *codec;
  795. char *node_content;
  796. mxml_node_t *node;
  797. node = mxmlFindElement(xml_node, xml_node, "Bandwidth", NULL, NULL, MXML_DESCEND);
  798. if (NULL != node) {
  799. node_content = node->child->value.opaque;
  800. band_width = apr_pstrdup(p, node_content);
  801. audio_stat->band_width = atoi(band_width);
  802. }
  803. node = mxmlFindElement(xml_node, xml_node, "SampleRate", NULL, NULL, MXML_DESCEND);
  804. if (NULL != node) {
  805. node_content = node->child->value.opaque;
  806. sample_rate = apr_pstrdup(p, node_content);
  807. audio_stat->sample_rate = atoi(sample_rate);
  808. }
  809. node = mxmlFindElement(xml_node, xml_node, "Codec", NULL, NULL, MXML_DESCEND);
  810. if (NULL != node) {
  811. node_content = node->child->value.opaque;
  812. codec = apr_pstrdup(p, node_content);
  813. aos_str_set(&audio_stat->codec, codec);
  814. }
  815. }
  816. void oss_live_channel_stat_content_parse(aos_pool_t *p, mxml_node_t *root, const char *xml_path, oss_live_channel_stat_t *stat)
  817. {
  818. mxml_node_t *stat_node;
  819. stat_node = mxmlFindElement(root, root, xml_path, NULL, NULL, MXML_DESCEND);
  820. if (NULL != stat_node) {
  821. char *status;
  822. char *connected_time;
  823. char *remote_addr;
  824. char *node_content;
  825. mxml_node_t *node;
  826. node = mxmlFindElement(stat_node, stat_node, "Status", NULL, NULL, MXML_DESCEND);
  827. if (NULL != node) {
  828. node_content = node->child->value.opaque;
  829. status = apr_pstrdup(p, (char *)node_content);
  830. aos_str_set(&stat->pushflow_status, status);
  831. }
  832. node = mxmlFindElement(stat_node, stat_node, "ConnectedTime", NULL, NULL, MXML_DESCEND);
  833. if (NULL != node) {
  834. node_content = node->child->value.opaque;
  835. connected_time = apr_pstrdup(p, (char *)node_content);
  836. aos_str_set(&stat->connected_time, connected_time);
  837. }
  838. node = mxmlFindElement(stat_node, stat_node, "RemoteAddr", NULL, NULL, MXML_DESCEND);
  839. if (NULL != node) {
  840. node_content = node->child->value.opaque;
  841. remote_addr = apr_pstrdup(p, (char *)node_content);
  842. aos_str_set(&stat->remote_addr, remote_addr);
  843. }
  844. node = mxmlFindElement(stat_node, stat_node, "Video", NULL, NULL, MXML_DESCEND);
  845. if (NULL != node) {
  846. oss_live_channel_stat_video_content_parse(p, node, &stat->video_stat);
  847. }
  848. node = mxmlFindElement(stat_node, stat_node, "Audio", NULL, NULL, MXML_DESCEND);
  849. if (NULL != node) {
  850. oss_live_channel_stat_audio_content_parse(p, node, &stat->audio_stat);
  851. }
  852. }
  853. }
  854. int oss_live_channel_stat_parse_from_body(aos_pool_t *p, aos_list_t *bc, oss_live_channel_stat_t *stat)
  855. {
  856. int res;
  857. mxml_node_t *root;
  858. const char xml_path[] = "LiveChannelStat";
  859. res = get_xmldoc(bc, &root);
  860. if (res == AOSE_OK) {
  861. oss_live_channel_stat_content_parse(p, root, xml_path, stat);
  862. mxmlDelete(root);
  863. }
  864. return res;
  865. }
  866. void oss_list_live_channel_content_parse(aos_pool_t *p, mxml_node_t *xml_node, oss_live_channel_content_t *content)
  867. {
  868. char *name;
  869. char *description;
  870. char *status;
  871. char *last_modified;
  872. char *node_content;
  873. mxml_node_t *node;
  874. node = mxmlFindElement(xml_node, xml_node, "Name", NULL, NULL, MXML_DESCEND);
  875. if (NULL != node) {
  876. node_content = node->child->value.opaque;
  877. name = apr_pstrdup(p, (char *)node_content);
  878. aos_str_set(&content->name, name);
  879. }
  880. node = mxmlFindElement(xml_node, xml_node, "Description", NULL, NULL, MXML_DESCEND);
  881. if (NULL != node) {
  882. if (NULL != node->child) {
  883. node_content = node->child->value.opaque;
  884. description = apr_pstrdup(p, (char *)node_content);
  885. aos_str_set(&content->description, description);
  886. } else {
  887. aos_str_set(&content->description, "");
  888. }
  889. }
  890. node = mxmlFindElement(xml_node, xml_node, "Status", NULL, NULL, MXML_DESCEND);
  891. if (NULL != node) {
  892. node_content = node->child->value.opaque;
  893. status = apr_pstrdup(p, (char *)node_content);
  894. aos_str_set(&content->status, status);
  895. }
  896. node = mxmlFindElement(xml_node, xml_node, "LastModified", NULL, NULL, MXML_DESCEND);
  897. if (NULL != node) {
  898. node_content = node->child->value.opaque;
  899. last_modified = apr_pstrdup(p, (char *)node_content);
  900. aos_str_set(&content->last_modified, last_modified);
  901. }
  902. node = mxmlFindElement(xml_node, xml_node, "PublishUrls", NULL, NULL, MXML_DESCEND);
  903. if (NULL != node) {
  904. oss_publish_urls_contents_parse(p, node, "Url", &content->publish_url_list);
  905. }
  906. node = mxmlFindElement(xml_node, xml_node, "PlayUrls", NULL, NULL, MXML_DESCEND);
  907. if (NULL != node) {
  908. oss_play_urls_contents_parse(p, node, "Url", &content->play_url_list);
  909. }
  910. }
  911. void oss_list_live_channel_contents_parse(aos_pool_t *p, mxml_node_t *root, const char *xml_path,
  912. aos_list_t *live_channel_list)
  913. {
  914. mxml_node_t *content_node;
  915. oss_live_channel_content_t *content;
  916. content_node = mxmlFindElement(root, root, xml_path, NULL, NULL, MXML_DESCEND);
  917. for ( ; content_node != NULL; ) {
  918. content = oss_create_list_live_channel_content(p);
  919. oss_list_live_channel_content_parse(p, content_node, content);
  920. aos_list_add_tail(&content->node, live_channel_list);
  921. content_node = mxmlFindElement(content_node, root, xml_path, NULL, NULL, MXML_DESCEND);
  922. }
  923. }
  924. int oss_list_live_channel_parse_from_body(aos_pool_t *p, aos_list_t *bc,
  925. aos_list_t *live_channel_list, aos_string_t *next_marker, int *truncated)
  926. {
  927. int res;
  928. mxml_node_t *root;
  929. const char next_marker_xml_path[] = "NextMarker";
  930. const char truncated_xml_path[] = "IsTruncated";
  931. const char live_channel_xml_path[] = "LiveChannel";
  932. char *next_partnumber_marker;
  933. res = get_xmldoc(bc, &root);
  934. if (res == AOSE_OK) {
  935. next_partnumber_marker = get_xmlnode_value(p, root, next_marker_xml_path);
  936. if (next_partnumber_marker) {
  937. aos_str_set(next_marker, next_partnumber_marker);
  938. }
  939. *truncated = get_truncated_from_xml(p, root, truncated_xml_path);
  940. oss_list_live_channel_contents_parse(p, root, live_channel_xml_path, live_channel_list);
  941. mxmlDelete(root);
  942. }
  943. return res;
  944. }
  945. void oss_live_channel_history_content_parse(aos_pool_t *p, mxml_node_t * xml_node,
  946. oss_live_record_content_t *content)
  947. {
  948. char *start_time;
  949. char *end_time;
  950. char *remote_addr;
  951. char *node_content;
  952. mxml_node_t *node;
  953. node = mxmlFindElement(xml_node, xml_node, "StartTime",NULL, NULL, MXML_DESCEND);
  954. if (NULL != node) {
  955. node_content = node->child->value.opaque;
  956. start_time = apr_pstrdup(p, (char *)node_content);
  957. aos_str_set(&content->start_time, start_time);
  958. }
  959. node = mxmlFindElement(xml_node, xml_node, "EndTime",NULL, NULL,MXML_DESCEND);
  960. if (NULL != node) {
  961. node_content = node->child->value.opaque;
  962. end_time = apr_pstrdup(p, (char *)node_content);
  963. aos_str_set(&content->end_time, end_time);
  964. }
  965. node = mxmlFindElement(xml_node, xml_node, "RemoteAddr",NULL, NULL,MXML_DESCEND);
  966. if (NULL != node) {
  967. node_content = node->child->value.opaque;
  968. remote_addr = apr_pstrdup(p, (char *)node_content);
  969. aos_str_set(&content->remote_addr, remote_addr);
  970. }
  971. }
  972. void oss_live_channel_history_contents_parse(aos_pool_t *p, mxml_node_t *root, const char *xml_path,
  973. aos_list_t *live_record_list)
  974. {
  975. mxml_node_t *node;
  976. oss_live_record_content_t *content;
  977. node = mxmlFindElement(root, root, xml_path, NULL, NULL, MXML_DESCEND);
  978. for ( ; node != NULL; ) {
  979. content = oss_create_live_record_content(p);
  980. oss_live_channel_history_content_parse(p, node, content);
  981. aos_list_add_tail(&content->node, live_record_list);
  982. node = mxmlFindElement(node, root, xml_path, NULL, NULL, MXML_DESCEND);
  983. }
  984. }
  985. int oss_live_channel_history_parse_from_body(aos_pool_t *p, aos_list_t *bc, aos_list_t *live_record_list)
  986. {
  987. int res;
  988. mxml_node_t *root = NULL;
  989. const char rule_xml_path[] = "LiveRecord";
  990. res = get_xmldoc(bc, &root);
  991. if (res == AOSE_OK) {
  992. oss_live_channel_history_contents_parse(p, root, rule_xml_path, live_record_list);
  993. mxmlDelete(root);
  994. }
  995. return res;
  996. }
  997. char *build_objects_xml(aos_pool_t *p, aos_list_t *object_list, const char *quiet)
  998. {
  999. char *object_xml;
  1000. char *xml_buff;
  1001. aos_string_t xml_doc;
  1002. mxml_node_t *doc;
  1003. mxml_node_t *root_node;
  1004. oss_object_key_t *content;
  1005. mxml_node_t *quiet_node;
  1006. doc = mxmlNewXML("1.0");
  1007. root_node = mxmlNewElement(doc, "Delete");
  1008. quiet_node = mxmlNewElement(root_node, "Quiet");
  1009. mxmlNewText(quiet_node, 0, quiet);
  1010. aos_list_for_each_entry(oss_object_key_t, content, object_list, node) {
  1011. mxml_node_t *object_node = mxmlNewElement(root_node, "Object");
  1012. mxml_node_t *key_node = mxmlNewElement(object_node, "Key");
  1013. mxmlNewText(key_node, 0, content->key.data);
  1014. }
  1015. xml_buff = new_xml_buff(doc);
  1016. if (xml_buff == NULL) {
  1017. return NULL;
  1018. }
  1019. aos_str_set(&xml_doc, xml_buff);
  1020. object_xml = aos_pstrdup(p, &xml_doc);
  1021. free(xml_buff);
  1022. mxmlDelete(doc);
  1023. return object_xml;
  1024. }
  1025. void build_delete_objects_body(aos_pool_t *p, aos_list_t *object_list, int is_quiet, aos_list_t *body)
  1026. {
  1027. char *objects_xml;
  1028. aos_buf_t *b;
  1029. char *quiet;
  1030. quiet = is_quiet > 0 ? "true": "false";
  1031. objects_xml = build_objects_xml(p, object_list, quiet);
  1032. aos_list_init(body);
  1033. b = aos_buf_pack(p, objects_xml, strlen(objects_xml));
  1034. aos_list_add_tail(&b->node, body);
  1035. }
  1036. mxml_node_t *set_xmlnode_value_str(mxml_node_t *parent, const char *name, const aos_string_t *value)
  1037. {
  1038. mxml_node_t *node;
  1039. char buff[AOS_MAX_XML_NODE_VALUE_LEN];
  1040. node = mxmlNewElement(parent, name);
  1041. apr_snprintf(buff, AOS_MAX_XML_NODE_VALUE_LEN, "%.*s", value->len, value->data);
  1042. return mxmlNewText(node, 0, buff);
  1043. }
  1044. mxml_node_t *set_xmlnode_value_int(mxml_node_t *parent, const char *name, int value)
  1045. {
  1046. mxml_node_t *node;
  1047. char buff[AOS_MAX_INT64_STRING_LEN];
  1048. node = mxmlNewElement(parent, name);
  1049. apr_snprintf(buff, AOS_MAX_INT64_STRING_LEN, "%d", value);
  1050. return mxmlNewText(node, 0, buff);
  1051. }
  1052. mxml_node_t *set_xmlnode_value_int64(mxml_node_t *parent, const char *name, int64_t value)
  1053. {
  1054. mxml_node_t *node;
  1055. char buff[AOS_MAX_INT64_STRING_LEN];
  1056. node = mxmlNewElement(parent, name);
  1057. apr_snprintf(buff, AOS_MAX_INT64_STRING_LEN, "%" APR_INT64_T_FMT, value);
  1058. return mxmlNewText(node, 0, buff);
  1059. }
  1060. int get_xmlnode_value_str(aos_pool_t *p, mxml_node_t *xml_node, const char *xml_path, aos_string_t *value)
  1061. {
  1062. char *node_content;
  1063. node_content = get_xmlnode_value(p, xml_node, xml_path);
  1064. if (NULL == node_content) {
  1065. return AOS_FALSE;
  1066. }
  1067. aos_str_set(value, node_content);
  1068. return AOS_TRUE;
  1069. }
  1070. int get_xmlnode_value_int(aos_pool_t *p, mxml_node_t *xml_node, const char *xml_path, int *value)
  1071. {
  1072. char *node_content;
  1073. node_content = get_xmlnode_value(p, xml_node, xml_path);
  1074. if (NULL == node_content) {
  1075. return AOS_FALSE;
  1076. }
  1077. *value = atoi(node_content);
  1078. return AOS_TRUE;
  1079. }
  1080. int get_xmlnode_value_int64(aos_pool_t *p, mxml_node_t *xml_node, const char *xml_path, int64_t *value)
  1081. {
  1082. char *node_content;
  1083. node_content = get_xmlnode_value(p, xml_node, xml_path);
  1084. if (NULL == node_content) {
  1085. return AOS_FALSE;
  1086. }
  1087. *value = aos_atoi64(node_content);
  1088. return AOS_TRUE;
  1089. }
  1090. char *oss_build_checkpoint_xml(aos_pool_t *p, const oss_checkpoint_t *checkpoint)
  1091. {
  1092. char *checkpoint_xml;
  1093. char *xml_buff;
  1094. aos_string_t xml_doc;
  1095. mxml_node_t *doc;
  1096. mxml_node_t *root_node;
  1097. mxml_node_t *local_node;
  1098. mxml_node_t *object_node;
  1099. mxml_node_t *cpparts_node;
  1100. mxml_node_t *parts_node;
  1101. int i = 0;
  1102. doc = mxmlNewXML("1.0");
  1103. root_node = mxmlNewElement(doc, "Checkpoint");
  1104. // MD5
  1105. set_xmlnode_value_str(root_node, "MD5", &checkpoint->md5);
  1106. // Type
  1107. set_xmlnode_value_int(root_node, "Type", checkpoint->cp_type);
  1108. // LocalFile
  1109. local_node = mxmlNewElement(root_node, "LocalFile");
  1110. // LocalFile.Path
  1111. set_xmlnode_value_str(local_node, "Path", &checkpoint->file_path);
  1112. // LocalFile.Size
  1113. set_xmlnode_value_int64(local_node, "Size", checkpoint->file_size);
  1114. // LocalFile.LastModified
  1115. set_xmlnode_value_int64(local_node, "LastModified", checkpoint->file_last_modified);
  1116. // LocalFile.MD5
  1117. set_xmlnode_value_str(local_node, "MD5", &checkpoint->file_md5);
  1118. // Object
  1119. object_node = mxmlNewElement(root_node, "Object");
  1120. // Object.Key
  1121. set_xmlnode_value_str(object_node, "Key", &checkpoint->object_name);
  1122. // Object.Size
  1123. set_xmlnode_value_int64(object_node, "Size", checkpoint->object_size);
  1124. // Object.LastModified
  1125. set_xmlnode_value_str(object_node, "LastModified", &checkpoint->object_last_modified);
  1126. // Object.ETag
  1127. set_xmlnode_value_str(object_node, "ETag", &checkpoint->object_etag);
  1128. // UploadId
  1129. set_xmlnode_value_str(root_node, "UploadId", &checkpoint->upload_id);
  1130. // CpParts
  1131. cpparts_node = mxmlNewElement(root_node, "CPParts");
  1132. // CpParts.Number
  1133. set_xmlnode_value_int(cpparts_node, "Number", checkpoint->part_num);
  1134. // CpParts.Size
  1135. set_xmlnode_value_int64(cpparts_node, "Size", checkpoint->part_size);
  1136. // CpParts.Parts
  1137. parts_node = mxmlNewElement(cpparts_node, "Parts");
  1138. for (i = 0; i < checkpoint->part_num; i++) {
  1139. mxml_node_t *part_node = mxmlNewElement(parts_node, "Part");
  1140. set_xmlnode_value_int(part_node, "Index", checkpoint->parts[i].index);
  1141. set_xmlnode_value_int64(part_node, "Offset", checkpoint->parts[i].offset);
  1142. set_xmlnode_value_int64(part_node, "Size", checkpoint->parts[i].size);
  1143. set_xmlnode_value_int(part_node, "Completed", checkpoint->parts[i].completed);
  1144. set_xmlnode_value_str(part_node, "ETag", &checkpoint->parts[i].etag);
  1145. }
  1146. // dump
  1147. xml_buff = new_xml_buff(doc);
  1148. if (xml_buff == NULL) {
  1149. return NULL;
  1150. }
  1151. aos_str_set(&xml_doc, xml_buff);
  1152. checkpoint_xml = aos_pstrdup(p, &xml_doc);
  1153. free(xml_buff);
  1154. mxmlDelete(doc);
  1155. return checkpoint_xml;
  1156. }
  1157. int oss_checkpoint_parse_from_body(aos_pool_t *p, const char *xml_body, oss_checkpoint_t *checkpoint)
  1158. {
  1159. mxml_node_t *root;
  1160. mxml_node_t *local_node;
  1161. mxml_node_t *object_node;
  1162. mxml_node_t *cpparts_node;
  1163. mxml_node_t *parts_node;
  1164. mxml_node_t *node;
  1165. int index = 0;
  1166. root = mxmlLoadString(NULL, xml_body, MXML_OPAQUE_CALLBACK);
  1167. if (NULL == root) {
  1168. return AOSE_XML_PARSE_ERROR;
  1169. }
  1170. // MD5
  1171. get_xmlnode_value_str(p, root, "MD5", &checkpoint->md5);
  1172. // Type
  1173. get_xmlnode_value_int(p, root, "Type", &checkpoint->cp_type);
  1174. // LocalFile
  1175. local_node = mxmlFindElement(root, root, "LocalFile", NULL, NULL, MXML_DESCEND);
  1176. // LocalFile.Path
  1177. get_xmlnode_value_str(p, local_node, "Path", &checkpoint->file_path);
  1178. // LocalFile.Size
  1179. get_xmlnode_value_int64(p, local_node, "Size", &checkpoint->file_size);
  1180. // LocalFile.LastModified
  1181. get_xmlnode_value_int64(p, local_node, "LastModified", &checkpoint->file_last_modified);
  1182. // LocalFile.MD5
  1183. get_xmlnode_value_str(p, local_node, "MD5", &checkpoint->file_md5);
  1184. // Object
  1185. object_node = mxmlFindElement(root, root, "Object", NULL, NULL, MXML_DESCEND);
  1186. // Object.Key
  1187. get_xmlnode_value_str(p, object_node, "Key", &checkpoint->object_name);
  1188. // Object.Size
  1189. get_xmlnode_value_int64(p, object_node, "Size", &checkpoint->object_size);
  1190. // Object.LastModified
  1191. get_xmlnode_value_str(p, object_node, "LastModified", &checkpoint->object_last_modified);
  1192. // Object.ETag
  1193. get_xmlnode_value_str(p, object_node, "ETag", &checkpoint->object_etag);
  1194. // UploadId
  1195. get_xmlnode_value_str(p, root, "UploadId", &checkpoint->upload_id);
  1196. // CpParts
  1197. cpparts_node = mxmlFindElement(root, root, "CPParts", NULL, NULL, MXML_DESCEND);
  1198. // CpParts.Number
  1199. get_xmlnode_value_int(p, cpparts_node, "Number", &checkpoint->part_num);
  1200. // CpParts.Size
  1201. get_xmlnode_value_int64(p, cpparts_node, "Size", &checkpoint->part_size);
  1202. // CpParts.Parts
  1203. parts_node = mxmlFindElement(cpparts_node, cpparts_node, "Parts", NULL, NULL, MXML_DESCEND);
  1204. node = mxmlFindElement(parts_node, parts_node, "Part", NULL, NULL, MXML_DESCEND);
  1205. for ( ; node != NULL; ) {
  1206. get_xmlnode_value_int(p, node, "Index", &index);
  1207. checkpoint->parts[index].index = index;
  1208. get_xmlnode_value_int64(p, node, "Offset", &checkpoint->parts[index].offset);
  1209. get_xmlnode_value_int64(p, node, "Size", &checkpoint->parts[index].size);
  1210. get_xmlnode_value_int(p, node, "Completed", &checkpoint->parts[index].completed);
  1211. get_xmlnode_value_str(p, node, "ETag", &checkpoint->parts[index].etag);
  1212. node = mxmlFindElement(node, parts_node, "Part", NULL, NULL, MXML_DESCEND);
  1213. }
  1214. mxmlDelete(root);
  1215. return AOSE_OK;
  1216. }