1 /**************************************************************************/
2 /*                                                                        */
3 /*       Copyright (c) Microsoft Corporation. All rights reserved.        */
4 /*                                                                        */
5 /*       This software is licensed under the Microsoft Software License   */
6 /*       Terms for Microsoft Azure RTOS. Full text of the license can be  */
7 /*       found in the LICENSE file at https://aka.ms/AzureRTOS_EULA       */
8 /*       and in the root directory of this software.                      */
9 /*                                                                        */
10 /**************************************************************************/
11 
12 
13 /**************************************************************************/
14 /**************************************************************************/
15 /**                                                                       */
16 /** USBX Component                                                        */
17 /**                                                                       */
18 /**   Pictbridge Application                                              */
19 /**                                                                       */
20 /**************************************************************************/
21 /**************************************************************************/
22 
23 
24 /* Include necessary system files.  */
25 
26 #define UX_SOURCE_CODE
27 
28 #include "ux_api.h"
29 #include "ux_pictbridge.h"
30 
31 
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _ux_pictbridge_xml_function_input_startjob_printinfo_croppingarea   */
37 /*                                                        PORTABLE C      */
38 /*                                                           6.1          */
39 /*                                                                        */
40 /*                                                                        */
41 /*  AUTHOR                                                                */
42 /*                                                                        */
43 /*    Chaoqiong Xiao, Microsoft Corporation                               */
44 /*                                                                        */
45 /*  DESCRIPTION                                                           */
46 /*                                                                        */
47 /*    This function decodes the "croppingarea" tag                        */
48 /*    It is followed by 4 coordinates in hexa form.                       */
49 /*                                                                        */
50 /*  INPUT                                                                 */
51 /*                                                                        */
52 /*    pictbridge                             Pictbridge instance          */
53 /*    input_variable                         Pointer to variable          */
54 /*    input_string                           Pointer to string            */
55 /*                                                                        */
56 /*  OUTPUT                                                                */
57 /*                                                                        */
58 /*    Completion Status                                                   */
59 /*                                                                        */
60 /*  CALLS                                                                 */
61 /*                                                                        */
62 /*                                                                        */
63 /*  CALLED BY                                                             */
64 /*                                                                        */
65 /*    _ux_pictbridge_object_parse                                         */
66 /*                                                                        */
67 /*  RELEASE HISTORY                                                       */
68 /*                                                                        */
69 /*    DATE              NAME                      DESCRIPTION             */
70 /*                                                                        */
71 /*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
72 /*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
73 /*                                            verified memset and memcpy  */
74 /*                                            cases,                      */
75 /*                                            resulting in version 6.1    */
76 /*                                                                        */
77 /**************************************************************************/
_ux_pictbridge_xml_function_input_startjob_printinfo_croppingarea(UX_PICTBRIDGE * pictbridge,UCHAR * input_variable,UCHAR * input_string,UCHAR * xml_parameter)78 UINT  _ux_pictbridge_xml_function_input_startjob_printinfo_croppingarea(UX_PICTBRIDGE *pictbridge,
79                             UCHAR *input_variable, UCHAR *input_string, UCHAR *xml_parameter)
80 {
81 UINT    length = 0;
82 ULONG   index;
83 UINT    status;
84 UCHAR   element_string[UX_PICTBRIDGE_MAX_ELEMENT_SIZE];
85 UCHAR   *element_ptr;
86 ULONG   element_length;
87 ULONG   hexa_value;
88 
89     UX_PARAMETER_NOT_USED(input_string);
90     UX_PARAMETER_NOT_USED(input_variable);
91 
92     /* The xml parameter is pointing to the beginning of the 4 coordinates. They are separated
93        by spaces. Each has 4 bytes in hexadecimal. We need to extract each ones and store them
94        in the printinfo area.  */
95     status = _ux_utility_string_length_check(xml_parameter, &length, UX_PICTBRIDGE_MAX_TAG_SIZE);
96     if (status != UX_SUCCESS)
97         return(status);
98 
99     /* Ensure the length is non zero, otherwise that means the tag has no parameter.  */
100     if (length == 0)
101 
102         /* That's a syntax error.  */
103         return(UX_PICTBRIDGE_ERROR_SCRIPT_SYNTAX_ERROR);
104 
105     /* Reset the cropping area index. */
106     index = 0;
107 
108     /* Reset the element area.  */
109    _ux_utility_memory_set(element_string, 0, UX_PICTBRIDGE_MAX_ELEMENT_SIZE); /* Use case of memset is verified. */
110 
111    /* And its length.  */
112    element_length = 0;
113 
114    /* Set the pointer to the beginning of the element string.  */
115    element_ptr =  element_string;
116 
117     /* Now parse the line and isolate each component of the cropping area.  */
118     /* Get the length of the "papersize " variable.  */
119     while(length != 0)
120     {
121 
122         /* Get a character from the xml parameter.  Check for delimiter. */
123         if (*xml_parameter == UX_PICTBRIDGE_TAG_CHAR_SPACE)
124         {
125 
126             /* Do we have a element ?  */
127             if (element_length != 0)
128             {
129 
130                 /* Yes we do, get the hexa value for that element.  */
131                 status =  _ux_pictbridge_element_to_hexa(element_string, &hexa_value);
132 
133                 /* Check for error.  */
134                 if (status != UX_SUCCESS)
135 
136                     /* We have a element syntax error.  */
137                     return(status);
138 
139                 /* Where to store this element.  */
140                 switch (index)
141                 {
142 
143                     case 0 :
144 
145                         /* This is the X coordinate of the cropping area.  */
146                         pictbridge -> ux_pictbridge_jobinfo.ux_pictbridge_jobinfo_printinfo_current -> ux_pictbridge_printinfo_croppingarea_xcoordinate = hexa_value;
147 
148                         break;
149 
150                     case 1 :
151 
152                         /* This is the Y coordinate of the cropping area.  */
153                         pictbridge -> ux_pictbridge_jobinfo.ux_pictbridge_jobinfo_printinfo_current -> ux_pictbridge_printinfo_croppingarea_ycoordinate = hexa_value;
154 
155                         break;
156                     case 2 :
157 
158                         /* This is the width of the cropping area.  */
159                         pictbridge -> ux_pictbridge_jobinfo.ux_pictbridge_jobinfo_printinfo_current -> ux_pictbridge_printinfo_croppingarea_width = hexa_value;
160 
161                         break;
162                     case 3 :
163                         /* This is the height of the cropping area.  */
164                         pictbridge -> ux_pictbridge_jobinfo.ux_pictbridge_jobinfo_printinfo_current -> ux_pictbridge_printinfo_croppingarea_height = hexa_value;
165 
166                         break;
167                 }
168 
169                 /* Next index now.  */
170                 index++;
171 
172                 /* Reset the element area.  */
173                _ux_utility_memory_set(element_string, 0, UX_PICTBRIDGE_MAX_ELEMENT_SIZE); /* Use case of memset is verified. */
174 
175                /* And its length.  */
176                element_length = 0;
177 
178                /* Set the pointer to the beginning of the element string.  */
179                element_ptr =  element_string;
180 
181             }
182         }
183         else
184         {
185 
186             /* We have a regular character. Store it in the element string buffer. No need to check
187                the syntax here as the string to hexa conversion will do that.  */
188             *element_ptr++ = *xml_parameter;
189 
190             /* Increase the length of the element.  */
191             element_length++;
192 
193         }
194 
195 
196         /* Next position.  */
197         xml_parameter++;
198 
199         /* Update length.  */
200         length--;
201 
202     }
203 
204     /* We get here when we reached the end of the xml parameter. We may still have the last element of the cropping area to parse.
205        The index value will tell us what to do.  */
206     switch (index)
207     {
208 
209         case 3 :
210 
211             /* Still need to parse the last element. Get the hexa value for that element.  */
212             status =  _ux_pictbridge_element_to_hexa(element_string, &hexa_value);
213 
214             /* Check for error.  */
215             if (status != UX_SUCCESS)
216 
217                 /* We have a element syntax error.  */
218                 return(status);
219 
220             /* This is the height of the cropping area.  */
221             pictbridge -> ux_pictbridge_jobinfo.ux_pictbridge_jobinfo_printinfo_current -> ux_pictbridge_printinfo_croppingarea_height = hexa_value;
222 
223             /* Operation is successful.  */
224             return(UX_SUCCESS);
225 
226         case 4:
227 
228             /* Operation is successful.  */
229             return(UX_SUCCESS);
230 
231         default :
232 
233             /* Syntax error.  Missing element of the cropping area.  */
234             return(UX_PICTBRIDGE_ERROR_SCRIPT_SYNTAX_ERROR);
235     }
236 
237 }
238 
239 
240