DLAgentSrvOMA.c 187 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076
/*****************************************************************************
*  Copyright Statement:
*  --------------------
*  This software is protected by Copyright and the information contained
*  herein is confidential. The software may not be copied and the information
*  contained herein may not be used or disclosed except with the written
*  permission of MediaTek Inc. (C) 2005
*
*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
*
*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
*
*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
*
*****************************************************************************/
/*****************************************************************************
 *
 * Filename:
 * ---------
 *
 *
 * Project:
 * --------
 *  MAUI
 *
 * Description:
 * ------------
 *
 *
 * Author:
 * -------
 * -------
 *
 *============================================================================
 *             HISTORY
 * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
 *------------------------------------------------------------------------------
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *------------------------------------------------------------------------------
 * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
 *============================================================================
 ****************************************************************************/

/****************************************************************************
* Include Files                                                                
*****************************************************************************/

#include "MMI_include.h"

#if defined (__MMI_DOWNLOAD_AGENT__)

#include "CommonScreens.h"
//#include "ProtocolEvents.h"
#include "app_mine.h"
#include "drm_def.h"
#include "DLAgentSrvDef.h"
#include "DLAgentSrvGprot.h"
#include "DLAgentSrvIProt.h"
#include "DLAgentSrvProt.h"
#ifdef __MMI_DOWNLOAD_AGENT__
#include "mmi_rp_srv_downloadagent_def.h"
#endif
#include "DLAgentSrvWPS.h"
#include "DLAgentSrvOMA.h"
//#include "XML_def.h"
#include "das_struct.h"                 /* WAP_DL_MAX_URL_LEN */
//#include "SettingDefs.h"                /* ST_NOTIFICATION */
//#include "PhoneBookDef.h"               /* IMG_PROCESSING_PHONEBOOK */
//#include "Wap_ps_struct.h"
//#include "Wapadp.h"
//#include "wgui_categories_inputs.h"    /* INPUT_TYPE_USE_ONLY_ENGLISH_MODES */
#include "Conversions.h"
//#include "FileMgr.h"
//#include "FileManagerGProt.h"           /* PUBLIC PRIVATE DRV */
//#include "FileManagerDef.h"             /*FMGR_FS_ACCESS_DENIED_TEXT*/
#include "FileMgrSrvGprot.h"
#include "Drm_gprot.h"


    #include "MMIDataType.h"
    #include "kal_general_types.h"
    #include "MMI_features.h"
    #include "wps_struct.h"
    #include "string.h"
    #include "kal_public_api.h"
    #include "DebugInitDef_Int.h"
    #include "mmi_frm_mem_gprot.h"
    #include "Unicodexdcl.h"
    #include "app_str.h"
    #include "GlobalResDef.h"
    #include "CustDataRes.h"
    #include "mmi_rp_srv_downloadagent_def.h"
    #include "mmi_frm_events_gprot.h"
    #include "mmi_frm_input_gprot.h"
    #include "mmi_frm_history_gprot.h"
    #include "CustMenuRes.h"
    #include "wgui_categories_util.h"
    #include "wgui_categories_list.h"
    #include "GlobalConstants.h"
    #include "fs_type.h"
    #include "fs_func.h"
    #include "wgui_categories_text_viewer.h"
    #include "browser_api.h"
    #include "MMI_conn_app_trc.h"
    #include "mmi_conn_app_trc.h"
    #include "kal_trace.h"
    #include "fs_errcode.h"
    #include "FileMgrType.h"
    #include "mmi_rp_file_type_def.h"

/****************************************************************************
* Define
*****************************************************************************/

#if !defined(__MMI_FMGR_CUSTICON_SUPPORT__) && defined(__MMI_DA_OMA_ICONURI_SUPPORT__)
/* __MMI_DA_OMA_ICONURI_SUPPORTED__ depends on  __MMI_FMGR_CUSTICON_SUPPORT__ */
#undef __MMI_DA_OMA_ICONURI_SUPPORT__
#endif

#if defined(__MMI_OMA_DD_DOWNLOAD__)
/****************************************************************************
* Define - Macro
*****************************************************************************/


    

/****************************************************************************
* Typedef - Struct
*****************************************************************************/


typedef struct
{
    srv_da_job_struct   *curr_job;
} srv_da_oma_context_struct;


/****************************************************************************
* Static Variable
*****************************************************************************/

static srv_da_oma_context_struct da_oma_context;
#ifdef __MMI_DA_USER_SELECT_DOWNLOAD_LOCATION__
static MMI_BOOL da_storage_selection;
#endif /* __MMI_DA_USER_SELECT_DOWNLOAD_LOCATION__ */

/****************************************************************************
* Global Variable
*****************************************************************************/

static void srv_da_oma_init_module(void);
static void srv_da_oma_get_name(const srv_da_job_struct *job, U16 *buffer, U32 buffer_len);
static const U16* srv_da_oma_get_item_filepath(const srv_da_job_struct* job);
static U32  srv_da_oma_get_item_progress(const srv_da_job_struct* job, srv_da_item_progress_struct *info);
static U16 srv_da_oma_get_job_id(const srv_da_job_struct* job);
void srv_da_oma_get_setting(const srv_da_job_struct *job, srv_da_setting_struct *setting_data);
static MMI_BOOL srv_da_oma_is_object_desc_available(const srv_da_job_struct* job);
static void srv_da_oma_get_object_desc(
    const srv_da_job_struct *job,
    U16* string_buffer,
    const U32 buffer_len);
static void srv_da_oma_get_item_status_desc(
    const srv_da_job_struct *job,
    U16 *string_buffer[],       /* string_buffer[num_of_buffers] */
    const U32 buffer_len,       /* Max length per buffer */
    const U32 num_of_buffers,   /* Number of buffers */
    U32 *num_of_filled);
static const S8* srv_da_oma_get_infoURL(const srv_da_job_struct* job);
static MMI_BOOL srv_da_oma_free_job(srv_da_job_struct* job);
static void srv_da_oma_abort_job(srv_da_job_struct* job, S32 prev_state, MMI_BOOL pauseOnly,
                                  srv_da_abort_callback_type end_callback);
static void srv_da_oma_dispatch_job(const srv_da_job_struct* job);
static void srv_da_oma_assign_filepath(srv_da_job_struct* job, const U16* new_filepath);
#if defined(__MMI_DOWNLOAD_AGENT_MULTI_DL__) && defined(__MMI_DA_RESUME__)
static void srv_da_oma_resume_job(srv_da_job_struct* job);
#endif
#ifdef __MMI_DA_RESUME__
static void srv_da_oma_auto_resume_try_to_resume(void *arg, S32 unique_id);
#endif
void srv_da_oma_select_storage(srv_da_job_struct *job);

const srv_da_module_funcptr_table srv_da_oma_module =
{
    srv_da_oma_init_module

    ,srv_da_oma_get_name
    ,srv_da_oma_get_item_filepath
    ,srv_da_oma_get_item_progress
    ,srv_da_oma_get_job_id
    ,srv_da_oma_get_setting
    ,srv_da_oma_is_object_desc_available
    ,srv_da_oma_get_object_desc
    ,srv_da_oma_get_item_status_desc
    ,srv_da_oma_get_infoURL

    ,srv_da_oma_free_job
    ,srv_da_oma_abort_job
    ,srv_da_oma_dispatch_job
    ,srv_da_oma_assign_filepath
    
#if defined(__MMI_DOWNLOAD_AGENT_MULTI_DL__) && defined(__MMI_DA_RESUME__)
    ,srv_da_oma_resume_job
#endif    
};


/****************************************************************************
* Function Forward Declaration
*****************************************************************************/

static void srv_da_oma_parse_dd_and_show_confirm(srv_da_job_struct *job);
void srv_da_oma_session_created_callback(MMI_BOOL success, U32 arg);
void srv_da_oma_http_response_callback(
    U32 arg,
    U8 result,
    U16 status,
    S8 *header,
    S8 *content_type,
    U32 content_len,
    const wps_http_rsp_struct *rsp);
void srv_da_oma_session_dl_progress_callback(U32 arg, U8 status, U32 curr_size, S32 cause);


/* iconURI */
static void srv_da_oma_icon_terminate_download(
                srv_da_job_struct *job,
                srv_da_oma_icon_state_enum next_icon_state);
static void srv_da_oma_icon_register_for_job(srv_da_job_struct* job);
static void srv_da_oma_icon_register_for_file(srv_da_oma_icon_struct* icon, U16 *filepath);

#ifdef __MMI_DA_OMA_ICONURI_SUPPORT__
static void srv_da_oma_icon_start_download(srv_da_job_struct* job);
static void srv_da_oma_icon_trigger_next_procedure(srv_da_job_struct *job);
static void srv_da_oma_icon_session_created_callback(MMI_BOOL success, U32 arg);
static void srv_da_oma_icon_session_http_response_callback(
                U32 arg,
                U8 result,
                U16 status,
                S8 *header,
                S8 *content_type,
                U32 content_len,
                const wps_http_rsp_struct *rsp);
static void srv_da_oma_icon_session_http_auth_ind_callback(U32 arg);
static void srv_da_oma_icon_session_dl_progress_callback(U32 arg, U8 status, U32 curr_size, S32 cause);
#endif

static void srv_da_oma_send_install_noti_result_callback(
    void *arg,
    srv_da_oma_send_report_result_enum result,
    U32 status);

void srv_da_oma_open_nextURL(srv_da_job_struct *job);
void srv_da_oma_cancel_download(void *arg, MMI_BOOL is_deleted);

/* UI related */


/* Tool API */
static void srv_da_oma_close_session(srv_da_job_struct* job);
MMI_BOOL srv_da_oma_popup_and_send_report(srv_da_job_struct *job, S32 error, MMI_BOOL end_job, MMI_BOOL bpopup);

#ifdef __DRM_SUPPORT__
static void srv_da_oma_drm_process(srv_da_job_struct *job);
#endif                                            

#if defined(__MMI_DOWNLOAD_AGENT_MULTI_DL__) && defined(__MMI_DA_RESUME__)
/* Resume */
static void srv_da_oma_resume_session_created_callback(MMI_BOOL success, U32 arg);
static void srv_da_oma_resume_http_auth_ind_callback(U32 arg);
static void srv_da_oma_resume_cancel_callback(void *arg, MMI_BOOL is_deleted);
#endif


#define END_OF_FUNCTION_DECLARATION
/****************************************************************************
* Function Section
*****************************************************************************/

/*****************************************************************************
* FUNCTION
*   srv_da_oma_init_module
* DESCRIPTION
* PARAMETERS
* RETURNS
*   void
*****************************************************************************/
static void srv_da_oma_init_module(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/

    da_oma_context.curr_job = NULL;
}

/*****************************************************************************
* FUNCTION
*   srv_da_oma_dd_setting
* DESCRIPTION
*   When the file is downloaded from WAP browser, we set it as oma download
*   else, we save it to file system only.
* PARAMETERS
* RETURNS
*   void
*****************************************************************************/
void srv_da_oma_dd_setting(
    S32 session_id,
    S32 mime_type,                  /* applib_mime_type_enum */
    S32 mime_subtype,               /* applib_mime_subtype_enum */
	S32 action,
    U32 filesize,
    S8  *url,                        /* WAP_DL_MAX_URL_LEN */
    S8  *mime_type_string,           /* WAP_DL _MAX_MIME_TYPE_LEN */
    U32 content_len,
    S8  *content,
    srv_da_setting_struct * setting)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/

    if( action == MMI_DA_WAP_DOWNLOAD ) /* OMA DL */
    {
        srv_da_bypass_setting(
            session_id, mime_type, mime_subtype, action,
            filesize, url, mime_type_string, content_len,
            content, setting);
        setting->can_minimize = MMI_FALSE;
    }
    else    /* treat this as normal file, dont dispatch */
    {
        srv_da_default_setting(
            session_id, mime_type, mime_subtype, action,
            filesize, url, mime_type_string, content_len,
            content, setting);
        setting->do_dispatch = MMI_FALSE;
    }

}


/*****************************************************************************
 * FUNCTION
 *  srv_da_oma_dd_presetting
 * DESCRIPTION
 *  Set the presetting to default values.
 * PARAMETERS
 *  param       [IN]  Parameters to determine pre-setting
 *  presetting  [OUT] Pre-setting
 * RETURNS
 *  void
 *****************************************************************************/
void srv_da_oma_dd_presetting(
    const srv_da_presetting_param_struct *param,
    srv_da_presetting_struct *presetting)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/

    /* Start to download without confirmation */
    presetting->confirm_download = MMI_FALSE;

    /* Not need content to determine setting */
    presetting->need_content = MMI_FALSE;
}


/*****************************************************************************
* FUNCTION
* DESCRIPTION
* PARAMETERS
* RETURNS
*****************************************************************************/
static MMI_BOOL srv_da_oma_job_match_dd_func(const srv_da_job_struct* job, U32 criteria)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_omadl_job_struct               *job_data;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/

    
    if(job->type != SRV_DA_JOB_TYPE_OMADL)
        return MMI_FALSE;
        
    job_data = (srv_da_omadl_job_struct*)job->data_ptr;
    if(!job_data)
        return MMI_FALSE;
    
    if(strcmp((S8*)criteria, job_data->dd_url) == 0)
    {
        return MMI_TRUE;
    }

    return MMI_FALSE;
}

/*****************************************************************************
* FUNCTION
* DESCRIPTION
* PARAMETERS
* RETURNS
*****************************************************************************/
srv_da_job_struct* srv_da_oma_find_job_by_dd(S8* dd_url)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    return srv_da_find_job(srv_da_oma_job_match_dd_func, (U32)dd_url);
}


/*****************************************************************************
 * FUNCTION
 *  srv_da_oma_get_new_unique_id
 * DESCRIPTION
 *  Allocate a unique ID
 * PARAMETERS
 *  void
 * RETURNS
 *  An unique ID
 *****************************************************************************/
U16 srv_da_oma_get_new_unique_id(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    static U16 next_id = 0;
    U16 return_id;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/

    return_id = next_id;
    next_id = (next_id + 1) & 0x7fff;

    return return_id;
}

#define PROCESS_DD

/*************************************************************************
* FUNCTION
*   srv_da_oma_process_dd_file
* DESCRIPTION
*   Start to handle dd file
* PARAMETERS
*   mime_type   [IN]    the mime type of file
*   mime_subtype[IN]    the sub mime type of file
*   action_type [IN]    defined in Download agent
*   filename    [IN]    the filepath of file
*   download_url[IN]    the source of file, normally is a link
*   mime_type_string    [IN]    the originaly mime type string get from server
* RETURNS
*   void
*************************************************************************/
void srv_da_oma_process_dd_file(S32 session_id, S32 mime_type, S32 mime_subtype,
                                S32 action_type, PU16 filename, PS8 download_url,
                                PS8 mime_type_string)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_job_struct           *job;
    srv_da_omadl_job_struct     *job_data;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/

    /* parse message & allocate a new job */
    job = srv_da_job_create_ex(SRV_DA_JOB_TYPE_OMADL, NULL);
    if (!job)
    {
#ifdef __MMI_DOWNLOAD_AGENT_MULTI_DL__
        /* 1. there is another job setuping, 2. no memory */
        switch(srv_da_get_last_error())
        {
        case SRV_DA_IERROR_EXCEED_MAX_JOB:
        case SRV_DA_IERROR_EXCEED_MAX_DL:
            MMI_ASSERT(0);
            break;

        default:
            break;
        }
#endif
        srv_da_oma_popup_and_send_report(NULL, SRV_DA_OMA_DEVICE_ABORTED, MMI_TRUE, MMI_TRUE);
        
        return;
    }

    DA_ALLOC_OBJ(job_data, srv_da_omadl_job_struct);

    job->data_ptr = job_data;
    
    job_data->oma_state = SRV_DA_OMA_STATE_PREPROCESSING;
    job_data->unique_id = srv_da_job_get_new_unique_id();
    job_data->icon = NULL;
    job_data->etag = NULL;
    job_data->size = 0;
    job_data->channel = SRV_DA_WPS_DEFAULT_CHANNEL;
    
    job_data->drm_status = SRV_DA_DRM_STATUS_NONE;
#ifdef __DRM_SUPPORT__
    job_data->drm_method = DRM_METHOD_NONE;
#endif
    job_data->drm_process_session = NULL;
    job_data->drm_wait_for_rights_session = NULL;
    job_data->time_to_wait_for_rights = -1;
    
    UCS2_STR_MALLOC_COPY(job_data->dd_filepath, filename);
    ANSI_STR_MALLOC_COPY(job_data->dd_url, download_url, WAP_DL_MAX_URL_LEN);

    srv_da_oma_parse_dd_and_show_confirm(job);
}


/*************************************************************************
 * FUNCTION
 *  srv_da_oma_parse_dd_and_show_confirm
 * DESCRIPTION
 *  Parse DD file and show confirm dialog to user.
 *  If app decide to skip confirm step, it will go to select-storage.
 * PARAMETERS
 *  job     [IN] Job
 * RETURNS
 *  void
 *************************************************************************/
static void srv_da_oma_parse_dd_and_show_confirm(srv_da_job_struct *job)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_omadl_job_struct *job_data;
    MMI_BOOL is_dd_valid;
    srv_da_oma_error_enum error;
    srv_da_oma_dd_struct *dd_info;
    srv_da_presetting_struct presetting;
    S32 i;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    job_data = (srv_da_omadl_job_struct*)job->data_ptr;

    is_dd_valid = srv_da_oma_parse_dd(job_data->dd_filepath, job, &(job_data->dd_info), job_data->dd_url);

    if (!is_dd_valid)
    {
        error = SRV_DA_OMA_INVALID_DESCRIPTOR;
        goto on_error;
    }

    dd_info = &job_data->dd_info;

    /* only support "1.0" */
    if (dd_info->DDVersion != NULL && mmi_ucs2cmp(dd_info->DDVersion, (S8*)L"1.0") != 0)
    {
        DA_TRACE_FUNC1(srv_da_oma_parse_dd_and_show_confirm, 1);
        error = SRV_DA_OMA_INVALID_DDVSERSION;
        goto on_error;
    }

    if (dd_info->objectURI == NULL)
    {
        DA_TRACE_FUNC1(srv_da_oma_parse_dd_and_show_confirm, 2);
        error = SRV_DA_OMA_INVALID_DESCRIPTOR;
        goto on_error;
    }

    /* size */
    if (dd_info->size == 0)
    {
        DA_TRACE_FUNC1(srv_da_oma_parse_dd_and_show_confirm, 3);
        error = SRV_DA_OMA_INVALID_DESCRIPTOR;
        goto on_error;
    }

    /* type */
    if (dd_info->type[0] == NULL)
    {
        DA_TRACE_FUNC1(srv_da_oma_parse_dd_and_show_confirm, 4);
        error = SRV_DA_OMA_INVALID_DESCRIPTOR;
        goto on_error;
    }

    /* content-type check */
    for (i = 0; i < 4; i++)
    {
        if (dd_info->type[i] != NULL &&
            applib_mime_type_look_up((kal_char*)dd_info->type[i], NULL, 0, 0) == NULL)
        {
            DA_TRACE_FUNC1(srv_da_oma_parse_dd_and_show_confirm, 5);
            error = SRV_DA_OMA_NON_ACCEPTABLE_CONTENT;
            goto on_error;
        }
    }

    job->mime_type = srv_da_util_lookup_mime_type_ascii((U8*)dd_info->type[0], 
                                                  srv_da_util_get_extension_ascii((S8*)dd_info->objectURI),
                                                  0, 0);
    job->type_handler = srv_da_search_mime_type_handler(job->mime_type);
    job_data->size = dd_info->size;

