* Parse a method pointed by start, end is the last character to check (if NULL * assume that start is a zero terminated string) * => assign enum bit to method. * Returns pointer to next char if parse succeeded * and NULL otherwise. */
| 55 | * and NULL otherwise. |
| 56 | */ |
| 57 | char* parse_method(char* start, char* end, unsigned int* method) |
| 58 | { |
| 59 | int len=0; |
| 60 | int max=0; |
| 61 | |
| 62 | if (!start || !method) { |
| 63 | LM_ERR("invalid parameter value\n"); |
| 64 | return NULL; |
| 65 | } |
| 66 | |
| 67 | if(end) |
| 68 | max = end - start; |
| 69 | *method = METHOD_UNDEF; |
| 70 | |
| 71 | switch (start[0]) { |
| 72 | case 'A': |
| 73 | case 'a': |
| 74 | if(end && max<3) |
| 75 | goto unknown; |
| 76 | |
| 77 | if ((start[1]=='c' || start[1]=='C') |
| 78 | && (start[2]=='k' || start[2]=='K')) |
| 79 | { |
| 80 | *method = METHOD_ACK; |
| 81 | len = 3; |
| 82 | goto done; |
| 83 | } |
| 84 | goto unknown; |
| 85 | |
| 86 | case 'B': |
| 87 | case 'b': |
| 88 | if(end && max<3) |
| 89 | goto unknown; |
| 90 | |
| 91 | if ((start[1]=='y' || start[1]=='Y') |
| 92 | && (start[2]=='e' || start[2]=='E')) |
| 93 | { |
| 94 | *method = METHOD_BYE; |
| 95 | len = 3; |
| 96 | goto done; |
| 97 | } |
| 98 | goto unknown; |
| 99 | |
| 100 | case 'C': |
| 101 | case 'c': |
| 102 | if(end && max<6) |
| 103 | goto unknown; |
| 104 | if ((start[1]=='a' || start[1]=='A') |
| 105 | && (start[2]=='n' || start[2]=='N') |
| 106 | && (start[3]=='c' || start[3]=='C') |
| 107 | && (start[4]=='e' || start[4]=='E') |
| 108 | && (start[5]=='l' || start[5]=='L')) |
| 109 | { |
| 110 | *method = METHOD_CANCEL; |
| 111 | len = 6; |
| 112 | goto done; |
| 113 | } |
| 114 | goto unknown; |
no test coverage detected