22
33import static com .eveningoutpost .dexdrip .models .JoH .emptyString ;
44import static com .eveningoutpost .dexdrip .cgm .webfollow .Agent .get ;
5+ import static com .eveningoutpost .dexdrip .utils .CipherUtils .getSHA256 ;
56
67import com .eveningoutpost .dexdrip .models .BgReading ;
78import com .eveningoutpost .dexdrip .models .JoH ;
1011
1112import org .json .JSONObject ;
1213
14+ import java .nio .charset .StandardCharsets ;
1315import java .text .ParseException ;
1416import java .text .SimpleDateFormat ;
1517import java .util .Locale ;
3234@ RequiredArgsConstructor
3335public class Cmd {
3436 private static final String PUSH_METHOD = "push" ;
37+ private static final String FPUSH_METHOD = "fpush" ;
38+ private static final String CPUSH_METHOD = "cpush" ;
3539 private static final String JSON_METHOD = "jput" ;
3640 private static final String JSON_TYPE = "application/json" ;
3741 private static final MediaType JSON = MediaType .parse (JSON_TYPE );
@@ -103,6 +107,18 @@ public boolean process(final String cmd) {
103107 }
104108 return true ;
105109
110+ case "vSet" :
111+ if (!JoH .emptyString (m .getByName (pc [2 ]))) {
112+ m .doAction (pc [1 ]);
113+ }
114+ return true ;
115+
116+ case "vuSet" :
117+ if (JoH .emptyString (m .getByName (pc [2 ]))) {
118+ m .doAction (pc [1 ]);
119+ }
120+ return true ;
121+
106122 case "evaluate" :
107123 evaluate (parts .length > 1 ? parts [1 ].split (";" ) : null );
108124 return true ;
@@ -125,17 +141,28 @@ public boolean process(final String cmd) {
125141
126142 switch (p1s [0 ]) {
127143
144+ case FPUSH_METHOD :
145+ case CPUSH_METHOD :
128146 case PUSH_METHOD :
129147 for (val as : asn ) {
130- val ass = as .split ("-" );
148+ m .log ("PUSH: as: " + as );
149+ val ass = as .split ("-" , 2 );
131150 val tok = ass [1 ].split (";" );
132- val tick = m .getByName (tok [1 ]);
151+ val tick = ( tok [ 1 ]. charAt ( 0 ) == '\'' ) ? tok [ 1 ]. substring ( 1 ) : m .getByName (tok [1 ]); // handle string literal
133152 if (tick == null ) {
134153 m .loge (tok [1 ] + " is null in " + as );
135154 return false ;
136155 }
137- m .log ("Setting: :" + ass [0 ] + ": to :" + String .format (tok [0 ], tick ));
138- cb .getClass ().getMethod (ass [0 ], String .class ).invoke (cb , String .format (tok [0 ], m .getByName (tok [1 ])));
156+ val mtick = mutate (tick , tok );
157+ m .log ("Setting: :" + ass [0 ] + ": to :" + String .format (tok [0 ], mtick ));
158+ if (p1s [0 ].equals (CPUSH_METHOD )) {
159+ m .setByName (ass [0 ], String .format (tok [0 ], mtick ));
160+ } else {
161+ cb .getClass ().getMethod (ass [0 ], String .class ).invoke (cb , String .format (tok [0 ], mtick ));
162+ }
163+ }
164+ if (!p1s [0 ].equals (PUSH_METHOD )) {
165+ return true ;
139166 }
140167 break ;
141168
@@ -177,6 +204,7 @@ public boolean process(final String cmd) {
177204 return presult ;
178205 } catch (Exception e ) {
179206 m .log ("Pprocess exception: " + e );
207+ e .printStackTrace ();
180208 return false ;
181209 }
182210 } catch (com .google .gson .JsonSyntaxException e ) {
@@ -193,13 +221,25 @@ public boolean process(final String cmd) {
193221 Cpref .startWithRefresh (true );
194222 }
195223 }
224+ e .printStackTrace ();
196225 } else {
197226 e .printStackTrace ();
198227 }
199228 }
200229 return false ;
201230 }
202231
232+ private String mutate (String tick , final String [] t ) throws NoSuchFieldException , IllegalAccessException {
233+ if (tick != null ) {
234+ val a1 = "%sha256" ;
235+ if (t [0 ].contains (a1 )) {
236+ t [0 ] = t [0 ].replace (a1 , "%s" );
237+ tick = getSHA256 (tick .getBytes (StandardCharsets .UTF_8 ));
238+ }
239+ }
240+ return tick ;
241+ }
242+
203243 private boolean pprocess (final String [] p3s , final Mapifier map ) {
204244 for (val psa : p3s ) {
205245 val pss = psa .split ("-" );
@@ -209,6 +249,7 @@ private boolean pprocess(final String[] p3s, final Mapifier map) {
209249 case "AZ" :
210250 val psd = map .pluckDouble (pss [0 ]);
211251 val ret = psd == 0d ;
252+ m .log ("AZ ret: " + ret );
212253 if (!ret ) {
213254 if (psd > 0d ) {
214255 m .token = null ;
@@ -220,6 +261,7 @@ private boolean pprocess(final String[] p3s, final Mapifier map) {
220261 }
221262 } catch (Exception e ) {
222263 m .loge ("pprocess exception: " + e );
264+ e .printStackTrace ();
223265 }
224266 }
225267 return false ;
@@ -228,7 +270,7 @@ private boolean pprocess(final String[] p3s, final Mapifier map) {
228270 private boolean extract (final String [] p2s , final Mapifier map ) throws NoSuchFieldException , IllegalAccessException , ParseException {
229271 for (val psa : p2s ) {
230272 val pss = psa .split ("-" );
231- val type = pss [0 ].replaceAll ("[a-z]" , "" );
273+ val type = pss [0 ].replaceAll ("[a-z! ]" , "" );
232274 val var = pss [0 ].replaceAll ("[A-Z]" , "" );
233275
234276 switch (type ) {
@@ -243,13 +285,21 @@ private boolean extract(final String[] p2s, final Mapifier map) throws NoSuchFie
243285 m .log ("Setting Any: " + var + " to " + map .pluckAny (pss [1 ]) + " <- " + var );
244286 break ;
245287 case "" :
246- val mvalue = map .pluckString (pss [1 ]);
247- if (mvalue .length () < 2 ) {
248- m .log ("Bad value: " + mvalue );
249- return false ;
288+ try {
289+ val mvalue = map .pluckString (pss [1 ]);
290+ if (mvalue == null || mvalue .length () < 2 ) {
291+ m .log ("Bad value: " + mvalue + " for " + pss [1 ]);
292+ return var .endsWith ("!" );
293+ }
294+ m .setByName (var , mvalue );
295+ m .log ("Setting String: " + var + " to " + mvalue + " <- " + pss [1 ]);
296+ } catch (RuntimeException e ) {
297+ val es = "" + e ;
298+ if (es .contains ("Invalid" )) {
299+ m .loge (es );
300+ }
301+ throw e ;
250302 }
251- m .setByName (var , mvalue );
252- m .log ("Setting String: " + var + " to " + mvalue + " <- " + pss [1 ]);
253303 break ;
254304 default :
255305 throw new RuntimeException ("Invalid type :" + type + ": <- " + var );
0 commit comments