#if 0 /* MAUI_01200815: The drive to store file may be system drive, so the following check is incorrect.*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif

    /* app check */
    {
        const srv_da_oma_install_check_tbl_struct* check_hdlr;
        check_hdlr = srv_da_oma_search_install_check_handler(job->mime_type);
        if(check_hdlr)
        {
            if(!check_hdlr->handler(&job_data->dd_info))
            {
                DA_TRACE_FUNC1(srv_da_oma_parse_dd_and_show_confirm, 7);
                error = SRV_DA_OMA_NON_ACCEPTABLE_CONTENT;
                goto on_error;
            }
        }
    }

    /* Get presetting */
    {
        srv_da_presetting_param_struct param;

        param.action = MMI_DA_OMA_DOWNLOAD;
        param.mime_type = job->mime_type;
        param.uri = job_data->dd_info.objectURI;

        if (job->type_handler->get_presetting != NULL)
        {
            job->type_handler->get_presetting(&param, &presetting);
        }
        else
        {
            srv_da_default_presetting(&param, &presetting);
        }
    }

#ifdef __MMI_DA_OMADL_CUST_CHL_SUPPORT__
    if (job->dl_flag & DA_DL_FLAG_SKIP_CONFIRM)
    {
        srv_da_oma_select_storage(job);
        return;
    }
#endif
#ifndef MMI_DA_PLUTO_SLIM
    if (presetting.confirm_download)
    {


		if (srv_da_oma_extract_dd_content_string(job))
{
			srv_da_adp_show_choice_screen(
            MMI_FALSE,
            (void*)job,
            sizeof (srv_da_job_struct),
            srv_da_oma_confirm_download_callback,
            srv_da_oma_download_cancel_callback,
            srv_da_oma_delete_screen_callback, 
            MMI_TRUE);
            }
            }
            else
#endif
            {
        srv_da_oma_select_storage(job);
    }

    return;

on_error:
    srv_da_oma_popup_and_send_report(job, error, MMI_TRUE, MMI_TRUE);
}

void srv_da_oma_get_setting(const srv_da_job_struct *job, srv_da_setting_struct *setting_data)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_setting_hdlr         setting_hdlr;
    srv_da_omadl_job_struct     *job_data;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    job_data = (srv_da_omadl_job_struct*)job->data_ptr;

    /* get setting */
    setting_hdlr = srv_da_default_setting;
    MMI_ASSERT(job->type_handler);
    if(job->type_handler->setting_hdlr)
        setting_hdlr = job->type_handler->setting_hdlr;

    setting_hdlr(
        0, 
        job->mime_type ? job->mime_type->mime_type : 0,
        job->mime_type ? job->mime_type->mime_subtype : 0,
        MMI_DA_OMA_DOWNLOAD,
        job_data->dd_info.size,
        job_data->dd_info.objectURI,
        job_data->dd_info.type[0],
        0,
        NULL,
        setting_data
    );

    MMI_ASSERT(srv_da_setting_check(setting_data));
}


/*****************************************************************************
 * FUNCTION
 *  srv_da_oma_get_infoURL
 * DESCRIPTION
 *  Get <infoURL> of the job. If not present, returns NULL.
 * PARAMETERS
 *  job     [IN] The job.
 * RETURNS
 *  <infoURL>
 *****************************************************************************/
static const S8* srv_da_oma_get_infoURL(const srv_da_job_struct *job)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_omadl_job_struct *job_data;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    job_data = (srv_da_omadl_job_struct*)job->data_ptr;
    return job_data->dd_info.infoURL;
}


/*****************************************************************************
 * FUNCTION
 *  srv_da_oma_decide_default_filename
 * DESCRIPTION
 *  To decide default filename by job and setting_data.
 * PARAMETERS
 *  job             [IN] Job.
 *  setting_data    [IN] Setting
 *  filename        [OUT] Filename
 *  file_ext        [OUT] File extension name
 * RETURNS
 *  void
 *****************************************************************************/
void srv_da_oma_decide_default_filename(
    const srv_da_job_struct *job,
    const srv_da_setting_struct *setting_data,
    U16 *filename,
    U16 *fileext)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_omadl_job_struct *job_data;
    U16 *ucs2_name;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    job_data = (srv_da_omadl_job_struct*)job->data_ptr;

    filename[0] = L'\0';
    fileext[0] = L'\0';

    if (setting_data->default_filename || setting_data->filename[0] == L'\0')
    {
        if (job_data->dd_info.name != NULL)
        {
            ucs2_name = (U16*)job_data->dd_info.name;
            
            if (srv_da_util_is_valid_filename(ucs2_name))
            {
                srv_da_extract_filepath(ucs2_name, filename, fileext);
            }
            else
            {
                srv_da_extract_filename_from_url(job_data->dd_info.objectURI, filename, fileext);
            }
        }
        else
        {
            srv_da_extract_filename_from_url(job_data->dd_info.objectURI, filename, fileext);
        }
    }
    else
    {
        srv_da_extract_filepath((U16*)setting_data->filename, filename, fileext);
    }

    if(job->mime_type != NULL)
    {
        mmi_asc_n_to_wcs(fileext, job->mime_type->file_ext, SRV_FMGR_PATH_MAX_FILE_EXT_LEN);
    }
}


/*****************************************************************************
 * FUNCTION
 *  srv_da_oma_select_storage
 * DESCRIPTION
 *  Start to select storage for the download.
 * PARAMETERS
 *  job     [IN] The job.
 * RETURNS
 *  void
 *****************************************************************************/
void srv_da_oma_select_storage(srv_da_job_struct *job)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_omadl_job_struct     *job_data;
    srv_da_setting_struct       *setting_data;
    srv_da_storage_parameter_struct *para;
    void *select_storage_instance;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    job_data = (srv_da_omadl_job_struct*)job->data_ptr;



    /* Delete in filename_done() */
    // DeleteScreenIfPresent(SCR_ID_DA_OMA_DOWNLOAD_OPTION);

    /* retrieve setting */
    setting_data = srv_da_get_setting_buffer();
    srv_da_oma_get_setting(job, setting_data);
    srv_da_copy_setting(job, setting_data);

    /* prepare storage parameter */

    para = (srv_da_storage_parameter_struct*)srv_da_adp_mem_allocate(sizeof(srv_da_storage_parameter_struct));
        
    memset(para, 0, sizeof(srv_da_storage_parameter_struct));
    
    para->drv = setting_data->drv;
    para->storage = setting_data->storage;
    
#ifdef MMI_DA_CFG_SELECT_STORAGE_BEFORE_DOWNLOAD
    para->select_storage = setting_data->storage == SRV_DA_STORAGE_NONE ? MMI_TRUE : MMI_FALSE;
#else
    if (para->storage == SRV_DA_STORAGE_NONE)
    {
        para->storage = SRV_DA_STORAGE_AUTO;
    }
    para->select_storage = MMI_FALSE;
#endif

    mmi_wcscpy(para->folder, setting_data->folder);

    srv_da_oma_decide_default_filename(job, setting_data, para->filename, para->fileext);
    
#ifdef MMI_DA_CFG_INPUT_FILENAME_BEFORE_DOWNLOAD
    para->select_filename = (!setting_data->default_filename && setting_data->filename[0] == 0) ? MMI_TRUE : MMI_FALSE;
#else
    para->select_filename = MMI_FALSE;
#endif

#ifdef __MMI_DA_USER_SELECT_DOWNLOAD_LOCATION__
    if (!da_storage_selection)
    {
        if (para->storage == SRV_DA_STORAGE_NONE)
        {
            para->storage = SRV_DA_STORAGE_AUTO;
        }
        para->select_storage = MMI_FALSE;
    }
#endif /* __MMI_DA_USER_SELECT_DOWNLOAD_LOCATION__*/

    para->filesize = job_data->dd_info.size;

#ifdef __DRM_SUPPORT__
    /* DRM processing require twice space */
    if( job->mime_type && 
        (job->mime_type->mime_subtype == MIME_SUBTYPE_DRM_CONTENT ||
         job->mime_type->mime_subtype == MIME_SUBTYPE_DRM_MESSAGE) )
    {
        para->filesize *= 2;
    }
#endif

    para->filecheck_func = srv_da_does_job_with_filepath_exist;

#ifdef __MMI_DA_OMADL_CUST_CHL_SUPPORT__
    if(job->dl_flag & DA_DL_FLAG_SPECIAL)
        para->skip_exist_check = MMI_TRUE;
#endif

    /* confirmed, select storage now. */
    srv_da_adp_display_select_storage ((U32) job, para, MMI_DA_OMA_DOWNLOAD);
    srv_srv_da_adp_mem_free(para);
}

srv_da_acceptance_enum srv_da_oma_filename_done(
    U32 criteria, U16* filepath, MMI_BOOL canback, MMI_BOOL canpopup, void *instance)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
   
    srv_da_job_struct           *job;
    srv_da_omadl_job_struct     *job_data;

    srv_da_setting_struct       *setting;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    job = (srv_da_job_struct*)criteria;
    job_data = (srv_da_omadl_job_struct*)job->data_ptr;
#ifdef __MMI_DA_USER_SELECT_DOWNLOAD_LOCATION__
    da_storage_selection = MMI_TRUE;
#endif
    
    if (filepath == NULL)
    {
#if 0
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#if 0 //sahil to do in app 
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif //0
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
 #ifndef __COSMOS_MMI_PACKAGE__             
/* under construction !*/
#endif
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif  //0  
    }

    srv_da_set_allow_to_trigger_connection(MMI_TRUE);
    
    UCS2_STR_MALLOC_COPY(job_data->filepath, filepath);

#ifdef __MMI_DA_OMADL_CUST_CHL_SUPPORT__
    if(job->dl_flag & DA_DL_FLAG_SPECIAL)
    {
        FS_HANDLE hd;
        if ((hd = FS_Open((PU16)filepath, FS_READ_ONLY)) >= 0)
        {
            FS_GetFileSize(hd, &(job_data->curr_size));
            FS_Close(hd);
        }
    }

    if(!(job->dl_flag & DA_DL_FLAG_SKIP_CONFIRM))
    {
        if (job_data->size != job_data->curr_size)/* MAUI_02636426: Only processing required no download initiated */
        {
#ifndef __COSMOS_MMI_PACKAGE__
            srv_da_adp_show_progressing(
                SRV_DA_ACTION_SCR_PLEASE_WAIT,
                SRV_DA_PROCESSING,
                srv_da_job_get_title_icon(job),
                SRV_DA_PLEASE_WAIT,
                MMI_TRUE,
                job,
                srv_da_oma_cancel_download);
#endif 
        }
    }
#else
#ifndef __COSMOS_MMI_PACKAGE__
    srv_da_adp_show_progressing(
        SRV_DA_ACTION_SCR_PLEASE_WAIT,
        SRV_DA_PROCESSING,
        srv_da_job_get_title_icon(job),
        SRV_DA_PLEASE_WAIT,
        MMI_TRUE,
        job,
        srv_da_oma_cancel_download);
#endif
#endif
    //sahil to do in app
#ifndef __COSMOS_MMI_PACKAGE__
#ifndef MMI_DA_PLUTO_SLIM
    ClearDelScrnIDCallbackHandler(SRV_DA_ACTION_SCR_OMA_DOWNLOAD_OPTION, NULL);
    DeleteScreenIfPresent(SRV_DA_ACTION_SCR_OMA_DOWNLOAD_OPTION);
#endif 
#endif 

#ifdef __MMI_DA_OMADL_CUST_CHL_SUPPORT__
    if (job->dl_flag & DA_DL_FLAG_SPECIAL)
    {
        if (job_data->size == job_data->curr_size)
        {
            /* MAUI_02636426: Very specific case when user manage to pull out battery while Job was in processing state */
            setting = srv_da_get_setting_buffer();
            srv_da_oma_get_setting(job, setting);
            srv_da_copy_setting(job, setting);
	    job->state = SRV_DA_JOB_STATE_DOWNLOADING;
            srv_da_job_start(job);
            MMI_ASSERT(job->reporting);

	    job_data->oma_state = SRV_DA_OMA_STATE_DOWNLOADING;

	    job->state = SRV_DA_JOB_STATE_COMPLETED;
            srv_da_oma_do_next_procedure (job);
            return SRV_DA_ACCEPTANCE_ACCEPT;
        }
    }
#endif
        
    da_oma_context.curr_job = NULL;
    srv_da_adp_set_active_select_storage_instance(NULL);

    job_data->session = srv_da_wps_create_session_ex(
        (U32)job,
        SRV_DA_WPS_SETTING_DEFAULT,
        job_data->channel,
        srv_da_oma_session_created_callback,
        srv_da_oma_http_response_callback,
        srv_da_oma_http_auth_ind_callback,
        srv_da_oma_session_dl_progress_callback);

#ifdef __MMI_DA_OMADL_CUST_CHL_SUPPORT__
    if (job->dl_flag & DA_DL_FLAG_SPECIAL)
    {
        MMI_BOOL unbuffered_write;
        unbuffered_write = MMI_TRUE;
        srv_da_wps_session_set_option(job_data->session, SRV_DA_WPS_OPTION_UNBUFFERED_WRITE, &(unbuffered_write));
    }
#endif



    return SRV_DA_ACCEPTANCE_ACCEPT;

}

/*************************************************************************
 * FUNCTION
 *  srv_da_oma_open_nextURL
 * DESCRIPTION
 *  Open nextURL in background
 * PARAMETERS
 *  job     [IN] Job
 * RETURNS
 *  void
 *************************************************************************/
void srv_da_oma_open_nextURL(srv_da_job_struct *job)
{
#ifdef BROWSER_SUPPORT
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_omadl_job_struct *job_data;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/

    job_data = (srv_da_omadl_job_struct*)job->data_ptr;
    
    if (job_data->dd_info.nextURL != NULL)
    {
#ifdef __MMI_DA_OMADL_CUST_CHL_SUPPORT__
        if(!(job->dl_flag & DA_DL_FLAG_SPECIAL))
#endif
        {
            if (wap_browser_is_open())
            {
                wap_start_browser(WAP_BROWSER_GOTO_URL_BACKGROUND, (kal_uint8*)job_data->dd_info.nextURL);
                DA_FREE_BUFFER(job_data->dd_info.nextURL);
                job_data->dd_info.nextURL = NULL; /* Make sure again */
            }
        }
    }
#endif
}

#define OMA_SEND_REQUEST


/*****************************************************************************
 * FUNCTION
 *  srv_da_oma_cancel_download
 * DESCRIPTION
 *  Cancel handler for the "Please wait" of initializing WPS session and
 *  sending HTTP request
 * PARAMETERS
 *  arg         [IN] srv_da_job_struct*
 *  is_deleted  [IN] In delete context
 * RETURNS
 *  void
 *****************************************************************************/
void srv_da_oma_cancel_download(void *arg, MMI_BOOL is_deleted)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_job_struct *job;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    job = (srv_da_job_struct*)arg;

    srv_da_oma_popup_and_send_report(job, SRV_DA_OMA_USER_CANCELLED, MMI_TRUE, (MMI_BOOL)(!is_deleted));
}


/*****************************************************************************
 * FUNCTION
 *  srv_da_oma_show_screen_for_http_response
 * DESCRIPTION
 *  Show job list or detail screen for the job.
 * PARAMETERS
 *  arg             [IN] srv_da_job_struct*
 * RETURNS
 *  void
 *****************************************************************************/
void srv_da_oma_show_screen_for_http_response(void *arg)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_job_struct *job;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/

    job = (srv_da_job_struct*)arg;

    if (!srv_da_is_job_valid(job))
    {
        return;
    }
    
#ifdef __MMI_DOWNLOAD_AGENT_MULTI_DL__
    if(job->setting_info.can_minimize)
    {
        /* bring up list screen */
        srv_da_adp_display_job_list(job, MMI_TRUE);
    }
    else
#endif        
    {
        srv_da_adp_display_job_detail(job);
    }
}


/*****************************************************************************
 * FUNCTION
 *  srv_da_oma_session_created_callback
 * DESCRIPTION
 *  Callback for WPS session created. Start to send HTTP requrest.
 * PARAMETERS
 *  success     [IN] Whether the session created successfully
 *  arg         [IN] srv_da_job_struct*
 * RETURNS
 *  void
 *****************************************************************************/
void srv_da_oma_session_created_callback(MMI_BOOL success, U32 arg)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_job_struct           *job;
    srv_da_omadl_job_struct     *job_data;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    job = (srv_da_job_struct*)arg;
    job_data = (srv_da_omadl_job_struct*)job->data_ptr;

    if (!success) /* If limit of channel resource */
    {
        srv_da_oma_open_nextURL(job);
        /* job_data->session will be closed by following function */
		//job->state = SRV_DA_JOB_STATE_PAUSED;
        srv_da_oma_popup_and_send_report(job, SRV_DA_OMA_DEVICE_ABORTED, MMI_FALSE, MMI_TRUE);
		//srv_da_update_job_status(job);
		#ifndef __COSMOS_MMI_PACKAGE__
		srv_da_adp_scr_progressing_close(SRV_DA_ACTION_SCR_PLEASE_WAIT);
        #endif
        return;
    }

    /* send request */
    if (!srv_da_wps_http_req(
        job_data->session,
        WPS_HTTP_METHOD_GET,
        job_data->dd_info.objectURI,
        NULL,
        NULL,
        job_data->filepath, /* Decided in mmi_da_oma_filename_done() */
        WPS_DATA_TYPE_FILE))
    {
        MMI_ASSERT(0);
    }

   srv_da_oma_open_nextURL(job);
    
}


/*****************************************************************************
 * FUNCTION
 *  srv_da_oma_is_type_in_the_list
 * DESCRIPTION
 *  Check if the MIME type is in the type_list[].
 * PARAMETERS
 *  mime_type   [IN] MIME type to be checked
 *  type_list   [IN] String array of types
 *  n_types     [IN] Number of elements in the type_list
 * RETURNS
 *  MMI_TRUE if the mime_type is found in the list
 *****************************************************************************/
static MMI_BOOL srv_da_oma_is_type_in_the_list(
    const applib_mime_type_struct *mime_type,
    S8 *type_list[],
    const U32 n_types)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U32 i;
    const applib_mime_type_struct *type_element;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (mime_type == NULL)
    {
        return MMI_FALSE;
    }
    
    for (i = 0; i < n_types; i++)
    {
        if (type_list[i] != NULL)
        {
            type_element = applib_mime_type_look_up((kal_char*)type_list[i], NULL, 0, 0);

            /*
             * We should not check the entry pointer directly, because one type can be
             * mapped to multiple MIME strings and multiple entries.
             */
            if (type_element != NULL &&
                mime_type->mime_subtype == type_element->mime_subtype)
            {
                return MMI_TRUE;
            }
        }
    }

    return MMI_FALSE;
}


/*****************************************************************************
 * FUNCTION
 *  srv_da_oma_http_response_callback
 * DESCRIPTION
 *  HTTP response handler for manual resumption.
 * PARAMETERS
 *  arg             [IN] (mmi_da_oma_send_report_session_struct*)Session
 *  result          [IN] Result
 *  status          [IN] Status code which server responded
 *  header          [IN] HTTP header
 *  content_type    [IN] Content-Type
 *  content_len     [IN] Content-Length
 * RETURNS
 *  void
 *****************************************************************************/
