Ticket #3155: patch3155

File patch3155, 7.8 KB (added by morpheuz@…, 17 years ago)

modifies httpstatus.cpp

Line 
1Index: programs/mythbackend/httpstatus.cpp
2===================================================================
3--- programs/mythbackend/httpstatus.cpp (revision 12904)
4+++ programs/mythbackend/httpstatus.cpp (working copy)
5@@ -83,6 +83,10 @@
6     if (sURI == "getCMGRDesc"          ) return( HSM_GetCMGRDesc     );
7     if (sURI == "getMSRRDesc"          ) return( HSM_GetMSRRDesc     );
8 
9+    if (sURI == "getRecProfiles"       ) return( HSM_GetRecProfiles   );
10+    if (sURI == "delRecProfiles"       ) return( HSM_DelRecProfiles   );
11+    if (sURI == "createRecProfiles"    ) return( HSM_CreateRecProfiles);
12+
13     if (sURI == "*"                    ) return( HSM_Asterisk        );
14 
15     return( HSM_Unknown );
16@@ -124,6 +128,10 @@
17                 case HSM_GetMusic       : GetMusic       ( pThread, pRequest ); return( true );
18                 case HSM_GetVideo       : GetVideo       ( pThread, pRequest ); return( true );
19 
20+                case HSM_GetRecProfiles    : GetRecProfiles    ( pRequest ); return( true );
21+                case HSM_DelRecProfiles    : DelRecProfiles    ( pRequest ); return( true );
22+                case HSM_CreateRecProfiles : CreateRecProfiles ( pRequest ); return( true );
23+
24                 default:
25                 {
26                                    pRequest->m_eResponseType   = ResponseTypeHTML;
27@@ -1236,6 +1244,142 @@
28 //
29 /////////////////////////////////////////////////////////////////////////////
30 
31+void HttpStatus::GetRecProfiles( HTTPRequest *pRequest )
32+{
33+    QString group_name = pRequest->m_mapParams[ "groupname" ];
34+
35+    // Build Response XML
36+    QDomDocument doc( "Profiles" );
37+
38+    QDomElement root = doc.createElement("Profiles");
39+    doc.appendChild(root);
40+
41+    root.setAttribute("asOf"      , QDateTime::currentDateTime().toString( Qt::ISODate ));
42+    root.setAttribute("version"   , MYTH_BINARY_VERSION           );
43+    root.setAttribute("protoVer"  , MYTH_PROTO_VERSION            );
44+
45+    MSqlQuery query(MSqlQuery::InitCon());
46+
47+    if (group_name != "")
48+    {
49+        query.prepare( "SELECT r.* FROM recordingprofiles r,profilegroups p"
50+                        " WHERE p.name=:GROUPNAME AND r.profilegroup = p.id" );
51+        query.bindValue(":GROUPNAME", group_name);
52+    } else
53+        query.prepare( "SELECT * FROM recordingprofiles" );
54+
55+    if (!query.exec() || !query.isActive())
56+        MythContext::DBError("No Profiles", query);
57+
58+    if (query.size() > 0)
59+    {
60+
61+        while(query.next())
62+        {
63+            QDomElement profile = doc.createElement("Profile");
64+            root.appendChild(profile);
65+
66+            profile.setAttribute("acodec"   , query.value(3).toString());
67+            profile.setAttribute("vcodec"   , query.value(2).toString());
68+            profile.setAttribute("name"     , query.value(1).toString());
69+            profile.setAttribute("id"       , query.value(0).toString());
70+
71+        }
72+
73+    }
74+
75+    // Sends back the response
76+    pRequest->m_mapRespHeaders[ "Cache-Control" ] = "no-cache=\"Ext\", max-age = 5000";
77+    pRequest->m_eResponseType = ResponseTypeXML;
78+    pRequest->m_response << doc.toString();
79+
80+}
81+
82+/////////////////////////////////////////////////////////////////////////////
83+//
84+/////////////////////////////////////////////////////////////////////////////
85+void HttpStatus::CreateRecProfiles( HTTPRequest *pRequest )
86+{
87+    pRequest->m_eResponseType   = ResponseTypeXML;
88+    pRequest->m_mapRespHeaders[ "Cache-Control" ] = "no-cache=\"Ext\", max-age = 5000";
89+
90+    QString profile_name = pRequest->m_mapParams[ "profilename" ];
91+    QString group_name   = pRequest->m_mapParams[ "groupname" ];
92+    QString vcodec       = pRequest->m_mapParams[ "vcodec" ];
93+    QString acodec       = pRequest->m_mapParams[ "acodec" ];
94+
95+    if (profile_name != "" && vcodec != "" && acodec != "" && group_name != "")
96+    {
97+        MSqlQuery query(MSqlQuery::InitCon());
98+
99+        query.prepare("SELECT id FROM profilegroups WHERE name=:GROUPNAME");
100+        query.bindValue(":GROUPNAME", group_name);
101+
102+        if (!query.exec() || !query.isActive())
103+            MythContext::DBError("Query problem while trying to "
104+                                 "retrieve id from Group_Name", query);
105+
106+        if (query.size() > 0)
107+        {
108+            query.first();
109+            QString group = query.value(0).toString();
110+
111+            query.prepare("INSERT INTO recordingprofiles VALUES"
112+                        " (NULL,:PNAME,:VCODEC,:ACODEC,:GROUP)" );
113+            query.bindValue(":PNAME", profile_name );
114+            query.bindValue(":VCODEC", vcodec );
115+            query.bindValue(":ACODEC", acodec );
116+            query.bindValue(":GROUP", group );
117+
118+            if (!query.exec() || !query.isActive())
119+            {
120+                MythContext::DBError("Problems while inserting profile", query);
121+                pRequest->m_response <<  "<Error>Problem with the MySQL Query</Error>";
122+            }
123+            else pRequest->m_response <<  "<Success>Profile Created</Success>";
124+
125+        }
126+        else
127+            pRequest->m_response <<  "<Error>No Result from SQL Query</Error>";
128+    }
129+    else
130+        pRequest->m_response <<  "<Error>You must specify ALL the parameters</Error>";
131+}
132+
133+/////////////////////////////////////////////////////////////////////////////
134+//
135+/////////////////////////////////////////////////////////////////////////////
136+
137+void HttpStatus::DelRecProfiles( HTTPRequest *pRequest )
138+{
139+    pRequest->m_eResponseType   = ResponseTypeXML;
140+    pRequest->m_mapRespHeaders[ "Cache-Control" ] = "no-cache=\"Ext\", max-age = 5000";
141+
142+    QString profile_id = pRequest->m_mapParams[ "id" ];
143+
144+    if (profile_id != "")
145+    {
146+        MSqlQuery query(MSqlQuery::InitCon());
147+        query.prepare("DELETE FROM recordingprofiles WHERE"
148+                    " id = :ID" );
149+        query.bindValue(":ID", profile_id );
150+
151+        if (!query.exec() || !query.isActive())
152+        {
153+            MythContext::DBError("Problems while deleting profile", query);
154+            pRequest->m_response <<  "<Error>Problem with the MySQL Query</Error>";
155+        }
156+        else pRequest->m_response <<  "<Success>Profile Deleted</Success>";
157+
158+    }
159+    else
160+        pRequest->m_response <<  "<Error>You must specify the id to delete</Error>";
161+}
162+
163+/////////////////////////////////////////////////////////////////////////////
164+//
165+/////////////////////////////////////////////////////////////////////////////
166+
167 void HttpStatus::GetStatusXML( HTTPRequest *pRequest )
168 {
169     QDomDocument doc( "Status" );                       
170Index: programs/mythbackend/httpstatus.h
171===================================================================
172--- programs/mythbackend/httpstatus.h   (revision 12904)
173+++ programs/mythbackend/httpstatus.h   (working copy)
174@@ -1,4 +1,5 @@
175-//////////////////////////////////////////////////////////////////////////////
176+//////////
177+////////////////////////////////////////////////////////////////////
178 // Program Name: httpstatus.h
179 //                                                                           
180 // Purpose - Html & XML status HttpServerExtension
181@@ -51,8 +52,12 @@
182     HSM_GetProgramDetails = 18,
183 
184     HSM_GetVideo        = 19,
185-    HSM_GetMSRRDesc     = 20
186+    HSM_GetMSRRDesc     = 20,
187 
188+    HSM_GetRecProfiles    = 21,
189+    HSM_DelRecProfiles    = 22,
190+    HSM_CreateRecProfiles = 23
191+
192 } HttpStatusMethod;
193 
194 /////////////////////////////////////////////////////////////////////////////
195@@ -180,6 +185,10 @@
196         void    GetVideo       ( HttpWorkerThread *pThread,
197                                  HTTPRequest      *pRequest );
198 
199+        void    GetRecProfiles    ( HTTPRequest *pRequest );
200+        void    DelRecProfiles    ( HTTPRequest *pRequest );
201+        void    CreateRecProfiles ( HTTPRequest *pRequest );
202+
203         void    GetDeviceDesc  ( HTTPRequest *pRequest );
204         void    GetFile        ( HTTPRequest *pRequest, QString sFileName );
205