parser.c

Go to the documentation of this file.
00001 
00015 #include "parser.h"
00016 
00017 
00018 /* parser is one for userspace and one for kernel */
00019 #ifdef __KERNEL__
00020  #include <linux/kernel.h>
00021  #include <linux/string.h>
00022 #else
00023  #include <stdio.h>
00024  #include <string.h>
00025 #endif
00026 
00027 
00036 inline int get_command_nr (const char * command_string){
00037 
00038 
00039 /* commands sends from deamon to kernel */
00040 #ifdef __KERNEL__       
00041         if (strcmp(command_string, CMD_OK) == 0 ){
00042                 return CMD_OK_NR;       
00043         }
00044         
00045         if (strcmp(command_string, CMD_ER) == 0 ){
00046                 return CMD_ER_NR;       
00047         }
00048         
00049 /* commands sends from kernel to deamon */
00050 #else 
00051         if (strcmp(command_string, TEST) == 0 ){        
00052                 return TEST_NR; 
00053         }
00054         
00055         if (strcmp(command_string, CREATE) == 0 ){
00056                 return CREATE_NR;       
00057         }
00058         
00059         if (strcmp(command_string, MKDIR) == 0 ){
00060                 return MKDIR_NR;        
00061         }
00062         
00063         if (strcmp(command_string, CLEAR_FILE) == 0 ){
00064                 return CLEAR_FILE_NR;   
00065         }
00066         
00067         if (strcmp(command_string, ADD_BLOCK) == 0 ){
00068                 return ADD_BLOCK_NR;    
00069         }
00070         
00071         if (strcmp(command_string, REMOVE_FILE) == 0 ){
00072                 return REMOVE_FILE_NR;  
00073         }
00074         
00075         if (strcmp(command_string, REMOVE_DIR) == 0 ){
00076                 return REMOVE_DIR_NR;   
00077         }
00078         
00079         if (strcmp(command_string, GET_BLOCK) == 0 ){
00080                 return GET_BLOCK_NR;    
00081         }
00082         
00083         if (strcmp(command_string, LOOKUP) == 0 ){
00084                 return LOOKUP_NR;       
00085         }
00086         
00087         if (strcmp(command_string, READ_DIR) == 0 ){
00088                 return READ_DIR_NR;     
00089         }
00090         
00091         if (strcmp(command_string, READ_INODE) == 0 ){
00092                 return READ_INODE_NR;   
00093         }
00094         
00095         if (strcmp(command_string, REPLACE_BLOCK) == 0 ){
00096                 return REPLACE_BLOCK_NR;        
00097         }
00098         
00099         if (strcmp(command_string, MOVE_FILE) == 0 ){
00100                 return MOVE_FILE_NR;    
00101         }
00102         
00103         if (strcmp(command_string, RENAME_FILE) == 0 ){
00104                 return RENAME_FILE_NR;  
00105         }
00106 
00107         if (strcmp(command_string, RENAME_DIR) == 0 ){
00108                 return RENAME_DIR_NR;   
00109         }
00110         
00111         if (strcmp(command_string, TRUNCATE_FILE) == 0 ){
00112                 return TRUNCATE_FILE_NR;        
00113         }
00114         
00115 
00116         
00117 #endif  
00118         return UNKNOWN_COMMAND_NR;
00119 }
00120 
00121 
00134 int parse_message(char *message, int message_len, struct_command * command) {
00135         
00136         /* chars counter */
00137         int i = 0;
00138         int pos = 0;
00139         
00140         /* determine version of protocol */
00141         while ((pos < message_len) && ((*message) != ' ') && (i < MAX_VERSION_LENGTH) ) {
00142                 command->version[i++] = *message;
00143                 message++;
00144                 pos++;
00145         }
00146         
00147         command->version[i] = '\x0';
00148         if ((*message) != '\x0') {
00149                 message++;
00150                 pos++;          
00151         }
00152         
00153         if (strcmp(command->version,FSD_VERSION) != 0){
00154                 PDEBUG("fsd_parse_message - protokol version control failed\n");
00155                 return EPROTOKOL_VERSION_ERROR;
00156         }
00157         
00158         i = 0;
00159         /* command */
00160         while  ((pos < message_len) && ((*message) != ' ') && (i < MAX_COMMAND_LENGTH)) {
00161                 command->command[i++] = *message;
00162                 message++; 
00163                 pos++;
00164         }
00165         
00166         command->command[i] = '\x0';
00167         if ((*message) != '\x0') {
00168                 message++;
00169                 pos++;
00170         }
00171         
00172         command->command_nr = get_command_nr(command->command);
00173         
00174         i = 0;
00175         /* parameter */
00176         while ((pos < message_len) && ((*message) != ' ') && (i < MAX_PARAM_LENGTH)) {
00177                 command->param[i++] = *message;
00178                 message++;
00179                 pos++;
00180                 
00181         }
00182         
00183         command->param[i] = '\x0';
00184         if ((*message) != '\x0') {
00185                 message++;
00186                 pos++;
00187         }
00188         
00189         i = 0;
00190         /* data */
00191         while ((pos < message_len) && (i < (MAX_BLOCK_LENGTH + MAX_SIZE_LENGTH + 1))) {
00192                 /* printf("pos=%d, i=%d, message[i]=%c\n", pos, i, *message); */
00193                 command->data[i++] = *message;
00194                 message++;
00195                 pos++;
00196                 
00197         }
00198         
00199         command->data[i] = '\x0'; /* added by Michal F. - zero is there for debugging messages */
00200         command->data_len = i;
00201         return OK;
00202 }
00203 
00204 

Generated on Mon May 28 13:33:08 2007 for MYSQLFS by  doxygen 1.5.0