void srv_da_oma_http_response_callback(
                U32 arg,
                U8 result,
                U16 status,
                S8 *header,
                S8 *content_type,
                U32 content_len,
                const wps_http_rsp_struct *rsp)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_job_struct           *job;
    srv_da_omadl_job_struct     *job_data;
    srv_da_oma_error_enum       error;
    MMI_BOOL                    user_cancel = MMI_FALSE;
    MMI_BOOL                    is_resume;
    srv_da_setting_struct       *setting;
    const applib_mime_type_struct *mime_type;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    DA_TRACE_FUNC2(srv_da_oma_http_response_callback, 0, content_len);

    job = (srv_da_job_struct*)arg;
    MMI_ASSERT(srv_da_is_job_valid(job));
    MMI_ASSERT(job->type == SRV_DA_JOB_TYPE_OMADL);
    MMI_ASSERT(job->state == SRV_DA_JOB_STATE_INIT || job->state == SRV_DA_JOB_STATE_RESUMING);
    job_data = (srv_da_omadl_job_struct*)job->data_ptr;
    is_resume = (job_data->curr_size > 0);

    /* check result */
    if(result != WPS_OK)
    {
        DA_TRACE_FUNC2(srv_da_oma_http_response_callback, 1, result);
        if( result == WPS_ERROR_FILE_ACCESS )
            error = SRV_DA_OMA_FILE_ACCESS_ERROR;
        else
            error = SRV_DA_OMA_LOADER_ERROR;
        if( result == WPS_ERROR_REQ_ABORT && job->state == SRV_DA_JOB_STATE_RESUMING)
            user_cancel = MMI_FALSE;
        goto on_error;
    }


    if (status >= 300 || status < 200)
    {
        DA_TRACE_FUNC2(srv_da_oma_http_response_callback, 3, status);
        error = SRV_DA_OMA_LOADER_ERROR;
        goto on_error;
    }
    else if (status == 401 || status == 407)
    {
        DA_TRACE_FUNC2(srv_da_oma_http_response_callback, 2, status);
        error = SRV_DA_OMA_UNAUTHORIZED;
        goto on_error;
    }

    if (status == 206)
    {
        if (content_len > 0)
        {
            if (content_len + job_data->curr_size == job_data->size)
            {
                /* OK */
            }
            else if (content_len == job_data->size)
            {
                /*
                 * [MAUI_02630704]
                 * Some server may send the total file length for Content-Length
                 * even for 206 Partial Content.
                 */
            }
            else
            {
                DA_TRACE_FUNC1(srv_da_oma_http_response_callback, 119);
                error = SRV_DA_OMA_LOADER_ERROR;
                goto on_error;
            }
        }
    }
    else if(status == 200)
    {
        if (!is_resume)
        {
            if (content_len > 0)
            {
                job_data->size = content_len;
            }
        }
        else
        {
            if (content_len != job_data->size)
            {
                /* Content-length mismatch */
                DA_TRACE_FUNC1(srv_da_oma_http_response_callback, 120);
                error = SRV_DA_OMA_LOADER_ERROR;
                goto on_error;
            }
        }
    }
    else
    {
        DA_TRACE_FUNC1(srv_da_oma_http_response_callback, 121);
        error = SRV_DA_OMA_LOADER_ERROR;
        goto on_error;
    }
    
    /* update content type */
    mime_type = srv_da_util_lookup_mime_type((U8*)content_type, 
                                                  srv_da_util_get_extension((U16*)job_data->filepath),
                                                  0, 0);

    DA_TRACE1(MMI_DA_TRC_MIMETYPE, (mime_type != NULL ? mime_type->mime_subtype : 0));

    if (is_resume && mime_type != job->mime_type)
    {
        /* MIME type mismatch */
        error = SRV_DA_OMA_LOADER_ERROR;
        goto on_error;
    }

    job->mime_type = mime_type;

    if (job->mime_type == NULL)
    {
        DA_TRACE_FUNC1(srv_da_oma_http_response_callback, 5);
        error = SRV_DA_OMA_NON_ACCEPTABLE_CONTENT;
        goto on_error;
    }

    if (!srv_da_oma_is_type_in_the_list(job->mime_type, job_data->dd_info.type, 4))
    {
#ifdef __DRM_SUPPORT__
        /*
         * MAUI_01253376: <type> in some DD only describes the content of DRM file
         * but not DRM format itself. So for DRM files, we should let it pass.
         */
        if (!srv_da_is_drm_content(job->mime_type))
#endif
        {
            DA_TRACE_FUNC1(srv_da_oma_http_response_callback, 6);
            error = SRV_DA_OMA_ATTRIBUTE_MISMATCH;
            goto on_error;
        }
    }

    job->type_handler = srv_da_search_mime_type_handler(job->mime_type);
    setting = srv_da_get_setting_buffer();
    srv_da_oma_get_setting(job, setting);
    srv_da_copy_setting(job, setting);

    /* its all ok now, Download start! */
    job->state = SRV_DA_JOB_STATE_DOWNLOADING;
    job_data->oma_state = SRV_DA_OMA_STATE_DOWNLOADING;

    /* Extract Etag for resumption */
    if (header != NULL)
    {
        if (job_data->etag == NULL)
        {
            S8 *etag;
        
            etag = (S8*)srv_da_adp_mem_allocate(MMI_DA_MAX_HTTP_ETAG_LEN);
            
            if (srv_da_util_extract_from_header(header, "ETag", etag, MMI_DA_MAX_HTTP_ETAG_LEN) == NULL)
            {
                srv_srv_da_adp_mem_free(etag);
            }
            else
            {
                job_data->etag = etag;
            }
        }

#ifdef __DRM_SUPPORT_SD_CALLBACK__
        srv_da_drm_extract_info_from_http_header(header, &(job_data->time_to_wait_for_rights));
#endif
        
        DA_TRACE_FUNC3(srv_da_oma_http_response_callback, 10, (S32)job_data->etag, job_data->time_to_wait_for_rights);
    }

    if(status != 206)
        job_data->curr_size = 0;
    
	if (!is_resume)
    {
    srv_da_job_start(job);
#ifndef __COSMOS_MMI_PACKAGE__
#if defined (__MMI_NCENTER_SUPPORT__)
        srv_da_adp_show_ncenter (job, SRV_DA_JOB_TYPE_OMADL);
#endif
#endif
        
    }
    kal_get_time(&job_data->dl_start_tick);

    /* DL start now, auth data is OK */
    job_data->auth_is_info_valid = MMI_TRUE;

    
    if (job->reporting && job->setting_info.filepath_hdlr != NULL)
    {
        S32 job_id = DA_MAKE_UNIQUE_ID(job, srv_da_oma_get_job_id(job));
    
        MMI_TRACE(MMI_DA_TRACE_GROUP, MMI_DA_TRC_FILEPATH_HDLR, job_id);

        job->setting_info.filepath_hdlr(
            job_id,
            job->mime_type->mime_type,
            job->mime_type->mime_subtype,
            job_data->filepath);
    }

    // srv_da_adp_oma_handle_http_rsp ((U32) job, status);
 #ifndef __COSMOS_MMI_PACKAGE__ 
	srv_da_adp_scr_progressing_close(SRV_DA_ACTION_SCR_PLEASE_WAIT);
#endif
    if (!is_resume)
    srv_da_oma_show_screen_for_http_response(job);  //TODO: Need not to call this API

    
    
    return;

on_error:

#if defined(__MMI_DOWNLOAD_AGENT_MULTI_DL__) && defined(__MMI_DA_RESUME__)

    if(job->state == SRV_DA_JOB_STATE_RESUMING && !user_cancel)
    {
        if (is_resume)
        {
            	job->state = SRV_DA_JOB_STATE_PAUSED;
			srv_da_adp_popup_error_for_job(job, SRV_DA_POPUP_TYPE_ERROR, 0, SRV_DA_ERROR_RESUME_FAIL, MMI_FALSE);
        }
        else
        {
            srv_da_oma_popup_and_send_report(job, error, MMI_FALSE, MMI_FALSE);
        }

        srv_da_oma_close_session(job);
    }
    else
#endif /* defined(__MMI_DOWNLOAD_AGENT_MULTI_DL__) && defined(__MMI_DA_RESUME__) */
    {
        srv_da_oma_popup_and_send_report(job, error, MMI_TRUE, MMI_TRUE);
    }
 #ifndef __COSMOS_MMI_PACKAGE__ 
   srv_da_adp_scr_progressing_close(SRV_DA_ACTION_SCR_PLEASE_WAIT);
#endif

}


/*****************************************************************************
 * FUNCTION
 *  srv_da_oma_session_dl_progress_callback
 * DESCRIPTION
 *  Download progress handler for MO download.
 * PARAMETERS
 *  arg         [IN] srv_da_job_struct*
 *  status      [IN] wps_dl_status_enum
 *  curr_size   [IN] Size already downloaded.
 *  cause       [IN] Error cause if any error
 * RETURNS
 *  void
 *****************************************************************************/
void srv_da_oma_session_dl_progress_callback(U32 arg, U8 status, U32 curr_size, S32 cause)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_job_struct           *job;
    srv_da_omadl_job_struct     *job_data;
    srv_da_oma_error_enum       oma_error;
    MMI_BOOL                    popup_error_afterward;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/

    job = (srv_da_job_struct*)arg;
    MMI_ASSERT(job && job->type == SRV_DA_JOB_TYPE_OMADL);
    job_data = (srv_da_omadl_job_struct*)job->data_ptr;

    /* state checking */
    if(job->state == SRV_DA_JOB_STATE_ABORTING ||
        job_data->session == SRV_DA_WPS_INVALID_SESSION)
    {
        return;
    }
    
    if(job->state != SRV_DA_JOB_STATE_DOWNLOADING)
    {
        MMI_ASSERT(0);
        return;
    }

    /* update status */
    job_data->curr_size = curr_size;
    kal_get_time(&job_data->dl_latest_tick);

    if(job_data->curr_size > job_data->dd_info.size)
        job_data->dd_info.size = job_data->curr_size;
    
    switch(status)
    {
        case WPS_DL_STATUS_ABORT:
            job->error_cause = srv_da_wps_map_error_code(cause);

#ifdef __MMI_DA_RESUME__
            if (cause > 0 && /* Network problem */
                !job->was_stopped_by_upper_layer &&
                job_data->size > 0 &&
                srv_da_is_allowed_to_trigger_connection())
            {
        #ifdef MMI_DA_WLAN_PREFER_SUPPORT
                /*
                 * MAUI_02662312: When auto resume channel does not get unset because this job status is still in 
                 * downloading, pause download and change the total active download count of WPS, it will be dcreased
                 * and now channel will be released if it is only active download.
                 */
                job->state = SRV_DA_JOB_STATE_PAUSED;
                srv_da_update_job_status(job);
                job->state = SRV_DA_JOB_STATE_DOWNLOADING;
        #endif /* MMI_DA_WLAN_PREFER_SUPPORT */                
                if(job_data->session != SRV_DA_WPS_INVALID_SESSION)
                {
                    srv_da_wps_close_session(job_data->session, NULL);
                    job_data->session = SRV_DA_WPS_INVALID_SESSION;
                }

            #ifdef MMI_DA_WLAN_PREFER_SUPPORT
                if (!srv_da_is_bearer_switching())
            #endif
				{
					if (!srv_da_is_pdp_switching())
                srv_da_util_trigger_proc_ext(srv_da_oma_auto_resume_try_to_resume, job, job_data->unique_id);
				}

                break;
            }
#endif /* __MMI_DA_RESUME__ */

            popup_error_afterward = MMI_TRUE;

            if (cause < 0) /* File system error */
            {
                oma_error = (cause == FS_DISK_FULL) ? SRV_DA_OMA_INSUFFICIENT_MEMORY : SRV_DA_OMA_FILE_ACCESS_ERROR;
                popup_error_afterward = MMI_FALSE;
                srv_da_adp_popup_error_for_job(job, SRV_DA_POPUP_TYPE_FS_ERROR, cause, 0,  MMI_FALSE);
            }
            else /* Network error */
            {
                oma_error = SRV_DA_OMA_LOSS_OF_SERVICE;
            }
            
#if defined(__MMI_DOWNLOAD_AGENT_MULTI_DL__) && defined(__MMI_DA_RESUME__)
            if(job->setting_info.can_minimize || job->reporting)
            {
                job->state = SRV_DA_JOB_STATE_PAUSED;
                srv_da_oma_popup_and_send_report(job, oma_error, MMI_FALSE, popup_error_afterward);
            }
            else
#endif /* defined(__MMI_DOWNLOAD_AGENT_MULTI_DL__) && defined(__MMI_DA_RESUME__) */
            {
                job->state = SRV_DA_JOB_STATE_ABORTED;
                srv_da_oma_popup_and_send_report(job, oma_error, MMI_TRUE, popup_error_afterward);
                return;
            }

            break;
            
        case WPS_DL_STATUS_COMPLETE:
            if (curr_size == 0)
            {
                job->state = SRV_DA_JOB_STATE_ABORTED;
                cause = SRV_DA_OMA_ATTRIBUTE_MISMATCH;
                srv_da_oma_popup_and_send_report(job, cause, MMI_TRUE, MMI_TRUE);
                return;
            }

            job->state = SRV_DA_JOB_STATE_COMPLETED;
            srv_da_oma_close_session(job);

            srv_da_oma_do_next_procedure(job);
            
            return;
            
        case WPS_DL_STATUS_DOWNLOADING:
            job->state = SRV_DA_JOB_STATE_DOWNLOADING;
            job_data->oma_state = SRV_DA_OMA_STATE_DOWNLOADING;
            break;
            
        default:
            MMI_ASSERT(0);
            break;
    }

    srv_da_update_job_status(job);
}


/*****************************************************************************
 * FUNCTION
 *  srv_da_oma_do_next_procedure
 * DESCRIPTION
 *  Do next procedure according to current job state(job->data_ptr->oma_state)
 *  This function will change job's state to next suitable state.
 *  BE SURE to call this function at the END of a function! Otherwise,
 *  it can not guarantee the correctness of the following procedure of the function.
 * PARAMETERS
 *  job     [IN/OUT] Target job
 * RETURNS
 *  void
 *****************************************************************************/
void srv_da_oma_do_next_procedure(srv_da_job_struct *job)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_omadl_job_struct *job_data;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    job_data = (srv_da_omadl_job_struct*)job->data_ptr;

    DA_TRACE_FUNC2(srv_da_oma_do_next_procedure, job->state, job_data->oma_state);

    if (job->state == SRV_DA_JOB_STATE_ABORTING)
    {
        return;
    }

    switch (job_data->oma_state)
    {
        case SRV_DA_OMA_STATE_DOWNLOADING:
        
#ifdef __MMI_DA_OMA_ICONURI_SUPPORT__

            if (job_data->dd_info.iconURI != NULL &&
                job_data->filepath[0] != SRV_FMGR_SYSTEM_DRV && /* DO NOT download icon to system drive */
                (job_data->icon == NULL || job_data->icon->state != SRV_DA_OMA_ICON_STATE_SUCCEED))
            {
                job->state = SRV_DA_JOB_STATE_PROCESSING;
                job_data->oma_state = SRV_DA_OMA_STATE_DOWNLOADING_ICON;
                    
                srv_da_oma_icon_start_download(job);
                
                break;
            }

            /* Go through */
            
        case SRV_DA_OMA_STATE_DOWNLOADING_ICON:
        
#endif /* __MMI_DA_OMA_ICONURI_SUPPORT__ */

            if (srv_da_oma_popup_and_send_report(job, SRV_DA_OMA_SUCCESS, MMI_FALSE, MMI_FALSE))
            {
                /* We have to wait for sending report successfully */
                job->state = SRV_DA_JOB_STATE_PROCESSING;
                job_data->oma_state = SRV_DA_OMA_STATE_SENDING_INSTALL_NOTIFICATION;
                break;
            }

            /* Go through */
           
        case SRV_DA_OMA_STATE_SENDING_INSTALL_NOTIFICATION:

            /*
             * NOTE: The report sending may fail.
             * In this condition, make sure it won't go here.
             */

            job->state = SRV_DA_JOB_STATE_PROCESSING;
            job_data->oma_state = SRV_DA_OMA_STATE_POSTPROCESSING;
            
#ifdef __DRM_SUPPORT__
            /* parse DRM type first */
            if (srv_da_is_drm_require_processing(job->mime_type))
            {
                srv_da_oma_drm_process(job);
                return;
            }
#endif

            srv_da_oma_icon_register_for_job(job);

            job->state = SRV_DA_JOB_STATE_COMPLETED;

            break;

        default:

            /* Unexpected state */
            MMI_EXT_ASSERT(MMI_FALSE, (job_data->oma_state), 0, 0);
            
            break;
    }

    srv_da_update_job_status(job);
}


static void srv_da_oma_session_aborted_callback(U32 arg)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_job_struct           *job;
    srv_da_omadl_job_struct               *job_data;
#ifdef __MMI_DOWNLOAD_AGENT_MULTI_DL__
    U32                         size;
#endif

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    DA_TRACE_FUNC(srv_da_oma_session_aborted_callback);

    job = (srv_da_job_struct*)arg;
    MMI_ASSERT(job && job->type == SRV_DA_JOB_TYPE_OMADL);
    job_data = (srv_da_omadl_job_struct*)job->data_ptr;

    /* session closed */
    job_data->session = SRV_DA_WPS_INVALID_SESSION;
    
    MMI_ASSERT(job->state == SRV_DA_JOB_STATE_ABORTING);
    job->state = SRV_DA_JOB_STATE_ABORTED;
    srv_da_oma_popup_and_send_report(job, SRV_DA_OMA_USER_CANCELLED, MMI_FALSE, MMI_FALSE);

#ifdef __MMI_DOWNLOAD_AGENT_MULTI_DL__
    size = srv_da_util_get_file_size(job_data->filepath);
    if(size)
        job_data->curr_size = size;
#endif

    if(job_data->abort_callback)
        job_data->abort_callback(job, 0);
    // After callback, job may be removed, do not use it.
}

static void srv_da_oma_close_session(srv_da_job_struct* job)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_omadl_job_struct *job_data;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    job_data = (srv_da_omadl_job_struct*)job->data_ptr;
    
    if(job_data && job_data->session != SRV_DA_WPS_INVALID_SESSION)
    {
        srv_da_wps_close_session(job_data->session, NULL);
        job_data->session = SRV_DA_WPS_INVALID_SESSION;
    }
}

#define OMA_JOB_TABLE

static MMI_BOOL srv_da_oma_free_job(srv_da_job_struct* job)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_omadl_job_struct     *job_data;
    srv_da_oma_dd_struct        *dd_info;
    S32                         i;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if(job->type != SRV_DA_JOB_TYPE_OMADL)
        return MMI_FALSE;
        
    job_data = (srv_da_omadl_job_struct*)job->data_ptr;

    if(job_data == NULL)
        return MMI_FALSE;

    if (job_data->session != SRV_DA_WPS_INVALID_SESSION)
    {
        srv_da_wps_close_session(job_data->session, NULL);
        job_data->session = SRV_DA_WPS_INVALID_SESSION;
    }

    if (job->state != SRV_DA_JOB_STATE_COMPLETED && job_data->filepath != NULL && !job->reporting)
    {
        srv_da_util_file_delete(job_data->filepath);
    }

    MMI_ASSERT(job_data->drm_process_session == NULL);

#ifdef __DRM_SUPPORT_SD_CALLBACK__
    if (job_data->drm_wait_for_rights_session != NULL)
    {
        srv_da_drm_wait_for_rights_cancel(job_data->drm_wait_for_rights_session);
        job_data->drm_wait_for_rights_session = NULL;
    }
#endif
    
    /* always delte DD file */
    FS_Delete(job_data->dd_filepath);
    
    /* free DD info */
    dd_info = &job_data->dd_info;
    DA_FREE_BUFFER(dd_info->objectURI);
    DA_FREE_BUFFER(dd_info->installNotifyURI);
    DA_FREE_BUFFER(dd_info->nextURL);
    DA_FREE_BUFFER(dd_info->DDVersion);
    DA_FREE_BUFFER(dd_info->name);
    DA_FREE_BUFFER(dd_info->description);
    DA_FREE_BUFFER(dd_info->vendor);
    DA_FREE_BUFFER(dd_info->infoURL);
    DA_FREE_BUFFER(dd_info->iconURI);
    DA_FREE_BUFFER(dd_info->installParam);
    for(i=0; i<4; i++)
        DA_FREE_BUFFER(dd_info->type[i]);

    DA_FREE_BUFFER(job_data->dd_url);
    DA_FREE_BUFFER(job_data->dd_filepath);
    DA_FREE_BUFFER(job_data->filepath);
    DA_FREE_BUFFER(job_data->etag);
    DA_FREE_BUFFER(job_data->auth_username);
    DA_FREE_BUFFER(job_data->auth_password);
    
    if (job_data->channel != SRV_DA_WPS_DEFAULT_CHANNEL)
    {
        srv_da_wps_release_channel(job_data->channel);
    }

    if (job_data->icon != NULL)
    {
        /* We don't need to remove the icon file since it has beed registered and moved,
           or deleted during abort. */
        DA_FREE_BUFFER(job_data->icon->filepath);
        DA_FREE_BUFFER(job_data->icon);
    }

    srv_srv_da_adp_mem_free(job_data);
    job->data_ptr = NULL;
    return MMI_TRUE;
}


/*****************************************************************************
 * FUNCTION
 *  srv_da_oma_get_name
 * DESCRIPTION
 *  Get item name to be displayed
 * PARAMETERS
 *  job         [IN] Job
 *  buffer      [IN] Buffer to be filled in
 *  buffer_len  [IN] Buffer length
 * RETURNS
 *  void
 *****************************************************************************/
static void srv_da_oma_get_name(const srv_da_job_struct *job, U16 *buffer, U32 buffer_len)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_omadl_job_struct *job_data;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    job_data = (srv_da_omadl_job_struct*)job->data_ptr;

    mmi_wcsncpy(buffer, job_data->filepath, buffer_len - 1);
    srv_da_util_process_filepath_to_be_displayed(buffer);
}


/*****************************************************************************
 * FUNCTION
 *  srv_da_oma_get_item_filepath
 * DESCRIPTION
 *  Get the file path of the job.
 * PARAMETERS
 *  job         [IN] Job
 * RETURNS
 *  Filepath. NOTE: The pointer returned should not be held permanently.
 *****************************************************************************/
static const U16* srv_da_oma_get_item_filepath(const srv_da_job_struct* job)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_omadl_job_struct *job_data;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    MMI_ASSERT(job->type == SRV_DA_JOB_TYPE_OMADL);
    
    job_data = (srv_da_omadl_job_struct*)job->data_ptr;
    
    return (job_data->filepath);
}

static U32  srv_da_oma_get_item_progress(const srv_da_job_struct* job, srv_da_item_progress_struct *info)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_omadl_job_struct *job_data;
    U32 secs;
    U32 progress;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    MMI_ASSERT(job->type == SRV_DA_JOB_TYPE_OMADL);
    job_data = (srv_da_omadl_job_struct*)job->data_ptr;

    info->fileSize = job_data->size;
    info->currSize = job_data->curr_size;
    secs = srv_da_util_ticks_to_milli_seconds(job_data->dl_latest_tick - job_data->dl_start_tick) / 1000;
    if(job_data->size && job_data->curr_size && secs)
        {
        info->secs_remain = (U32)((U64)secs * (U64)(job_data->size - job_data->curr_size) / (U64)job_data->curr_size);
    }
    else
    {
        info->secs_remain = MMI_DA_UTIL_ESTIMATED_TIME_UNKNOWN;
    }
        
    progress = MMI_DA_UTIL_ESTIMATED_TIME_UNKNOWN;

    if(job_data->size > 0)
    {
        progress = (U32)( ((U64)job_data->curr_size * (U64)100) / (U64)(job_data->size) );

        if (progress > 100)
        {
            progress = 100;
        }
    }
    else
    {
    switch (job->state)
    {
        case SRV_DA_JOB_STATE_COMPLETED:
            case SRV_DA_JOB_STATE_PROCESSING:
            progress = 100;
            break;
            
        default:
                progress = MMI_DA_UTIL_ESTIMATED_TIME_UNKNOWN;
            break;
    }
    }

    return progress;
   
}


/*****************************************************************************
 * FUNCTION
 *  srv_da_oma_is_object_desc_available
 * DESCRIPTION
 *  Query function for object description. Returns MMI_TRUE if the description
 *  is available by calling srv_da_oma_get_object_desc().
 * PARAMETERS
 *  job     [IN] Job to be queried.
 * RETURNS
 *  MMI_TRUE if if the description is available by calling srv_da_oma_get_object_desc().
 *****************************************************************************/
static MMI_BOOL srv_da_oma_is_object_desc_available(const srv_da_job_struct* job)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_omadl_job_struct *job_data;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    job_data = (srv_da_omadl_job_struct*)job->data_ptr;

    return (job_data->dd_info.name != NULL || job_data->dd_info.description != NULL);
}


/*****************************************************************************
 * FUNCTION
 *  srv_da_oma_get_object_desc
 * DESCRIPTION
 *  Fill the object description of job in string_buffer[]
 * PARAMETERS
 *  job             [IN] Job.
 *  string_buffer   [IN] String buffer
 *  buffer_len      [IN] Length of string_buffer (in U16)
 * RETURNS
 *  void
 *****************************************************************************/
static void srv_da_oma_get_object_desc(
                const srv_da_job_struct *job,
                U16* string_buffer,
                const U32 buffer_len)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_omadl_job_struct *job_data;
    U16* buffer_end;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    job_data = (srv_da_omadl_job_struct*)job->data_ptr;
    buffer_end = string_buffer;
#if 0 //sahil to do in app
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif //0
}

/*****************************************************************************
 * FUNCTION
 *  srv_da_oma_get_item_status_desc
 * DESCRIPTION
 *  Fill the object description of job in string_buffer[]
 * PARAMETERS
 *  job                 [IN]  Job.
 *  string_buffer       [IN]  Array of string buffers
 *  buffer_len          [IN]  Length of each string buffer element (in U16)
 *  num_of_buffers      [IN]  Number of string buffers. That is, this function can only
 *                            fill string_buffer[0..number_of_buffers-1]
 *  num_of_filled       [OUT] Number of filled buffer by this function
 * RETURNS
 *  void
 *****************************************************************************/
static void srv_da_oma_get_item_status_desc(
                const srv_da_job_struct *job,
                U16 *string_buffer[],       /* string_buffer[num_of_buffers] */
                const U32 buffer_len,       /* Max length per buffer */
                const U32 num_of_buffers,   /* Number of buffers */
                U32 *num_of_filled)
{
            
}


static void srv_da_oma_abort_job(srv_da_job_struct* job, S32 prev_state, MMI_BOOL pauseOnly,
                                  srv_da_abort_callback_type end_callback)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_omadl_job_struct *job_data;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    MMI_ASSERT(job->type == SRV_DA_JOB_TYPE_OMADL);
    MMI_ASSERT(job->state == SRV_DA_JOB_STATE_ABORTING);
    MMI_ASSERT(end_callback);
    job_data = (srv_da_omadl_job_struct*)job->data_ptr;

    job_data->abort_callback = end_callback;

    DA_TRACE_FUNC1(srv_da_oma_abort_job, prev_state);
    
    switch(prev_state)
    {
    case SRV_DA_JOB_STATE_DOWNLOADING:
	case SRV_DA_JOB_STATE_RESUMING:
        if (job_data->session != SRV_DA_WPS_INVALID_SESSION)
        {
            srv_da_wps_close_session(job_data->session, srv_da_oma_session_aborted_callback);
            job_data->session = SRV_DA_WPS_INVALID_SESSION;
        }
        break;

    case SRV_DA_JOB_STATE_PROCESSING: /* abort when downloading icon or sending report. */
        
        srv_da_oma_icon_terminate_download(job, SRV_DA_OMA_ICON_STATE_CANCELLED);

        switch (job_data->oma_state)
        {
            case SRV_DA_OMA_STATE_DOWNLOADING_ICON:
                /* The callback function will free the job */
                if (job_data->abort_callback != NULL)
                {
                    job->state = SRV_DA_JOB_STATE_ABORTED;
                    srv_da_oma_popup_and_send_report(job, SRV_DA_OMA_USER_CANCELLED, MMI_FALSE, MMI_TRUE);
                    job_data->abort_callback(job, 0);
                }
                else
                {
                    srv_da_oma_popup_and_send_report(job, SRV_DA_OMA_USER_CANCELLED, MMI_TRUE, MMI_TRUE);
                }

                break;

            case SRV_DA_OMA_STATE_SENDING_INSTALL_NOTIFICATION:

                MMI_ASSERT(job_data->install_noti_session != 0);
                MMI_ASSERT(pauseOnly == MMI_FALSE);     // can not suspend in this state

                srv_da_oma_send_report_cancel(job_data->install_noti_session);
                job_data->install_noti_session = 0;

                srv_da_adp_popup_for_job(job,
                    SRV_DA_POPUP_TYPE_INFO,
                    SRV_DA_OMA_ERROR_SEND_REPORT_CANCEL,
                    MMI_FALSE,
					NULL);

                job->state = SRV_DA_JOB_STATE_ABORTED;

                if (end_callback != NULL)
                {
                    end_callback(job, 0);
                }

                break;

            case SRV_DA_OMA_STATE_POSTPROCESSING:

#ifdef __DRM_SUPPORT__
                if (job_data->drm_process_session != NULL)
                {
                    /* State will be changed to be ABORTED and the abort_cb()
                       will be called in the callback */
                    srv_da_drm_process_cancel(job_data->drm_process_session);
                    job_data->drm_process_session = NULL;
                    return;
                }
#endif

#ifdef __DRM_SUPPORT_SD_CALLBACK__
                if (job_data->drm_wait_for_rights_session != NULL)
                {
                    srv_da_drm_wait_for_rights_cancel(job_data->drm_wait_for_rights_session);
                    job_data->drm_wait_for_rights_session = NULL;
                }
#endif /* __DRM_SUPPORT_SD_CALLBACK__ */

                job->state = SRV_DA_JOB_STATE_ABORTED;
                job_data->drm_status = SRV_DA_DRM_STATUS_NONE;

                if (end_callback != NULL)
                {
                    end_callback(job, 0);
                }

                break;
        }

        break;

    default:
        MMI_ASSERT(0);
        break;
    }
    
}

#if defined(__MMI_DOWNLOAD_AGENT_MULTI_DL__) && defined(__MMI_DA_RESUME__)
static void srv_da_oma_resume_job(srv_da_job_struct* job)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_omadl_job_struct *job_data;
    U32                     size;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    MMI_ASSERT(job->type == SRV_DA_JOB_TYPE_OMADL);
    job_data = (srv_da_omadl_job_struct*)job->data_ptr;

    switch (job_data->oma_state)
    {
        case SRV_DA_OMA_STATE_DOWNLOADING:
#ifndef __COSMOS_MMI_PACKAGE__
            srv_da_adp_show_progressing(
                SRV_DA_ACTION_SCR_PLEASE_WAIT,
                SRV_DA_PROCESSING,
                srv_da_job_get_title_icon(job),
                SRV_DA_PLEASE_WAIT,
                MMI_TRUE,
                job,
                srv_da_oma_resume_cancel_callback);  //TODO: No need to display progress in resumption for */
#endif

            /* Before resume, check the file length again */
            size = srv_da_util_get_file_size(job_data->filepath);
            if(size)
                job_data->curr_size = size;
            
            MMI_ASSERT(job->state == SRV_DA_JOB_STATE_RESUMING);
#if 0           
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif
           
            job_data->session = srv_da_wps_create_session((U32)job,
                                      SRV_DA_WPS_SETTING_DEFAULT,
                                      srv_da_oma_resume_session_created_callback,
                                      srv_da_oma_http_response_callback,
                                      srv_da_oma_resume_http_auth_ind_callback,
                                      srv_da_oma_session_dl_progress_callback);
            break;

        case SRV_DA_OMA_STATE_DOWNLOADING_ICON:
        case SRV_DA_OMA_STATE_POSTPROCESSING:
            job->state = SRV_DA_JOB_STATE_DOWNLOADING;
            job_data->oma_state = SRV_DA_OMA_STATE_DOWNLOADING;
            //srv_da_oma_show_screen_for_http_response(job);
            srv_da_oma_do_next_procedure(job);
            
            break;
        case SRV_DA_OMA_STATE_SENDING_INSTALL_NOTIFICATION:
            job->state = SRV_DA_JOB_STATE_PROCESSING;
            job_data->oma_state = SRV_DA_OMA_STATE_DOWNLOADING;
            srv_da_oma_do_next_procedure(job);
            break;

        default:
            break;
    }
}
#endif

static void srv_da_oma_dispatch_job(const srv_da_job_struct* job)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_omadl_job_struct *job_data;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    MMI_ASSERT(job->type == SRV_DA_JOB_TYPE_OMADL);
    job_data = (srv_da_omadl_job_struct*)job->data_ptr;

    srv_da_dispatch_to_app(
        DA_MAKE_UNIQUE_ID(job, srv_da_oma_get_job_id(job)),
        job->mime_type,
        MMI_DA_OMA_DOWNLOAD,
        job_data->filepath,
        job_data->dd_info.objectURI,
        NULL,
        job->type_handler);

}


/*****************************************************************************
 * FUNCTION
 *  srv_da_oma_get_job_id
 * DESCRIPTION
 *  Get LOCAL ID of an OMA download job.
 * PARAMETERS
 *  job         [IN] Job
 * RETURNS
 *  Local ID
 *****************************************************************************/
static U16 srv_da_oma_get_job_id(const srv_da_job_struct* job)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_omadl_job_struct *job_data;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/

    job_data = (srv_da_omadl_job_struct*)job->data_ptr;

    return job_data->unique_id;
}


/*****************************************************************************
 * FUNCTION
 *  srv_da_oma_assign_filepath
 * DESCRIPTION
 *  Assign a new filepath for the file of the job.
 * PARAMETERS
 *  job             [IN/OUT] Job
 *  new_filepath    [IN]     Filepath
 * RETURNS
 *  void
 *****************************************************************************/
static void srv_da_oma_assign_filepath(srv_da_job_struct* job, const U16* new_filepath)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_omadl_job_struct *job_data;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    MMI_ASSERT(job->type == SRV_DA_JOB_TYPE_OMADL);
    MMI_ASSERT(job->state == SRV_DA_JOB_STATE_COMPLETED);
    job_data = (srv_da_omadl_job_struct*)job->data_ptr;

    UCS2_STR_MALLOC_COPY(job_data->filepath, new_filepath);
}


/*****************************************************************************
 * FUNCTION
 *  srv_da_oma_get_installParam
 * DESCRIPTION
 *  Get the value of <installParam> of an OMA download.
 * PARAMETERS
 *  session_id      [IN] Session ID
 * RETURNS
 *  The value of <installParam>. If absent, returns NULL.
 *****************************************************************************/
const S8* srv_da_oma_get_installParam(S32 session_id)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_job_struct *job;
    srv_da_omadl_job_struct *job_data;
    S8 *installParam;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    installParam = NULL;
    
    job = srv_da_find_job(srv_da_job_match_id_func, session_id);

    if (job != NULL &&
        job->type == SRV_DA_JOB_TYPE_OMADL)
    {
        job_data = (srv_da_omadl_job_struct*)job->data_ptr;
        installParam = job_data->dd_info.installParam;
    }

    return installParam;
}


/*****************************************************************************
 * FUNCTION
 *  srv_da_oma_get_progressiveDownloadFlag
 * DESCRIPTION
 *  Get the value of <progressiveDownloadFlag> of an OMA download.
 * PARAMETERS
 *  session_id      [IN] Session ID
 * RETURNS
 *  The value of <progressiveDownloadFlag>.
 *  By default it returns MMI_FALSE if absent.
 *****************************************************************************/
MMI_BOOL srv_da_oma_get_progressiveDownloadFlag(S32 session_id)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_job_struct *job;
    srv_da_omadl_job_struct *job_data;
    MMI_BOOL progressiveDownloadFlag;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/

    progressiveDownloadFlag = MMI_FALSE;

    job = srv_da_find_job(srv_da_job_match_id_func, session_id);

    if (job != NULL &&
        job->type == SRV_DA_JOB_TYPE_OMADL)
    {
        job_data = (srv_da_omadl_job_struct*)job->data_ptr;
        progressiveDownloadFlag = job_data->dd_info.progressiveDownloadFlag;
    }

    return progressiveDownloadFlag;
}




void srv_da_oma_user_auth_callback(U32 criteria, U16* username, U16* password)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_job_struct           *job;
    srv_da_omadl_job_struct     *job_data;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/

    job = (srv_da_job_struct*)criteria;
    MMI_ASSERT(job && job->type == SRV_DA_JOB_TYPE_OMADL);
    job_data = (srv_da_omadl_job_struct*)job->data_ptr;

    if(!username || !password)
    {
        if(job->state != SRV_DA_JOB_STATE_INIT && job->state != SRV_DA_JOB_STATE_PAUSED && job->state != SRV_DA_JOB_STATE_RESUMING) 
        {    
            MMI_ASSERT(0);
        }
        if(job->state == SRV_DA_JOB_STATE_PAUSED || job->state == SRV_DA_JOB_STATE_RESUMING)
            job->state = SRV_DA_JOB_STATE_ABORTED;

        srv_da_oma_popup_and_send_report(job, SRV_DA_OMA_USER_CANCELLED, MMI_TRUE, MMI_TRUE);
#ifndef __COSMOS_MMI_PACKAGE__
		srv_da_adp_scr_progressing_close(SRV_DA_ACTION_SCR_PLEASE_WAIT);
#endif
    }
    else
    {
        // Cache last username/password
        UCS2_STR_MALLOC_COPY(job_data->auth_username, username);
        UCS2_STR_MALLOC_COPY(job_data->auth_password, password);

        /* User input info, it is not valid yet */
        job_data->auth_is_info_valid = MMI_FALSE;
        
        srv_da_wps_session_auth_UCS2(job_data->session, username, password);
    }
}


#if defined(__MMI_DOWNLOAD_AGENT_MULTI_DL__) && defined(__MMI_DA_RESUME__)

#define RESUME

static void srv_da_oma_resume_session_created_callback(MMI_BOOL success, U32 arg)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_job_struct           *job;
    srv_da_omadl_job_struct               *job_data;
    S8                          *header;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    
    job = (srv_da_job_struct*)arg;
    MMI_ASSERT(job && job->type == SRV_DA_JOB_TYPE_OMADL);
    job_data = (srv_da_omadl_job_struct*)job->data_ptr;

    if (!success)
    {
        /* fail to create section */
		 job->state = SRV_DA_JOB_STATE_PAUSED;
        srv_da_adp_popup_error_for_job(job, SRV_DA_POPUP_TYPE_ERROR, 0, SRV_DA_ERROR_RESUME_FAIL, MMI_FALSE);
  #ifndef __COSMOS_MMI_PACKAGE__ 
		srv_da_adp_scr_progressing_close(SRV_DA_ACTION_SCR_PLEASE_WAIT);
#endif
        srv_da_wps_close_session(job_data->session, NULL);
        job_data->session = SRV_DA_WPS_INVALID_SESSION;
        return;
    }

    header = (S8 *)srv_da_adp_mem_allocate(128);
    
    /* send request */
    if(!srv_da_wps_http_req(
        job_data->session,
        WPS_HTTP_METHOD_GET,
        job_data->dd_info.objectURI,
        srv_da_util_gen_http_header_to_resume(header, job_data->etag, job_data->curr_size),
        NULL,
        job_data->filepath,
        WPS_DATA_TYPE_FILE))
    {
        MMI_ASSERT(0);
    }

    srv_srv_da_adp_mem_free(header);
}


/*****************************************************************************
 * FUNCTION
 *  srv_da_oma_resume_http_auth_ind_callback
 * DESCRIPTION
 *  HTTP auth ind handler for resumption.
 * PARAMETERS
 *  arg         [IN] srv_da_job_struct*
 * RETURNS
 *  void
 *****************************************************************************/
static void srv_da_oma_resume_http_auth_ind_callback(U32 arg)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_job_struct           *job;
    srv_da_omadl_job_struct     *job_data;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/

    job = (srv_da_job_struct*)arg;
    MMI_ASSERT(job && job->type == SRV_DA_JOB_TYPE_OMADL);
    job_data = (srv_da_omadl_job_struct*)job->data_ptr;

    /* if auth info not valid yet, it means user need re-input */
    if(!job_data->auth_password || !job_data->auth_username || !job_data->auth_is_info_valid)
    {
    #ifndef MMI_DA_PLUTO_SLIM
        srv_da_adp_show_user_auth_screen((U32) job, srv_da_oma_user_auth_callback);
   	#endif
    }
    else
    {
        srv_da_wps_session_auth_UCS2(job_data->session, job_data->auth_username, job_data->auth_password);
    }
}


/*****************************************************************************
 * FUNCTION
 *  srv_da_oma_resume_cancel_callback
 * DESCRIPTION
 *  Cancel callback of trying resumption.
 * PARAMETERS
 *  arg         [IN] srv_da_job_struct*
 *  is_deleted  [IN] In delete context
 * RETURNS
 *  void
 *****************************************************************************/
static void srv_da_oma_resume_cancel_callback(void *arg, MMI_BOOL is_deleted)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_job_struct *job;
    srv_da_omadl_job_struct *job_data;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    job = (srv_da_job_struct*)arg;
    job_data = (srv_da_omadl_job_struct*)job->data_ptr;
    if (job->state == SRV_DA_JOB_STATE_RESUMING);
    {
        if (job_data->session != SRV_DA_WPS_INVALID_SESSION)
        {
            srv_da_wps_close_session(job_data->session, NULL);
            job_data->session = SRV_DA_WPS_INVALID_SESSION;
        }
        job->state = SRV_DA_JOB_STATE_PAUSED;
        srv_da_update_job_status(job);
    }
}

#endif

#define ICONURI


#ifdef __MMI_DA_OMA_ICONURI_SUPPORT__

/*****************************************************************************
 * FUNCTION
 *  srv_da_oma_icon_start_download
 * DESCRIPTION
 *  Start to download the job's icon. If the icon has been downloaded or
 *  no icon can be downloaded, this function will do nothing.
 * PARAMETERS
 *  job         [IN/OUT]    The job to download icon.
 * RETURNS
 *  void
 *****************************************************************************/
static void srv_da_oma_icon_start_download(srv_da_job_struct* job)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_omadl_job_struct *job_data;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    DA_TRACE_FUNC1(srv_da_oma_icon_start_download, 0);
    
    job_data = (srv_da_omadl_job_struct*)job->data_ptr;
    
    if (job_data->dd_info.iconURI != NULL)
    {
        /* We have to download icon */
        srv_da_oma_icon_struct *icon;
    
        if (job_data->icon == NULL)
        {
            job_data->icon = (srv_da_oma_icon_struct*)srv_da_adp_mem_allocate(sizeof(srv_da_oma_icon_struct));
            
            icon = job_data->icon;
            icon->session = SRV_DA_WPS_INVALID_SESSION;
            icon->filepath = NULL;
            icon->state = SRV_DA_OMA_ICON_STATE_NONE;
            icon->mime_type = NULL;
            icon->job = job;
        }

        icon = job_data->icon;

        DA_TRACE_FUNC2(srv_da_oma_icon_start_download, 1, (icon->state));

        switch (icon->state)
        {
            case SRV_DA_OMA_ICON_STATE_DOWNLOADING:
                /* We are unnecessary to do anything.
                   Next procedure will be triggered after download completed or aborted. */
                break;
                
            case SRV_DA_OMA_ICON_STATE_SUCCEED:
                srv_da_oma_icon_trigger_next_procedure(job);
                break;
                
            default: /* NONE, FAILED, CANCELLED */
                icon->state = SRV_DA_OMA_ICON_STATE_DOWNLOADING;

                DA_TRACE_FUNC1(srv_da_oma_icon_start_download, 2);
                
                icon->session = srv_da_wps_create_session_ex((U32)icon,
                    SRV_DA_WPS_SETTING_DEFAULT,
                    job_data->channel,
                    srv_da_oma_icon_session_created_callback,
                    srv_da_oma_icon_session_http_response_callback,
                    srv_da_oma_icon_session_http_auth_ind_callback,
                    srv_da_oma_icon_session_dl_progress_callback);

                break; /* Next procedure will be triggered afterward */
        }

    }

}
#endif /* __MMI_DA_OMA_ICONURI_SUPPORT__ */


/*****************************************************************************
 * FUNCTION
 *  srv_da_oma_icon_terminate_download
 * DESCRIPTION
 *  Termiate the icon downloading. This will delete the icon file even
 *  if the icon has been downloaded successfuly.
 * PARAMETERS
 *  job                 [IN/OUT]    The job whose icon downloading will be terminated.
 *  next_icon_state     [IN]        The next state that the job_data->icon will be.
 * RETURNS
 *  void
 *****************************************************************************/
static void srv_da_oma_icon_terminate_download(
                srv_da_job_struct *job,
                srv_da_oma_icon_state_enum next_icon_state)
{
#ifdef __MMI_DA_OMA_ICONURI_SUPPORT__
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_omadl_job_struct *job_data;
    srv_da_oma_icon_struct *icon;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    job_data = (srv_da_omadl_job_struct*)job->data_ptr;
    icon = job_data->icon;

    if (icon != NULL)
    {
        DA_TRACE_FUNC2(srv_da_oma_icon_terminate_download, (icon->state), next_icon_state);

        if (icon->state == SRV_DA_OMA_ICON_STATE_DOWNLOADING)
        {
            if (icon->session != SRV_DA_WPS_INVALID_SESSION)
            {
                srv_da_wps_close_session(icon->session, NULL);
                icon->session = SRV_DA_WPS_INVALID_SESSION;
            }
        }

        if (icon->filepath != NULL)
        {
            FS_Delete(icon->filepath);
            srv_srv_da_adp_mem_free(icon->filepath);
            icon->filepath = NULL;
        }


        MMI_EXT_ASSERT(next_icon_state == SRV_DA_OMA_ICON_STATE_CANCELLED ||
                        next_icon_state == SRV_DA_OMA_ICON_STATE_FAILED,
                        next_icon_state, 0, 0);
        
        icon->state = next_icon_state;
    }
    
#endif /* __MMI_DA_OMA_ICONURI_SUPPORT__*/
}


/*****************************************************************************
 * FUNCTION
 *  srv_da_oma_icon_register_for_file
 * DESCRIPTION
 *  Register icon for the file downloaded.
 * PARAMETERS
 *  icon        [IN] the pointer of icon structure.
 *                   If icon == NULL or invalid, the icon of the filepath will be cleaned.
 *  filepath    [IN] file path
 * RETURNS
 *  void
 *****************************************************************************/
static void srv_da_oma_icon_register_for_file(srv_da_oma_icon_struct *icon, U16 *filepath)
{
#ifdef __MMI_DA_OMA_ICONURI_SUPPORT__
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S32 register_result;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (icon != NULL && icon->state == SRV_DA_OMA_ICON_STATE_SUCCEED)
    {
        DA_TRACE_FUNC1(srv_da_oma_icon_register_for_file, 10);

        /* Correct the file extension of the icon.
           Note that we didn't give any extension when send HTTP request */
        {
            U16 *new_icon_filepath;
            
            new_icon_filepath = (U16 *)srv_da_adp_mem_allocate(SRV_FMGR_PATH_MAX_LEN);
            kal_wsprintf(new_icon_filepath, "%w.%s", icon->filepath, icon->mime_type->file_ext);
            FS_Rename(icon->filepath, new_icon_filepath); /* FS_Rename(old_name, new_name) */
            mmi_wcscpy(icon->filepath, new_icon_filepath); /* mmi_wcscpy(dest, src) */
            srv_srv_da_adp_mem_free(new_icon_filepath);
        }
        
        /* register to file manager */
        register_result = srv_fmgr_custicon_do(SRV_FMGR_CUSTICON_OP_REGISTER, filepath, icon->filepath);
        
        if (register_result != SRV_FMGR_CUSTICON_RESULT_OK)
        {
            /* Failed */
            DA_TRACE_FUNC2(srv_da_oma_icon_register_for_file, 11, register_result);
            srv_da_oma_icon_terminate_download(icon->job, SRV_DA_OMA_ICON_STATE_CANCELLED);
        }
    }
    else
    {
        /* clean icon for the filepath */
        register_result = srv_fmgr_custicon_do(SRV_FMGR_CUSTICON_OP_DEREGISTER, filepath, NULL);
        DA_TRACE_FUNC2(srv_da_oma_icon_register_for_file, 20, register_result);
    }
#endif /* __MMI_DA_OMA_ICONURI_SUPPORT__ */
}


/*****************************************************************************
 * FUNCTION
 *  srv_da_oma_icon_register_for_job
 * DESCRIPTION
 *  Register icon for the file downloaded. If job->icon == NULL or invalid,
 *  the icon of the file will be cleaned.
 * PARAMETERS
 *  job         [IN] job which has an icon associated.
 * RETURNS
 *  void
 *****************************************************************************/
static void srv_da_oma_icon_register_for_job(srv_da_job_struct* job)
{
#ifdef __MMI_DA_OMA_ICONURI_SUPPORT__
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_omadl_job_struct *job_data;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    job_data = (srv_da_omadl_job_struct*)job->data_ptr;
    srv_da_oma_icon_register_for_file(job_data->icon, job_data->filepath);
#endif /* __MMI_DA_OMA_ICONURI_SUPPORT__ */
}


#ifdef __MMI_DA_OMA_ICONURI_SUPPORT__
/*****************************************************************************
 * FUNCTION
 *  srv_da_oma_icon_trigger_next_procedure
 * DESCRIPTION
 *  Trigger next procedure if it is necessary.
 *  [NOTE & BE CAREFUL]
 *  We have to make sure ALL break points of icon downloading call this function.
 * PARAMETERS
 *  icon         [IN] The icon structure of the job.
 * RETURNS
 *  void
 *****************************************************************************/
static void srv_da_oma_icon_trigger_next_procedure(srv_da_job_struct *job)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_omadl_job_struct *job_data;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    DA_TRACE_FUNC(srv_da_oma_icon_trigger_next_procedure);

    job_data = (srv_da_omadl_job_struct*)job->data_ptr;

    /* We can trigger next procedure only when oma_state == DOWNLOADING_ICON */
    MMI_ASSERT(job_data->oma_state == SRV_DA_OMA_STATE_DOWNLOADING_ICON);
    srv_da_oma_do_next_procedure(job);
}


/*****************************************************************************
 * FUNCTION
 *  srv_da_oma_icon_session_created_callback
 * DESCRIPTION
 *  Callback function for WPS session created for icon downloading.
 *  This function will determine the filepath of icon.
 * PARAMETERS
 *  success     [IN] Suceessfully created
 *  arg         [IN] srv_da_oma_icon_struct* icon
 * RETURNS
 *  void
 *****************************************************************************/
static void srv_da_oma_icon_session_created_callback(MMI_BOOL success, U32 arg)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_oma_icon_struct *icon;
    srv_da_job_struct *job;
    srv_da_omadl_job_struct *job_data;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    icon = (srv_da_oma_icon_struct*)arg;
    job = icon->job;
    job_data = (srv_da_omadl_job_struct*)job->data_ptr;

    DA_TRACE_FUNC1(srv_da_oma_icon_session_created_callback, success);

    /* We only allocate & assign filepath in this function */
    MMI_ASSERT(icon->filepath == NULL);

    if (success)
    {
        U16 *folder_path;
        MMI_BOOL filepath_ok;

        filepath_ok = MMI_FALSE;

        icon->filepath = (U16*)srv_da_adp_mem_allocate(sizeof(U16) * (SRV_FMGR_PATH_MAX_LEN + 1));

        /* Get a temp file in FMGR_DEFAULT_FOLDER_RECEIVED */
        folder_path = (U16*)srv_da_adp_mem_allocate(sizeof(U16) * (SRV_FMGR_PATH_MAX_LEN + 4));
        kal_wsprintf(folder_path, "%c:\\%w", job_data->filepath[0], FMGR_DEFAULT_FOLDER_TEMP);
        if (srv_da_util_create_file_dir(folder_path, MMI_FALSE) >= 0)
        {
            filepath_ok = srv_da_util_get_temp_filename(folder_path, icon->filepath, SRV_FMGR_PATH_MAX_LEN);
        }
        srv_srv_da_adp_mem_free(folder_path);

        if (!filepath_ok)
        {
            goto srv_da_oma_icon_session_created_callback_terminate;
        }

        if (!srv_da_wps_http_req(
            icon->session,
            WPS_HTTP_METHOD_GET,
            job_data->dd_info.iconURI,
            NULL,
            NULL,
            icon->filepath,
            WPS_DATA_TYPE_FILE) )
        {
            goto srv_da_oma_icon_session_created_callback_terminate;
        }
    }
    else
    {
        /* session is invalid */
        icon->state = SRV_DA_OMA_ICON_STATE_FAILED;
        srv_da_wps_close_session(icon->session, NULL);
        icon->session = SRV_DA_WPS_INVALID_SESSION;

        srv_da_oma_icon_trigger_next_procedure(job);
    }

    return;

srv_da_oma_icon_session_created_callback_terminate:

    srv_da_oma_icon_terminate_download(job, SRV_DA_OMA_ICON_STATE_FAILED);

    srv_da_oma_icon_trigger_next_procedure(job);
}


/*****************************************************************************
 * FUNCTION
 *  srv_da_oma_icon_session_http_auth_ind_callback
 * DESCRIPTION
 *  Callback function for HTTP authencation indication for icon downloading.
 *  If authentication is needed, we will terminate the icon download.
 * PARAMETERS
 *  arg         [IN] srv_da_oma_icon_struct* icon
 * RETURNS
 *  void
 *****************************************************************************/
static void srv_da_oma_icon_session_http_auth_ind_callback(U32 arg)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_oma_icon_struct *icon;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    DA_TRACE_FUNC(srv_da_oma_icon_session_http_auth_ind_callback);
    
    icon = (srv_da_oma_icon_struct*)arg;
    
    /* We abandon downloading icon if it needs authentication */
    srv_da_oma_icon_terminate_download(icon->job, SRV_DA_OMA_ICON_STATE_CANCELLED);

    srv_da_oma_icon_trigger_next_procedure(icon->job);
}


/*****************************************************************************
 * FUNCTION
 *  srv_da_oma_icon_session_http_response_callback
 * DESCRIPTION
 *  Callback function for HTTP response for icon downloading.
 *  We will cancel some icon format here.
 * PARAMETERS
 *  arg             [IN] srv_da_oma_icon_struct* icon
 *  result          [IN] message->result
 *  status          [IN] message->status
 *  content_type    [IN] Content-Type from HTTP response
 *  content_len     [IN] Length of Content-Type
 * RETURNS
 *  void
 *****************************************************************************/
static void srv_da_oma_icon_session_http_response_callback(
    U32 arg,
    U8 result,
    U16 status,
    S8 *header,
    S8 *content_type,
    U32 content_len,
    const wps_http_rsp_struct *rsp)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_oma_icon_struct *icon;
    srv_da_job_struct *job;
    srv_da_omadl_job_struct *job_data;
    filetypes_file_type_enum icon_filetype;
    srv_da_oma_icon_state_enum next_icon_state_on_error;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    DA_TRACE_FUNC3(srv_da_oma_icon_session_http_response_callback, 0, result, status);
    
    icon = (srv_da_oma_icon_struct*)arg;
    job = icon->job;
    job_data = (srv_da_omadl_job_struct*)job->data_ptr;

    MMI_ASSERT(job->state != SRV_DA_JOB_STATE_INIT);
    MMI_ASSERT(icon->session != SRV_DA_WPS_INVALID_SESSION);

    /*********************************************************************
     * Note: Be sure to trigger next procedure if terminate the download *
     * in this function.                                                 *
     *********************************************************************/

    /*** Server denied / connetion failed ***/
    next_icon_state_on_error = SRV_DA_OMA_ICON_STATE_FAILED;
    
    if (result != WPS_OK || status != 200)
    {
        goto srv_da_oma_icon_session_http_response_callback_terminate;
    }
    
    /********* Cancelled by device **********/
    next_icon_state_on_error = SRV_DA_OMA_ICON_STATE_CANCELLED;

    /* Query FMGR whether the type of the icon is supported */
    {
        U16 *ext_in_U16;
        
        icon->mime_type = srv_da_util_lookup_mime_type((U8*)content_type, NULL, 0, 0);

        if (icon->mime_type == NULL || icon->mime_type->file_ext == NULL)
        {
            /* Invalid MIME type or unsupported MIME type */
            DA_TRACE_FUNC1(srv_da_oma_icon_session_http_response_callback, 10);
            goto srv_da_oma_icon_session_http_response_callback_terminate;
        }
        
        ext_in_U16 = (U16*)srv_da_adp_mem_allocate((strlen(icon->mime_type->file_ext) + 1) * sizeof(U16));
        mmi_asc_to_wcs(ext_in_U16, icon->mime_type->file_ext);
        icon_filetype = srv_fmgr_types_find_type_by_extension_str(ext_in_U16);
        srv_srv_da_adp_mem_free(ext_in_U16);

        /* Now we got icon_filetype */
    }

    if (!srv_fmgr_custicon_is_type_support(icon_filetype))
    {
        DA_TRACE_FUNC1(srv_da_oma_icon_session_http_response_callback, 20);
        goto srv_da_oma_icon_session_http_response_callback_terminate;
    }
    
    if (content_len > SRV_DA_OMA_MAX_ICON_SIZE)
    {
        DA_TRACE_FUNC1(srv_da_oma_icon_session_http_response_callback, 30);
        goto srv_da_oma_icon_session_http_response_callback_terminate;
    }

    if (srv_da_util_check_free_space(icon->filepath[0], content_len) == MMI_FALSE)
    {
        DA_TRACE_FUNC1(srv_da_oma_icon_session_http_response_callback, 40);
        goto srv_da_oma_icon_session_http_response_callback_terminate;
    }


    DA_TRACE_FUNC1(srv_da_oma_icon_session_http_response_callback, 99);

    return;
    
srv_da_oma_icon_session_http_response_callback_terminate:

    srv_da_oma_icon_terminate_download(job, next_icon_state_on_error);
    srv_da_oma_icon_trigger_next_procedure(job);
    
}


/*****************************************************************************
 * FUNCTION
 *  srv_da_oma_icon_session_dl_progress_callback
 * DESCRIPTION
 *  Callback function for progress indication for icon downloading.
 * PARAMETERS
 *  arg         [IN] srv_da_oma_icon_struct* icon
 *  status      [IN] message->status
 *  curr_size   [IN] file size
 *  cause       [IN] error cause (WPS internal value, do not use this field)
 * RETURNS
 *  void
 *****************************************************************************/
static void srv_da_oma_icon_session_dl_progress_callback(U32 arg, U8 status, U32 curr_size, S32 cause)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_oma_icon_struct *icon;
    srv_da_job_struct *job;
    srv_da_omadl_job_struct *job_data;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    icon = (srv_da_oma_icon_struct*)arg;
    job = icon->job;
    job_data = (srv_da_omadl_job_struct*)job->data_ptr;

    if (icon->session == SRV_DA_WPS_INVALID_SESSION)
    {
        return;
    }

    switch (status)
    {
        case WPS_DL_STATUS_DOWNLOADING:

            if (curr_size > SRV_DA_OMA_MAX_ICON_SIZE)
            {
                DA_TRACE_FUNC2(srv_da_oma_icon_session_dl_progress_callback, 10, curr_size);
                srv_da_oma_icon_terminate_download(job, SRV_DA_OMA_ICON_STATE_CANCELLED);
                srv_da_oma_icon_trigger_next_procedure(job);
            }
            
            break;
            
        case WPS_DL_STATUS_COMPLETE:
            DA_TRACE_FUNC1(srv_da_oma_icon_session_dl_progress_callback, 20);
            
            srv_da_wps_close_session(icon->session, NULL);
            icon->session = SRV_DA_WPS_INVALID_SESSION;
            icon->state = SRV_DA_OMA_ICON_STATE_SUCCEED;
            
            srv_da_oma_icon_trigger_next_procedure(job);
            
            break;
            
        case WPS_DL_STATUS_ABORT:
            DA_TRACE_FUNC2(srv_da_oma_icon_session_dl_progress_callback, 30, cause);
        
            if (icon->state != SRV_DA_OMA_ICON_STATE_CANCELLED)
            {
                /* Icon download was aborted by lower layer */
                srv_da_oma_icon_terminate_download(job, SRV_DA_OMA_ICON_STATE_FAILED);
                srv_da_oma_icon_trigger_next_procedure(job);
            }
            
            break;
    }
}

#endif /* __MMI_DA_OMA_ICONURI_SUPPORT__ */


#define SEND_REPORT

/*****************************************************************************
 * FUNCTION
 *  srv_da_oma_terminate_job
 * DESCRIPTION
 *  Terminate a job. The job will be set in a termination state and update to
 *  client & user. Before termination, the resource hold by the job shall be
 *  released before.
 * PARAMETERS
 *  job     [IN/OUT] The job to be terminated
 * RETURNS
 *  void
 *****************************************************************************/
static void srv_da_oma_terminate_job(srv_da_job_struct *job)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    MMI_ASSERT(job != NULL);
    
    if (job == da_oma_context.curr_job)
    {
        da_oma_context.curr_job = NULL;
    }

    if (job->state == SRV_DA_JOB_STATE_INIT)
    {
        srv_da_job_cancel(job);
    }
    else if (job->state == SRV_DA_JOB_STATE_PAUSED)
    {
        job->state = SRV_DA_JOB_STATE_ABORTED;
        srv_da_update_job_status(job);
    }
	else if (job->state == SRV_DA_JOB_STATE_RESUMING)
    {
        job->state = SRV_DA_JOB_STATE_ABORTED;
        srv_da_update_job_status(job);
    }
    else if (job->state == SRV_DA_JOB_STATE_ABORTED ||
             job->state == SRV_DA_JOB_STATE_FAILED)
    {
        srv_da_update_job_status(job);
    }
    else
    {
        MMI_ASSERT(0);
    }
}


/*****************************************************************************
* FUNCTION
*   srv_da_oma_popup_and_send_report
* DESCRIPTION
*   Send status report to server. After finish, we will destory the channel.
* PARAMETERS
*   error   IN  status code
* RETURNS
*   void
*****************************************************************************/
MMI_BOOL srv_da_oma_popup_and_send_report(srv_da_job_struct *job, S32 error, MMI_BOOL end_job, MMI_BOOL bpopup)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_omadl_job_struct     *job_data = NULL;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    DA_TRACE_FUNC1(srv_da_oma_popup_and_send_report, error);

    /* if need do status report */
    if (job != NULL)
    {
        job_data = (srv_da_omadl_job_struct*)job->data_ptr;
        if(job_data)
        {
        if (job_data->dd_info.installNotifyURI != NULL)
        {
            if (srv_da_is_allowed_to_trigger_connection())
            {
                S8 *report_content;
                void (*result_callback)(void *arg, srv_da_oma_send_report_result_enum result, U32 status_code);
                
                srv_da_oma_report_map_string(error, NULL, &report_content);

                if (error == SRV_DA_OMA_SUCCESS)
                {
                    /* We need to wait for response */
                    result_callback = srv_da_oma_send_install_noti_result_callback;
                }
                else
                {
                    result_callback = NULL;
                }

                if (job_data->install_noti_session != 0)
                {
                    srv_da_oma_send_report_cancel(job_data->install_noti_session);
                }
                    
                job_data->install_noti_session = srv_da_oma_send_report(
                    job_data->dd_info.installNotifyURI,
                    report_content,
                    SRV_DA_OMA_SEND_REPORT_DEFAULT_NUM_TO_TRY,
                    job_data->channel,
                    job,
                    result_callback);

                if (error == SRV_DA_OMA_SUCCESS)
                {
                    /* We have to wait for result */
                    return MMI_TRUE;
                }
            }
            else if (error == SRV_DA_OMA_SUCCESS)
            {
                error = SRV_DA_OMA_USER_CANCELLED;
                end_job = MMI_TRUE;
                bpopup = MMI_TRUE;
            }
        }
    }
    }


    if (error != SRV_DA_OMA_SUCCESS)
    {
        if (bpopup)
        {
            srv_da_adp_oma_popup_message(job, (srv_da_oma_error_enum)error, end_job);
        }

        if (job_data != NULL && job_data->filepath != NULL && end_job)
        {
            srv_da_util_file_delete(job_data->filepath);
        }

        if (job != NULL)
        {
            srv_da_oma_close_session(job);
        }
        
        if (job != NULL && end_job)
        {
            srv_da_oma_terminate_job(job);
        }
    }
    else
    {
        MMI_ASSERT(job && (job->state == SRV_DA_JOB_STATE_COMPLETED ||
            job->state == SRV_DA_JOB_STATE_PROCESSING));
        /* clean up process will be done after dispatching */
    }
    return MMI_FALSE;
}


/*****************************************************************************
 * FUNCTION
 *  srv_da_oma_send_install_noti_result_callback
 * DESCRIPTION
 *  Callback of sending install notification. If success, this function will
 *  release the object. Otherwise, the object will be discarded.
 * PARAMETERS
 *  arg         [IN] srv_da_job_struct*
 *  result      [IN] Result
 *  status      [IN] Status code the server responded
 * RETURNS
 *  void
 *****************************************************************************/
static void srv_da_oma_send_install_noti_result_callback(
    void *arg,
    srv_da_oma_send_report_result_enum result,
    U32 status)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_job_struct *job;
    srv_da_omadl_job_struct *job_data;
    U32                     err_stringid;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    DA_TRACE_FUNC2(srv_da_oma_send_report_callback, result, status);
    
    MMI_ASSERT(arg != NULL);
    job = (srv_da_job_struct*)arg;
    job_data = (srv_da_omadl_job_struct*)job->data_ptr;
    
    job_data->install_noti_session = 0;
    
    err_stringid = 0;
    
    if (result == SRV_DA_OMA_SEND_REPORT_RESULT_OK)
    {
        err_stringid = 0;
    }
    else if (result == SRV_DA_OMA_SEND_REPORT_RESULT_TIMEOUT)
    {
        /* "Well-Intentioned Attempt" */
        /* Since we do our best to send report but no response from server,
           allow to release object to user */
        err_stringid = 0;
        MMI_TRACE(MMI_DA_TRACE_GROUP, MMI_DA_OMA_WELL_INTENT_ATTEMPT, srv_da_oma_get_job_id(job));
    }
    else if(status == 401 || status == 407)
    {
        err_stringid = SRV_DA_AHTUENTICATION_FAILED;
    }
    else
    {
        err_stringid = SRV_DA_OMA_ERROR_SEND_REPORT_FAIL;
    }

    if(!job)
    {
#ifndef __MMI_DOWNLOAD_AGENT_MULTI_DL__
        if(err_stringid)
        {
            srv_da_adp_popup(err_stringid, 0, SRV_DA_POPUP_TYPE_ERROR);
        }
#endif
        return;
    }

    /* handle complete job */
    MMI_ASSERT(job->state == SRV_DA_JOB_STATE_PROCESSING);
    MMI_ASSERT(job->type == SRV_DA_JOB_TYPE_OMADL);
    job_data = (srv_da_omadl_job_struct*)job->data_ptr;

    if(err_stringid)
    {
        /* there is error */
        job->state = SRV_DA_JOB_STATE_ABORTED;
        srv_da_util_file_delete(job_data->filepath);
        srv_da_adp_popup_error_for_job(job, SRV_DA_POPUP_TYPE_ERROR, 0, err_stringid, MMI_TRUE);
        srv_da_update_job_status(job);

        return;
    }
    else
    {
        MMI_ASSERT(job_data->oma_state == SRV_DA_OMA_STATE_SENDING_INSTALL_NOTIFICATION);
        srv_da_oma_do_next_procedure(job);
    }
}


#define DRM_PROC

#ifdef __DRM_SUPPORT__

#ifdef __DRM_SUPPORT_SD_CALLBACK__

/*****************************************************************************
 * FUNCTION
 *  srv_da_oma_drm_rights_arrived_callback
 * DESCRIPTION
 *  To be notified that DRM rights has been arrived.
 * PARAMETERS
 *  arg                     [IN]  srv_da_job_struct*
 * RETURNS
 *  void
 *****************************************************************************/
static void srv_da_oma_drm_rights_arrived_callback(void *arg)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_job_struct *job;
    srv_da_omadl_job_struct *job_data;
    srv_da_setting_struct setting;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    job = (srv_da_job_struct*)arg;
    job_data = (srv_da_omadl_job_struct*)job->data_ptr;

    job_data->drm_wait_for_rights_session = NULL;
    job_data->drm_status = SRV_DA_DRM_STATUS_RIGHTS_ARRIVED;    
    job->state = SRV_DA_JOB_STATE_COMPLETED;

    /* Update do_dispatch */
    srv_da_oma_get_setting(job, &setting);
    srv_da_copy_setting(job, &setting);

    job->notified_complete = MMI_FALSE;

#ifdef __MMI_DOWNLOAD_AGENT_MULTI_DL__
    
    srv_da_update_job_status(job);
    
#else /* __MMI_DOWNLOAD_AGENT_MULTI_DL__ */

    srv_da_job_drm_save_as(job, job_data->drm_method);
        
#endif /* __MMI_DOWNLOAD_AGENT_MULTI_DL__ */
}


/*****************************************************************************
 * FUNCTION
 *  srv_da_oma_drm_fail_to_wait_callback
 * DESCRIPTION
 *  Callback function for waiting DRM rights failed.
 * PARAMETERS
 *  arg                     [IN]  srv_da_job_struct*
 *  can_continue_waiting    [IN]  If MMI_TRUE, continue_waiting can set to be MMI_TRUE
 *  continue_waiting        [OUT] Continue waiting for rights infinitely
 * RETURNS
 *  void
 *****************************************************************************/
static void srv_da_oma_drm_fail_to_wait_callback(
    void *arg,
    drm_sd_expiry_type_enum cause,
    MMI_BOOL can_continue_waiting,
    MMI_BOOL *continue_waiting)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_job_struct *job;
    srv_da_omadl_job_struct *job_data;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    job = (srv_da_job_struct*)arg;
    job_data = (srv_da_omadl_job_struct*)job->data_ptr;

    if (can_continue_waiting)
    {
#ifdef __MMI_DOWNLOAD_AGENT_MULTI_DL__

        *continue_waiting = MMI_TRUE;

        if (cause == DRM_SD_EXPIRY_TIMEOUT)
        {
            
            srv_da_adp_popup_long_msg_for_job(job, job_data->filepath)  ;
        }
            
#else /* __MMI_DOWNLOAD_AGENT_MULTI_DL__ */

        *continue_waiting = MMI_FALSE;
        job_data->drm_wait_for_rights_session = NULL;
        if (cause == DRM_SD_EXPIRY_TIMEOUT)
        {
            srv_da_adp_popup(SRV_DA_RIGHTS_DID_NOT_ARRIVE_ON_TIME, 0, SRV_DA_POPUP_TYPE_INFO);
        }

#endif /* __MMI_DOWNLOAD_AGENT_MULTI_DL__ */

    }
    else
    {
        *continue_waiting = MMI_FALSE;
        job_data->drm_wait_for_rights_session = NULL;
    }

    job_data->drm_status = SRV_DA_DRM_STATUS_NO_RIGHTS;
    job->state = SRV_DA_JOB_STATE_COMPLETED;
    
    /* notifyed_complete will be reset when rights arrived */
    job->notified_complete = MMI_TRUE;

    srv_da_update_job_status(job);
}

#endif /*__DRM_SUPPORT_SD_CALLBACK__ */


/*****************************************************************************
 * FUNCTION
 *  srv_da_oma_drm_process_callback
 * DESCRIPTION
 *  Callback for DRM processing result.
 * PARAMETERS
 *  arg             [IN] srv_da_job_struct*
 *  result          [IN] Processing result
 *  new_filepath    [IN] The filepath of processing result(output), it may be
 *                       the same to original path.
 *  method          [IN] DRM method
 *  is_archive      [IN] archive
 * RETURNS
 *  void
 *****************************************************************************/
static void srv_da_oma_drm_process_callback(
    void *arg,
    S32 result,
    const U16 *new_filepath,
    const applib_mime_type_struct *new_mime_type,
    drm_method_enum method,
    const srv_da_drm_result_info_struct *info)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_job_struct *job;
    srv_da_omadl_job_struct *job_data;
    const applib_mime_type_struct *mime_type_to_rename;
    srv_da_setting_struct setting;
    U16 *filepath_after_moved;
    U16 *filename;
    U16 file_drive;
    S32 fs_error;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/  
    job = (srv_da_job_struct*)arg;
    job_data = (srv_da_omadl_job_struct*)job->data_ptr;

    job_data->drm_process_session = NULL;

    if (job->state == SRV_DA_JOB_STATE_ABORTING)
    {
        job->state = SRV_DA_JOB_STATE_ABORTED;
    
        if (job_data->abort_callback != NULL)
        {
            job_data->abort_callback(job, 0);
        }

        return;
    }

    if (srv_da_job_update_content_by_drm_processing_result(
        job,
        MMI_DA_OMA_DOWNLOAD,
        result,
        new_filepath,
        new_mime_type,
        info))
    {
        mime_type_to_rename = new_mime_type;
        
#ifdef __DRM_V02__
        if(method == DRM_METHOD_V2) /* use .odf for drm 2.0 files */
        {
            mime_type_to_rename = applib_mime_type_look_up(NULL, NULL, MIME_TYPE_APPLICATION, MIME_SUBTYPE_DRM_CONTENT_V2);
        }
#endif /* __DRM_V02__ */

        srv_da_oma_get_setting(job, &setting);

        filepath_after_moved = (U16*)srv_da_adp_mem_allocate((SRV_FMGR_PATH_MAX_LEN + 1) * sizeof(U16));

        /* MAUI_01867210: Delete before moving can avoid name collision */
        if (mmi_wcsicmp(job_data->filepath, new_filepath) != 0)
        {
            /* Delete old file */
            srv_da_util_file_delete(job_data->filepath);
        }

        filename = srv_da_util_get_filename(job_data->filepath);
        
        /*
         * MAUI_01867210:
         * To let srv_da_move_as_new_type() can use original name.
         * Skip the name checking by srv_da_does_job_with_filepath_exist()
         */
        file_drive = job_data->filepath[0];
        job_data->filepath[0] = L'\0';
        
        fs_error = srv_da_move_as_new_type(
            new_filepath,
            setting.folder,
            filename,
            mime_type_to_rename,
            filepath_after_moved);

        /* Restore the full filepath to let redrawing correct */
        job_data->filepath[0] = file_drive;

        if (fs_error == FS_NO_ERROR)
        {
            U32 filepath_len;

            /* Reassign the filepath of the DRM processing result to job */
            filepath_len = mmi_wcslen(filepath_after_moved);
            srv_srv_da_adp_mem_free(job_data->filepath);
            job_data->filepath = (U16 *)srv_da_adp_mem_allocate((filepath_len + 1) * sizeof(U16));
            mmi_wcscpy(job_data->filepath, filepath_after_moved);

            srv_da_copy_setting(job, &setting);
            DRM_register_file((kal_wchar*)job_data->filepath);
            job_data->drm_method = method;

            /* Register icon first. If the file will be moved to another folder,
               it will notify FMGR to change the filepath later. */
            srv_da_oma_icon_register_for_file(job_data->icon, job_data->filepath);

#ifdef __DRM_SUPPORT_SD_CALLBACK__
            if (job_data->time_to_wait_for_rights >= 0 &&
                job->mime_type != NULL && /* Only wait for rights when the MIME type is supported */
                !srv_da_drm_has_rights(job_data->filepath, job->mime_type))
            {
                job_data->drm_wait_for_rights_session = srv_da_drm_wait_for_rights(
                    job_data->filepath,
                    job_data->time_to_wait_for_rights,
                    job,
                    srv_da_oma_drm_rights_arrived_callback,
                    srv_da_oma_drm_fail_to_wait_callback);

                if (job_data->drm_wait_for_rights_session != NULL)
                {
                    job_data->drm_status = SRV_DA_DRM_STATUS_WAITING_FOR_RIGHTS;
                }
                else
                {
                    /* Treat as fail to wait, no rights */
                    job_data->drm_status = SRV_DA_DRM_STATUS_NO_RIGHTS;
                    job->state = SRV_DA_JOB_STATE_COMPLETED;
                    job->setting_info.confirm_dispatch = MMI_FALSE;
                    job->setting_info.do_dispatch = MMI_FALSE;
                }

                srv_da_update_job_status(job);
                
            }
            else
#endif /* __DRM_SUPPORT_SD_CALLBACK__ */
            {
                job->state = SRV_DA_JOB_STATE_COMPLETED;
            
#ifdef __MMI_DOWNLOAD_AGENT_MULTI_DL__

                srv_da_update_job_status(job);
                
#else /* __MMI_DOWNLOAD_AGENT_MULTI_DL__ */

                srv_da_job_drm_save_as(job, method);
                    
#endif /* __MMI_DOWNLOAD_AGENT_MULTI_DL__ */
            }
        }
        else
        {
            srv_da_adp_popup_error_for_job(job, SRV_DA_POPUP_TYPE_FS_ERROR, fs_error, 0, MMI_TRUE);
            srv_da_update_job_status(job);
        }

        srv_srv_da_adp_mem_free(filepath_after_moved);
    }
    else
    {
        srv_da_update_job_status(job);
    }
}


/*****************************************************************************
 * FUNCTION
 *  srv_da_oma_drm_process
 * DESCRIPTION
 *  Do DRM process for the job. srv_da_oma_drm_process_callback will be called
 *  to notify the processing result.
 * PARAMETERS
 *  job     [IN] Job
 * RETURNS
 *  void
 *****************************************************************************/
static void srv_da_oma_drm_process(srv_da_job_struct *job)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_omadl_job_struct *job_data;
    MMI_BOOL need_to_wait;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/  
    job_data = (srv_da_omadl_job_struct*)job->data_ptr;

    job->state = SRV_DA_JOB_STATE_PROCESSING;

    job_data->drm_wait_for_rights_session = NULL;
    job_data->drm_process_session = srv_da_drm_process(
        job_data->filepath,
        job->mime_type,
        &need_to_wait,
        job,
        srv_da_oma_drm_process_callback);

    if (job_data->drm_process_session != NULL)
    {
        if (need_to_wait)
        {
            job_data->drm_status = SRV_DA_DRM_STATUS_PROCESSING;
            srv_da_update_job_status(job);
        }
    }
    else
    {
        /* If no need to wait, it will call the callback function directly */
        /* Whatever the case is, the callback function will be called finally. */
    }
}


#endif /* __DRM_SUPPORT__ */

#define AUTO_RESUME

#ifdef __MMI_DA_RESUME__
/*
 * Yes, the code is very similar to HTTP auto-resume.
 * But it is not easy to extract common code and init/destroy requests gracefully.
 * If we have template mechanism like C++, we can do this easily.
 */

/*****************************************************************************
 * FUNCTION
 *  srv_da_oma_auto_resume_failed
 * DESCRIPTION
 *  Procedure for auto-resume failed.
 * PARAMETERS
 *  job     [IN] Job
 * RETURNS
 *  void
 *****************************************************************************/
static void srv_da_oma_auto_resume_failed(srv_da_job_struct *job)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_omadl_job_struct *job_data;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/

    job_data = (srv_da_omadl_job_struct*)job->data_ptr;

    if (job_data->session != SRV_DA_WPS_INVALID_SESSION)
    {
        srv_da_wps_close_session(job_data->session, NULL);
        job_data->session = SRV_DA_WPS_INVALID_SESSION;
    }
    
#ifdef __MMI_DOWNLOAD_AGENT_MULTI_DL__
    if (job->setting_info.can_minimize)
    {
        job->state = SRV_DA_JOB_STATE_PAUSED;
        srv_da_oma_popup_and_send_report(job, SRV_DA_OMA_LOSS_OF_SERVICE, MMI_FALSE, MMI_TRUE);
        srv_da_update_job_status(job);
    }
    else
#endif /* __MMI_DOWNLOAD_AGENT_MULTI_DL__ */
    {
        job->state = SRV_DA_JOB_STATE_ABORTED;
        srv_da_oma_popup_and_send_report(job, SRV_DA_OMA_LOSS_OF_SERVICE, MMI_TRUE, MMI_TRUE);
    }
}


/*****************************************************************************
 * FUNCTION
 *  srv_da_oma_auto_resume_wps_created_callback
 * DESCRIPTION
 *  Auto-resume
 *  When WPS session is created successfully, send HTTP request.
 * PARAMETERS
 *  success     [IN] Session is created successfully
 *  arg         [IN] srv_da_job_struct*
 * RETURNS
 *  void
 *****************************************************************************/
static void srv_da_oma_auto_resume_wps_created_callback(MMI_BOOL success, U32 arg)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_job_struct           *job;
    srv_da_omadl_job_struct     *job_data;
    S8                          *header;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    job = (srv_da_job_struct*)arg;
    job_data = (srv_da_omadl_job_struct*)job->data_ptr;

    if (job->state == SRV_DA_JOB_STATE_ABORTING)
    {
        return;
    }

    MMI_EXT_ASSERT(job->state == SRV_DA_JOB_STATE_DOWNLOADING, job->state, 0, 0);

    if (!success)
    {
        srv_da_oma_auto_resume_failed(job);
    }
    else
    {
        header = (S8 *)srv_da_adp_mem_allocate(128);
        
        if (!srv_da_wps_http_req(
            job_data->session,
            WPS_HTTP_METHOD_GET,
            job_data->dd_info.objectURI,
            srv_da_util_gen_http_header_to_resume(header, job_data->etag, job_data->curr_size),
            NULL,
            job_data->filepath,
            0))
        {
            MMI_ASSERT(0);
        }

        srv_srv_da_adp_mem_free(header);
    }
    
}


/*****************************************************************************
 * FUNCTION
 *  srv_da_oma_auto_resume_wps_created_callback
 * DESCRIPTION
 *  For auto-resume.
 *  Check the HTTP response, to determine whether we successfully resumed.
 *  If not, prompt error message to the user eventually.
 * PARAMETERS
 *  arg             [IN] (mmi_da_oma_send_report_session_struct*)Session
 *  result          [IN] Result
 *  status          [IN] Status code which server responded
 *  header          [IN] HTTP header
 *  content_type    [IN] Content-Type
 *  content_len     [IN] Content-Length
 * RETURNS
 *  void
 *****************************************************************************/
static void srv_da_oma_auto_resume_wps_http_response_callback(
    U32 arg,
    U8 result,
    U16 status,
    S8 *header,
    S8 *content_type,
    U32 content_len,
    const wps_http_rsp_struct *rsp)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_job_struct           *job;
    srv_da_omadl_job_struct     *job_data;
    const applib_mime_type_struct *mime_type;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    job = (srv_da_job_struct*)arg;
    job_data = (srv_da_omadl_job_struct*)job->data_ptr;

    if (job->state == SRV_DA_JOB_STATE_ABORTING)
    {
        return;
    }

    MMI_EXT_ASSERT(job->state == SRV_DA_JOB_STATE_DOWNLOADING, job->state, 0, 0);

    MMI_TRACE(MMI_DA_TRACE_GROUP, MMI_DA_TRC_AUTO_RESUME_HTTP_RSP,
            DA_MAKE_UNIQUE_ID(job, job_data->unique_id), result, status,
            job_data->curr_size, content_len, job_data->size);

    /* check result */
    if(result != WPS_OK)
    {
        goto auto_resume_failed;
    }
    else
    {
        if (status != 206)
        {
            goto auto_resume_failed;
        }
        else
        {
            if (content_len == 0)
            {
                /* We can not guarantee the content is the same to before */
                goto auto_resume_failed;
            }
            else if (job_data->curr_size + content_len != job_data->size)
            {
                goto auto_resume_failed;
            }
        }
    }
    
    /* check mimetype */
    mime_type = srv_da_util_lookup_mime_type((U8*)content_type, NULL, 0, 0);

    /* Suppose their pointers will be the same (the same entry of our MIME type table) */
    if(job->mime_type != mime_type)
    {
        goto auto_resume_failed;
    }
    
    return;
    
auto_resume_failed:

    srv_da_oma_auto_resume_failed(job);
    
}


/*****************************************************************************
 * FUNCTION
 *  srv_da_oma_auto_resume_auth_ind_callback
 * DESCRIPTION
 *  Treat as resume failed if need authentication again.
 * PARAMETERS
 *  arg         [IN] (srv_da_job_struct*)Job
 * RETURNS
 *  void
 *****************************************************************************/
static void srv_da_oma_auto_resume_auth_ind_callback(U32 arg)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_job_struct           *job;
	srv_da_omadl_job_struct		*job_data;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/

    job = (srv_da_job_struct*)arg;

    MMI_ASSERT(job && job->type == SRV_DA_JOB_TYPE_OMADL);
    job_data = (srv_da_omadl_job_struct*)job->data_ptr;

    /* if auth info not valid yet, it means user need re-input */
    if(!job_data->auth_password || !job_data->auth_username || !job_data->auth_is_info_valid)
    {
   #ifndef MMI_DA_PLUTO_SLIM
        srv_da_adp_show_user_auth_screen((U32) job, srv_da_oma_user_auth_callback);
   #endif
    }
    else
    {
        srv_da_wps_session_auth_UCS2(job_data->session, job_data->auth_username, job_data->auth_password);
    }
    }




/*****************************************************************************
 * FUNCTION
 *  srv_da_oma_auto_resume_try_to_resume
 * DESCRIPTION
 *  For auto-resume.
 *  Try to resume. If the job is not in DOWNLOADING state, the resumption
 *  will not be triggered.
 * PARAMETERS
 *  arg         [IN] (srv_da_job_struct*)Job
 *  unique_id   [IN] This ID should match the job's
 * RETURNS
 *  void
 *****************************************************************************/
static void srv_da_oma_auto_resume_try_to_resume(void *arg, S32 unique_id)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_job_struct           *job;
    srv_da_omadl_job_struct     *job_data;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    job = (srv_da_job_struct*)arg;
    job_data = (srv_da_omadl_job_struct*)job->data_ptr;

    if (!srv_da_is_job_valid(job) ||
        job->type != SRV_DA_JOB_TYPE_OMADL ||
        job_data->unique_id != unique_id)
    {
        return;
    }

    /* To auto resume, the state should be still DOWNLOADING */
    if (job->state != SRV_DA_JOB_STATE_DOWNLOADING)
    {
        return;
    }
    
    MMI_ASSERT(job_data->session == SRV_DA_WPS_INVALID_SESSION);

    if (srv_da_is_allowed_to_trigger_connection())
    {
        MMI_TRACE(MMI_DA_TRACE_GROUP, MMI_DA_TRC_AUTO_RESUME_TRY,
            DA_MAKE_UNIQUE_ID(job, job_data->unique_id), job_data->curr_size);
    
        job_data->session = srv_da_wps_create_session_ex((U32)job,
                              SRV_DA_WPS_SETTING_DEFAULT,
                              job_data->channel,
                              srv_da_oma_auto_resume_wps_created_callback,
                              srv_da_oma_auto_resume_wps_http_response_callback,
                              srv_da_oma_auto_resume_auth_ind_callback,
                              srv_da_oma_session_dl_progress_callback);

#ifdef __MMI_DA_OMADL_CUST_CHL_SUPPORT__
        if (job->dl_flag & DA_DL_FLAG_SPECIAL)
        {
            MMI_BOOL unbuffered_write = MMI_TRUE;
            srv_da_wps_session_set_option(job_data->session,
                SRV_DA_WPS_OPTION_UNBUFFERED_WRITE,
                &(unbuffered_write));
        }
#endif /* __MMI_DA_OMADL_CUST_CHL_SUPPORT__ */

    }
    else
    {
        srv_da_oma_auto_resume_failed(job);
    }
}

#endif /* __MMI_DA_RESUME__ */

#ifdef __MMI_DA_OMADL_CUST_CHL_SUPPORT__


/*****************************************************************************
 * FUNCTION
 *  srv_da_start_oma_download
 * DESCRIPTION
 *  Now only DM can call this function.
 *  WILL BE DISCARDED IN THE FUTURE!
 * PARAMETERS
 * RETURNS
 *  void
 *****************************************************************************/
void srv_da_start_oma_download(
    S8* dd_filepath,
    void* req_data, 
    BOOL show_confirm,
    srv_da_dl_report_callback cb)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_job_struct           *job;
    srv_da_omadl_job_struct     *job_data;
    wps_set_channel_req_struct  *req = (wps_set_channel_req_struct*)req_data;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/

    MMI_TRACE(MMI_DA_TRACE_GROUP, MMI_DA_TRC_START_OMA_DL, (U32)dd_filepath, (U32)req_data, show_confirm, (U32)cb);
    
    DA_TRACE_FUNC2(srv_da_start_oma_download, 1, show_confirm);

    /* parse message & allocate a new job */
    job = srv_da_job_create_ex(SRV_DA_JOB_TYPE_OMADL, NULL);
    
    if (!job)
    {
#ifdef __MMI_DOWNLOAD_AGENT_MULTI_DL__
        DA_TRACE_FUNC2(srv_da_start_oma_download, 2, srv_da_get_last_error());
#endif

        srv_da_oma_popup_and_send_report(NULL, SRV_DA_OMA_DEVICE_ABORTED, MMI_TRUE, MMI_FALSE);
        
        if (cb != NULL)
        {
            cb(MMI_FALSE);
        }
        
        return;
    }
    
    job->dl_flag = DA_DL_FLAG_SPECIAL;
    
    srv_da_job_set_notify_callback(job, cb);
    
    if(!show_confirm)
        job->dl_flag |= DA_DL_FLAG_SKIP_CONFIRM;

    DA_ALLOC_OBJ(job_data, srv_da_omadl_job_struct);

    job->data_ptr = job_data;
     
    UCS2_STR_MALLOC_COPY(job_data->dd_filepath, dd_filepath);
    ANSI_STR_MALLOC_COPY(job_data->dd_url, "local://", 10);
    job_data->unique_id = srv_da_job_get_new_unique_id();
    job_data->etag = NULL;
    job_data->drm_status = SRV_DA_DRM_STATUS_NONE;
#ifdef __DRM_SUPPORT__
    job_data->drm_method = DRM_METHOD_NONE;
#endif
    job_data->drm_process_session = NULL;
    job_data->drm_wait_for_rights_session = NULL;
    job_data->time_to_wait_for_rights = -1;
    job_data->size = 0;
    
    if (req != NULL)
    {
        job_data->channel = srv_da_wps_reserve_cust_channel(req);
    }
    else
    {
        job_data->channel = SRV_DA_WPS_DEFAULT_CHANNEL;
    }
    
    srv_da_oma_parse_dd_and_show_confirm(job);
}
#endif

srv_da_job_struct* srv_da_oma_get_current_job (void)
{
    return da_oma_context.curr_job;
}

void srv_da_oma_set_current_job (srv_da_job_struct *job)
{
    da_oma_context.curr_job = job;
}

MMI_BOOL srv_da_oma_is_oma_processing_required (const applib_mime_type_struct *type)
{
    if (type &&
        (
    #ifdef __MMI_OMA_DD_DOWNLOAD__
         type->mime_subtype == MIME_SUBTYPE_OMA_DD ||
    #endif
    #ifdef __MMI_OMA_DD2_DOWNLOAD__
         type->mime_subtype == MIME_SUBTYPE_OMA_DD2 ||
    #endif
         MMI_FALSE ))
    {
        return MMI_TRUE;
    }
    return MMI_FALSE;
}

MMI_BOOL srv_da_oma_extract_dd_content_string (srv_da_job_struct *job)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_omadl_job_struct *job_data;
    S8          ddcontent[1000];
    S8          ddcontent2[2000];
    FS_HANDLE   hd = -1;
    UINT        fileSize, sizeRead;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    job_data = job->data_ptr;
    
    /* load text from DD */
    if ((hd = FS_Open(job_data->dd_filepath, FS_READ_ONLY)) < 0)
        goto errorFs;

    if(FS_GetFileSize(hd, &fileSize) < 0)
        goto errorFs;

    if(FS_Read(hd, ddcontent, fileSize, &sizeRead)<0)
        goto errorFs;

    ddcontent[sizeRead] = '\0';
    FS_Close(hd);
    hd = -1;

    mmi_chset_convert(MMI_CHSET_UTF8, MMI_CHSET_UCS2, (S8*)ddcontent, (S8*)ddcontent2, 1998); /*TODO: remove hardcoding */

    return MMI_TRUE;

    /* clean up if there is error */
errorFs:
    srv_da_adp_popup(0, hd, SRV_DA_POPUP_TYPE_FS_ERROR);

    if(hd >= 0)
        FS_Close(hd);
    return MMI_FALSE;
}


void srv_da_oma_fill_message_string(void *arg, U16 *buffer, U32 buffer_len)
{
#if 0
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif /* 0 */
}



void srv_da_oma_http_auth_ind_callback(U32 arg)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_job_struct           *job;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    job = (srv_da_job_struct*)arg;
    MMI_ASSERT(job && job->type == SRV_DA_JOB_TYPE_OMADL);
#ifndef MMI_DA_PLUTO_SLIM
    srv_da_adp_show_user_auth_screen ((U32) job, srv_da_oma_user_auth_callback);
#endif
#if 0
#ifdef __MMI_DA_OMADL_CUST_CHL_SUPPORT__
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif
/* under construction !*/
#if 0 //sahil to do in app       
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif //0
/* under construction !*/
#endif /* 0 */
}


void srv_da_oma_confirm_download_callback(void *arg, U16 *filepath)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_job_struct           *job;
    srv_da_omadl_job_struct     *job_data;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    job = (srv_da_job_struct*)arg;
    job_data = (srv_da_omadl_job_struct*)job->data_ptr;

    if(filepath == NULL)
    {
        /*----------------------------------------------------------------*/
        /* Local Variables                                                */
        /*----------------------------------------------------------------*/

        /*----------------------------------------------------------------*/
        /* Code Body                                                      */
        /*----------------------------------------------------------------*/
        MMI_ASSERT(srv_da_oma_get_current_job() == NULL || srv_da_oma_get_current_job() == job);
    #ifdef __MMI_DA_OMADL_CUST_CHL_SUPPORT__
        if (job->dl_flag & DA_DL_FLAG_SPECIAL)
        {
            srv_da_oma_select_storage(job);
            return;
        }
    #endif

    #ifdef MMI_DA_CFG_OMA_EXPOSE_DD_TO_USER
        srv_da_oma_set_current_job(job);
        srv_da_adp_display_oma_download_options((U32)job);
    #else
        srv_da_oma_select_storage(job);
    #endif
    }
    else
    {
    srv_da_set_allow_to_trigger_connection(MMI_TRUE);
    
    UCS2_STR_MALLOC_COPY(job_data->filepath, filepath);

#ifdef __MMI_DA_OMADL_CUST_CHL_SUPPORT__
    if(job->dl_flag & DA_DL_FLAG_SPECIAL)
    {
        FS_HANDLE hd;
        if ((hd = FS_Open((PU16)filepath, FS_READ_ONLY)) >= 0)
        {
            FS_GetFileSize(hd, &(job_data->curr_size));
            FS_Close(hd);
        }
    }
#endif
        
    srv_da_oma_set_current_job(NULL);

    job_data->session = srv_da_wps_create_session_ex(
        (U32)job,
        SRV_DA_WPS_SETTING_DEFAULT,
        job_data->channel,
        srv_da_oma_session_created_callback,
        srv_da_oma_http_response_callback,
        srv_da_oma_http_auth_ind_callback,
        srv_da_oma_session_dl_progress_callback);

#ifdef __MMI_DA_OMADL_CUST_CHL_SUPPORT__
    if (job->dl_flag & DA_DL_FLAG_SPECIAL)
    {
        MMI_BOOL unbuffered_write;
        unbuffered_write = MMI_TRUE;
        srv_da_wps_session_set_option(job_data->session, SRV_DA_WPS_OPTION_UNBUFFERED_WRITE, &(unbuffered_write));
    }
#endif
}
}

void srv_da_oma_download_cancel_callback(void *arg)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_job_struct *job;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    job = (srv_da_job_struct*)arg;
    
    srv_da_oma_open_nextURL(job);
    /* VIKAS */
    srv_da_oma_popup_and_send_report(job, SRV_DA_OMA_USER_CANCELLED, MMI_TRUE, MMI_FALSE);
}

void srv_da_oma_delete_screen_callback(void *arg)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_job_struct *job;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    job = (srv_da_job_struct*)arg;
    srv_da_oma_popup_and_send_report(job, SRV_DA_OMA_USER_CANCELLED, MMI_TRUE, MMI_FALSE);
}



/****************************************************************************
 * [Report Service]
 *
 * This utility is used to send OMA report. It provides capability of retrying,
 * and session automatical handling. It can send report in background, so that
 * clients can "launch-and-forget."
 ****************************************************************************/

/****************************************************************************
 * Constants & Configurations
 ****************************************************************************/

/*
 * If number of session sending report >= this value,
 * the session which has smallest num_to_try will stop re-sending.
 */
#define SRV_DA_OMA_SEND_REPORT_RESEND_THRESHOLD 3


#define SRV_DA_OMA_SEND_REPORT_INITED_MAGIC 0x68473827


/****************************************************************************
 * Typedef
 ****************************************************************************/

typedef struct srv_da_oma_send_report_session_struct_s
{
    U32 id;
    S8 *uri_to_post;
    S8 *content;
    U32 num_to_try;
    void *arg;
    void (*result_callback)(void *arg, srv_da_oma_send_report_result_enum result, U32 status_code);
    
    srv_da_wps_session_handle wps_session;

    struct srv_da_oma_send_report_session_struct_s *next;
} srv_da_oma_send_report_session_struct;


typedef struct
{
    /* For lazy initialization. If initialized, this field will set to SRV_DA_OMA_SEND_REPORT_INITED_MAGIC */
    U32 inited_magic;
    
    srv_da_oma_send_report_session_struct *session_list;
    U16 num_of_sessions;
    
    MMI_BOOL can_retry;
} srv_da_oma_send_report_context_struct;


/****************************************************************************
 * Global Variable
 ****************************************************************************/

static srv_da_oma_send_report_context_struct g_srv_da_oma_send_report_cntx;


/*****************************************************************************
 * FUNCTION
 *  srv_da_oma_send_report_init
 * DESCRIPTION
 *  Initialize send-report service. Before using send-report, be sure to
 *  initialize first.
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void srv_da_oma_send_report_init(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/

    if (g_srv_da_oma_send_report_cntx.inited_magic != SRV_DA_OMA_SEND_REPORT_INITED_MAGIC)
    {
        g_srv_da_oma_send_report_cntx.num_of_sessions = 0;
        g_srv_da_oma_send_report_cntx.session_list = NULL;
        g_srv_da_oma_send_report_cntx.can_retry = MMI_TRUE;
        g_srv_da_oma_send_report_cntx.inited_magic = SRV_DA_OMA_SEND_REPORT_INITED_MAGIC;
    }
}


/*****************************************************************************
 * FUNCTION
 *  srv_da_oma_send_report_can_retry
 * DESCRIPTION
 *  Test if it is proper to resend in current situation.
 * PARAMETERS
 *  void
 * RETURNS
 *  MMI_BOOL
 *****************************************************************************/
#define srv_da_oma_send_report_can_retry() \
    (g_srv_da_oma_send_report_cntx.can_retry && srv_da_is_allowed_to_trigger_connection())


/*****************************************************************************
 * FUNCTION
 *  srv_da_oma_send_report_is_session_valid
 * DESCRIPTION
 *  Check the validity of a session.
 * PARAMETERS
 *  session     [IN] Session
 * RETURNS
 *  MMI_BOOL
 *****************************************************************************/
static MMI_BOOL srv_da_oma_send_report_is_session_valid(srv_da_oma_send_report_session_struct *session)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_oma_send_report_session_struct *session_in_list;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    for (session_in_list = g_srv_da_oma_send_report_cntx.session_list; session_in_list != NULL; session_in_list = session_in_list->next)
    {
        if (session_in_list == session)
        {
            return MMI_TRUE;
        }
    }

    return MMI_FALSE;
}


/*****************************************************************************
 * FUNCTION
 *  srv_da_oma_send_report_new_session_id
 * DESCRIPTION
 *  Get a new and unique ID for session.
 * PARAMETERS
 *  void
 * RETURNS
 *  Unique ID
 *****************************************************************************/
static U32 srv_da_oma_send_report_new_session_id(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    static U32 next_id = 1;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    return (next_id++);
}


/*****************************************************************************
 * FUNCTION
 *  srv_da_oma_send_report_free_session
 * DESCRIPTION
 *  Free session. This function will remove the session from list and
 *  free all resource it used.
 * PARAMETERS
 *  session     [IN] Session
 * RETURNS
 *  void
 *****************************************************************************/
static void srv_da_oma_send_report_free_session(srv_da_oma_send_report_session_struct *session)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_oma_send_report_session_struct *s_in_list;
    srv_da_oma_send_report_session_struct *prev;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    prev = NULL;
    for (s_in_list = g_srv_da_oma_send_report_cntx.session_list; s_in_list != NULL; s_in_list = s_in_list->next)
    {
        if (s_in_list == session && s_in_list->id == session->id)
        {
            break;
        }

        prev = s_in_list;
    }

    if (s_in_list == NULL)
    {
        return;
    }

    /* Remove from list */
    if (prev == NULL)
    {
        g_srv_da_oma_send_report_cntx.session_list = session->next;
    }
    else
    {
        prev->next = session->next;
    }

    g_srv_da_oma_send_report_cntx.num_of_sessions--;
    
    
    srv_srv_da_adp_mem_free(session->uri_to_post);
    srv_srv_da_adp_mem_free(session->content);
    if (session->wps_session != SRV_DA_WPS_INVALID_SESSION)
    {
        srv_da_wps_close_session(session->wps_session, NULL);
    }
    srv_srv_da_adp_mem_free(session);

}


/*****************************************************************************
 * FUNCTION
 *  srv_da_oma_send_report_get_session_by_id
 * DESCRIPTION
 *  Search the list, get the session which ID equals to the given.
 * PARAMETERS
 *  id      [IN] Session ID
 * RETURNS
 *  Session; NULL if not found.
 *****************************************************************************/
static srv_da_oma_send_report_session_struct* srv_da_oma_send_report_get_session_by_id(U32 id)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_oma_send_report_session_struct *session;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    for (session = g_srv_da_oma_send_report_cntx.session_list; session != NULL; session = session->next)
    {
        if (session->id == id)
        {
            break;
        }
    }

    return session; /* If not found, returns NULL */
}


/*****************************************************************************
 * FUNCTION
 *  srv_da_oma_send_report_do_post
 * DESCRIPTION
 *  Post report to server and decrease num_to_try.
 * PARAMETERS
 *  arg     [IN/OUT] (srv_da_oma_send_report_session_struct*)Session
 *  id      [IN] Session ID
 * RETURNS
 *  void
 *****************************************************************************/
static void srv_da_oma_send_report_do_post(void *arg, S32 id)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_oma_send_report_session_struct *session;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    session = (srv_da_oma_send_report_session_struct*)arg;

    if (!srv_da_oma_send_report_is_session_valid(session) || session->id != (U32)id)
    {
        return;
    }

    MMI_TRACE(MMI_DA_TRACE_GROUP, MMI_DA_OMA_SEND_REPORT, session->id, session->num_to_try);

    if (session->num_to_try > 0)
    {
        session->num_to_try--;
    }

    srv_da_wps_http_req(session->wps_session,
        WPS_HTTP_METHOD_POST,
        session->uri_to_post,
        NULL,
        session->content,
        NULL,
        0);
}


/*****************************************************************************
 * FUNCTION
 *  srv_da_oma_send_report_session_created_callback
 * DESCRIPTION
 *  Session created handler for WPS service.
 * PARAMETERS
 *  success     [IN] MMI_TRUE if session is created successfully.
 *  arg         [IN] Session
 * RETURNS
 *  void
 *****************************************************************************/
static void srv_da_oma_send_report_session_created_callback(MMI_BOOL success, U32 arg)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_oma_send_report_session_struct *session;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    session = (srv_da_oma_send_report_session_struct*)arg;

    if (!srv_da_oma_send_report_is_session_valid(session))
    {
        return;
    }

    if (!success)
    {
        if (session->result_callback != NULL)
        {
            session->result_callback(session->arg, SRV_DA_OMA_SEND_REPORT_RESULT_FAILED, 0);
        }
        srv_da_oma_send_report_free_session(session);
        return;
    }
    
    srv_da_oma_send_report_do_post(session, session->id);
}


/*****************************************************************************
 * FUNCTION
 *  srv_da_oma_send_report_http_response_callback
 * DESCRIPTION
 *  HTTP response handler for WPS session.
 * PARAMETERS
 *  arg             [IN] (srv_da_oma_send_report_session_struct*)Session
 *  result          [IN] Result
 *  status          [IN] Status code which server responded
 *  header          [IN] HTTP header
 *  content_type    [IN] Content-Type
 *  content_len     [IN] Content-Length
 * RETURNS
 *  void
 *****************************************************************************/
static void srv_da_oma_send_report_http_response_callback(
    U32 arg,
    U8 result,
    U16 status,
    S8 *header,
    S8 *content_type,
    U32 content_len,
    const wps_http_rsp_struct *rsp)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_oma_send_report_session_struct *session;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    session = (srv_da_oma_send_report_session_struct*)arg;

    if (!srv_da_oma_send_report_is_session_valid(session))
    {
        return;
    }

    if (result == WPS_OK)
    {
        if (session->result_callback != NULL)
        {
            srv_da_oma_send_report_result_enum result;

            if (200 <= status && status < 300)
            {
                result = SRV_DA_OMA_SEND_REPORT_RESULT_OK;
            }
            else if (status == 504) /* 504 Gateway timeout */
            {
                result = SRV_DA_OMA_SEND_REPORT_RESULT_TIMEOUT;
            }
            else
            {
                result = SRV_DA_OMA_SEND_REPORT_RESULT_FAILED;
            }

            srv_da_wps_close_session(session->wps_session, NULL);
            session->wps_session = SRV_DA_WPS_INVALID_SESSION;
        
            session->result_callback(session->arg, result, status);
        }
        
        srv_da_oma_send_report_free_session(session);
    }
    else if ((result == WPS_ERROR_REQ_ABORT && rsp->cause == WPS_CAUSE_COMM_NO_RESPONSE) && /* Timeout */
        srv_da_oma_send_report_can_retry())
    {
        if (session->num_to_try > 0)
        {
            srv_da_util_trigger_proc_ext(srv_da_oma_send_report_do_post, session, session->id);
        }
        else /* Exceeds max number to retry */
        {
            srv_da_wps_close_session(session->wps_session, NULL);
            session->wps_session = SRV_DA_WPS_INVALID_SESSION;

            if (session->result_callback != NULL)
            {
                session->result_callback(session->arg, SRV_DA_OMA_SEND_REPORT_RESULT_TIMEOUT, status);
            }

            srv_da_oma_send_report_free_session(session);
        }
    }
    else /* Other error */
    {
        if (session->num_to_try > 0 &&
            srv_da_oma_send_report_can_retry() &&
            (session->result_callback != NULL && srv_da_wps_is_bearer_activated((U32)session->arg)))
        {
            srv_da_util_trigger_proc_ext(srv_da_oma_send_report_do_post, session, session->id);
        }
        else
        {
            if (session->num_to_try > 0)
            {
                MMI_TRACE(MMI_DA_TRACE_GROUP, MMI_DA_OMA_SEND_REPORT_STOP_RETRY, session->id, session->num_to_try);
            }
        
            if (session->result_callback != NULL)
            {
                srv_da_wps_close_session(session->wps_session, NULL);
                session->wps_session = SRV_DA_WPS_INVALID_SESSION;
            
                session->result_callback(session->arg, SRV_DA_OMA_SEND_REPORT_RESULT_FAILED, status);
            }

            srv_da_oma_send_report_free_session(session);
        }
    }
}


/*****************************************************************************
 * FUNCTION
 *  srv_da_oma_send_report_http_auth_callback
 * DESCRIPTION
 *  HTTP authtication handler for WPS session.
 *  Stop sending report and notify FAILED.
 * PARAMETERS
 *  arg         [IN] (srv_da_oma_send_report_session_struct*)Session
 * RETURNS
 *  void
 *****************************************************************************/
static void srv_da_oma_send_report_http_auth_callback(U32 arg)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_oma_send_report_session_struct *session;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    session = (srv_da_oma_send_report_session_struct*)arg;

    if (!srv_da_oma_send_report_is_session_valid(session))
    {
        return;
    }
    
    if (session->result_callback != NULL)
    {
        srv_da_wps_close_session(session->wps_session, NULL);
        session->wps_session = SRV_DA_WPS_INVALID_SESSION;
        
        session->result_callback(session->arg, SRV_DA_OMA_SEND_REPORT_RESULT_FAILED, 401); /* 401 Unauthroized */
    }

    srv_da_oma_send_report_free_session(session);
}


/*****************************************************************************
 * FUNCTION
 *  srv_da_oma_send_report
 * DESCRIPTION
 *  Start to send report.
 * PARAMETERS
 *  uri_to_post     [IN] The URI to post report.
 *  content         [IN] Report
 *  num_to_try      [IN] The total number to send report if no response.
 *  channel         [IN] Use specific channel, can be SRV_DA_WPS_DEFAULT_CHANNEL.
 *  arg             [IN] Will be passed to result_callback()
 *  result_callback [IN] Result callback function
 * RETURNS
 *  Session ID; will not be 0 if the session was created successfully
 *****************************************************************************/
U32 srv_da_oma_send_report(
    const S8 *uri_to_post,
    const S8 *content,
    U32 num_to_try,
    srv_da_wps_channel_handle channel,
    void *arg,
    void (*result_callback)(void *arg, srv_da_oma_send_report_result_enum result, U32 status_code))
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_oma_send_report_session_struct *session;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    srv_da_oma_send_report_init();
    
    if (num_to_try == 0)
    {
        num_to_try = SRV_DA_OMA_SEND_REPORT_DEFAULT_NUM_TO_TRY;
    }

    g_srv_da_oma_send_report_cntx.can_retry = MMI_TRUE;
    
    session = (srv_da_oma_send_report_session_struct*)srv_da_adp_mem_allocate(sizeof(srv_da_oma_send_report_session_struct));

    session->id = srv_da_oma_send_report_new_session_id();
    session->uri_to_post = (S8 *) srv_da_adp_mem_allocate(strlen(uri_to_post) + 1);
    strcpy(session->uri_to_post, uri_to_post);
    session->content = (S8 *)srv_da_adp_mem_allocate(strlen(content) + 1);
    strcpy(session->content, content);
    session->num_to_try = num_to_try;
    session->arg = arg;
    session->result_callback = result_callback;
    session->wps_session = SRV_DA_WPS_INVALID_SESSION;

    session->next = g_srv_da_oma_send_report_cntx.session_list;
    g_srv_da_oma_send_report_cntx.session_list = session;
    g_srv_da_oma_send_report_cntx.num_of_sessions++;


    if (g_srv_da_oma_send_report_cntx.num_of_sessions >= SRV_DA_OMA_SEND_REPORT_RESEND_THRESHOLD)
    {
        srv_da_oma_send_report_session_struct *candidate;
        srv_da_oma_send_report_session_struct *s_in_list;

        candidate = session->next;

        if (candidate != NULL)
        {
            /* Pick the session which has smallest num_to_try */
            for (s_in_list = candidate; s_in_list != NULL; s_in_list = s_in_list->next)
            {
                if (s_in_list->result_callback == NULL && candidate->result_callback != NULL)
                {
                    /* Pick the report not need to notify user first */
                    candidate = s_in_list;
                }
                else if (
                    ((s_in_list->result_callback != NULL && candidate->result_callback != NULL) ||
                        (s_in_list->result_callback == NULL && candidate->result_callback == NULL)) &&
                    s_in_list->num_to_try < candidate->num_to_try)
                {
                    /* Pick the report has smallest num_to_try first */
                    candidate = s_in_list;
                }
            }

            MMI_TRACE(MMI_DA_TRACE_GROUP, MMI_DA_OMA_SEND_REPORT_STOP_RETRY,
                candidate->id, candidate->num_to_try);

            /* Stop retrying */
            candidate->num_to_try = 0;
        }
    }

#ifdef __MMI_DA_OMADL_CUST_CHL_SUPPORT__
    if (channel != SRV_DA_WPS_DEFAULT_CHANNEL)
    {
        session->wps_session = srv_da_wps_create_session_ex(
            (U32)session,
            SRV_DA_WPS_SETTING_OMA_REPORT,
            channel,
            srv_da_oma_send_report_session_created_callback,
            srv_da_oma_send_report_http_response_callback,
            srv_da_oma_send_report_http_auth_callback,
            NULL);
    }
    else
#endif
    {
        session->wps_session = srv_da_wps_create_session(
            (U32)session,
            SRV_DA_WPS_SETTING_OMA_REPORT,
            srv_da_oma_send_report_session_created_callback,
            srv_da_oma_send_report_http_response_callback,
            srv_da_oma_send_report_http_auth_callback,
            NULL);
    }

    return session->id;
}


/*****************************************************************************
 * FUNCTION
 *  srv_da_oma_send_report_cancel
 * DESCRIPTION
 *  Stop sending report.
 * PARAMETERS
 *  session_id  [IN] Session ID
 * RETURNS
 *  void
 *****************************************************************************/
void srv_da_oma_send_report_cancel(U32 session_id)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_da_oma_send_report_session_struct *session;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    session = srv_da_oma_send_report_get_session_by_id(session_id);

    if (session == NULL)
    {
        return;
    }

    MMI_TRACE(MMI_DA_TRACE_GROUP, MMI_DA_OMA_SEND_REPORT_CANCEL, session->id, session->num_to_try);

    srv_da_oma_send_report_free_session(session);
    
}


/*****************************************************************************
 * FUNCTION
 *  srv_da_oma_send_report_get_number_of_sessions
 * DESCRIPTION
 *  Get the number of reports sending.
 * PARAMETERS
 *  void
 * RETURNS
 *  The number of reports sending.
 *****************************************************************************/
U32 srv_da_oma_send_report_get_number_of_sessions(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    return g_srv_da_oma_send_report_cntx.num_of_sessions;
}


/*****************************************************************************
 * FUNCTION
 *  srv_da_oma_send_report_stop_retrying
 * DESCRIPTION
 *  Stop re-sending.
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void srv_da_oma_send_report_stop_retrying(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    g_srv_da_oma_send_report_cntx.can_retry = MMI_FALSE;
}
void srv_da_oma_set_storage_selection(MMI_BOOL new_value)
{
#ifdef __MMI_DA_USER_SELECT_DOWNLOAD_LOCATION__
    da_storage_selection = new_value;
#endif
}
#endif /*__MMI_OMA_DD_DOWNLOAD__ */
#endif /* __MMI_DOWNLOAD_AGENT__ */