CCSDS_study project
This commit is contained in:
267
netzob-030/lib/interface/Interface.c
Normal file
267
netzob-030/lib/interface/Interface.c
Normal file
@@ -0,0 +1,267 @@
|
||||
// -*- coding: utf-8 -*-
|
||||
|
||||
//+---------------------------------------------------------------------------+
|
||||
//| 01001110 01100101 01110100 01111010 01101111 01100010 |
|
||||
//| |
|
||||
//| Netzob : Inferring communication protocols |
|
||||
//+---------------------------------------------------------------------------+
|
||||
//| Copyright (C) 2011-2017 Georges Bossert and Frédéric Guihéry |
|
||||
//| This program is free software: you can redistribute it and/or modify |
|
||||
//| it under the terms of the GNU General Public License as published by |
|
||||
//| the Free Software Foundation, either version 3 of the License, or |
|
||||
//| (at your option) any later version. |
|
||||
//| |
|
||||
//| This program is distributed in the hope that it will be useful, |
|
||||
//| but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
//| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||
//| GNU General Public License for more details. |
|
||||
//| |
|
||||
//| You should have received a copy of the GNU General Public License |
|
||||
//| along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
||||
//+---------------------------------------------------------------------------+
|
||||
//| @url : http://www.netzob.org |
|
||||
//| @contact : contact@netzob.org |
|
||||
//| @sponsors : Amossys, http://www.amossys.fr |
|
||||
//| Supélec, http://www.rennes.supelec.fr/ren/rd/cidre/ |
|
||||
//+---------------------------------------------------------------------------+
|
||||
|
||||
//Compilation Windows
|
||||
//cl -Fe_libInterface.pyd -Ox -Ot -openmp -LD /I"C:\Python26\include" /I"C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include" libInterface.c "C:\Python26\libs\python26.lib" "C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\lib\vcomp.lib"
|
||||
|
||||
//+---------------------------------------------------------------------------+
|
||||
//| Import Associated Header
|
||||
//+---------------------------------------------------------------------------+
|
||||
#include "Interface.h"
|
||||
#ifdef _WIN32
|
||||
#include <stdio.h>
|
||||
#include <malloc.h>
|
||||
#endif
|
||||
|
||||
#ifdef CCALLFORDEBUG
|
||||
//+---------------------------------------------------------------------------+
|
||||
//| callbackStatus : displays the status on terminal when using only C calls
|
||||
//+---------------------------------------------------------------------------+
|
||||
int callbackStatus(int stage, double percent, char* message, ...) {
|
||||
// Variadic member
|
||||
va_list args;
|
||||
|
||||
// local variables
|
||||
char buffer[4096];
|
||||
|
||||
va_start(args, message);
|
||||
vsnprintf(buffer, sizeof(buffer), message, args);
|
||||
va_end(args);
|
||||
buffer[4095] = '\0';
|
||||
|
||||
printf("[%d, %f] %s\n", stage, percent, buffer);
|
||||
return 1;
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
//+---------------------------------------------------------------------------+
|
||||
//| deserializeMessages : Deserialization of messages
|
||||
//+---------------------------------------------------------------------------+
|
||||
unsigned int deserializeMessages(t_group * group, char *format, unsigned char *serialMessages, unsigned int nbMessages, Bool debugMode) {
|
||||
unsigned int i_message = 0;
|
||||
char * p;
|
||||
unsigned int serial_shift = 0;
|
||||
unsigned int format_shift = 0;
|
||||
unsigned int len_size_message=0;
|
||||
unsigned int size_message=0;
|
||||
char * size_message_str;
|
||||
unsigned int nbDeserializedMessages = 0;
|
||||
|
||||
for (i_message=0; i_message < nbMessages; i_message++) {
|
||||
// Retrieve the size of each message
|
||||
p = strchr(format + format_shift, 'M');
|
||||
len_size_message = (unsigned int) (p - (format + format_shift));
|
||||
size_message_str = malloc((len_size_message + 1) * sizeof(char));
|
||||
memcpy(size_message_str, format + format_shift, len_size_message);
|
||||
size_message_str[len_size_message] = '\0';
|
||||
size_message = atoi(size_message_str);
|
||||
|
||||
// Register the message
|
||||
group->messages[i_message].len = size_message;
|
||||
group->messages[i_message].alignment = serialMessages + serial_shift;
|
||||
group->messages[i_message].mask = malloc(size_message * sizeof(unsigned char));
|
||||
memset(group->messages[i_message].mask, '\0', size_message);
|
||||
t_score score;
|
||||
group->messages[i_message].score = &score;
|
||||
|
||||
nbDeserializedMessages += 1;
|
||||
|
||||
format_shift = format_shift + len_size_message + 1;
|
||||
serial_shift = serial_shift + size_message;
|
||||
|
||||
// Cleaning useless allocated memory
|
||||
free(size_message_str);
|
||||
}
|
||||
|
||||
if (debugMode == TRUE) {
|
||||
printf("A number of %d messages has been deserialized.\n", nbDeserializedMessages);
|
||||
for (i_message = 0; i_message<nbDeserializedMessages; i_message++) {
|
||||
printf("Message %u : \n", i_message);
|
||||
hexdump(group->messages[i_message].alignment, group->messages[i_message].len);
|
||||
}
|
||||
}
|
||||
return nbDeserializedMessages;
|
||||
}
|
||||
|
||||
unsigned int deserializeGroups(t_groups * groups, char * format, unsigned char * serialGroups, int nbGroups, Bool debugMode) {
|
||||
int i_group = 0;
|
||||
int j_group = 0;
|
||||
int l = 0;
|
||||
char * p;
|
||||
char *q;
|
||||
char *r;
|
||||
char *s;
|
||||
unsigned short int format_shift = 0;
|
||||
unsigned int len_size_group = 0;
|
||||
unsigned int len_size_message = 0;
|
||||
unsigned int len_score_group = 0;
|
||||
unsigned int size_group = 0;
|
||||
unsigned int size_message = 0;
|
||||
char * size_group_str;
|
||||
char * size_message_str;
|
||||
char * score_group;
|
||||
unsigned int i_message = 0;
|
||||
|
||||
for (i_group = 0; i_group <nbGroups; i_group++) {
|
||||
//Retrieve the precompiled scores
|
||||
s = strchr(format + format_shift, 'E');
|
||||
if (s != NULL){ // Used for compatibility between version
|
||||
for (j_group = i_group + 1; j_group < nbGroups ; j_group ++){
|
||||
r = strchr(format + format_shift, 'S');
|
||||
if (r!=NULL && (int) (s - r) > 0){
|
||||
len_score_group = (unsigned int) (r - (format + format_shift));
|
||||
score_group = malloc((len_score_group + 1) * sizeof(unsigned char));
|
||||
memcpy(score_group, format + format_shift, len_score_group);
|
||||
score_group[len_score_group]='\0';
|
||||
groups->groups[i_group].scores[j_group-(i_group+1)] = atof(score_group);
|
||||
format_shift += len_score_group + 1;
|
||||
free(score_group);
|
||||
}
|
||||
else{
|
||||
break;
|
||||
}
|
||||
}
|
||||
format_shift += 1; // FOR LETTER 'E'*/
|
||||
}
|
||||
// retrieve the number of messages in the current group
|
||||
p = strchr(format + format_shift, 'G');
|
||||
len_size_group = (unsigned int) (p - (format + format_shift));
|
||||
size_group_str = malloc((len_size_group + 1) * sizeof(char));
|
||||
memcpy(size_group_str, format + format_shift, len_size_group);
|
||||
size_group_str[len_size_group] = '\0';
|
||||
size_group = (unsigned int) atoi(size_group_str);
|
||||
format_shift += len_size_group + 1;
|
||||
|
||||
// Allocate pointers to store the messages of current group
|
||||
groups->groups[i_group].len = size_group;
|
||||
groups->groups[i_group].messages = malloc(size_group * sizeof(t_message));
|
||||
|
||||
for (i_message = 0; i_message < size_group; i_message++) {
|
||||
// Retrieve the size of each message
|
||||
q = strchr(format + format_shift, 'M');
|
||||
len_size_message = (unsigned int) (q - (format + format_shift));
|
||||
size_message_str = malloc((len_size_message + 1) * sizeof(char));
|
||||
memcpy(size_message_str, format + format_shift, len_size_message);
|
||||
size_message_str[len_size_message] = '\0';
|
||||
size_message = atoi(size_message_str);
|
||||
format_shift += len_size_message + 1;
|
||||
|
||||
// Retrieve the data of each message
|
||||
groups->groups[i_group].messages[i_message].len = size_message;
|
||||
groups->groups[i_group].messages[i_message].alignment = serialGroups + l;
|
||||
groups->groups[i_group].messages[i_message].mask = serialGroups + l + size_message;
|
||||
|
||||
l += size_message * 2;
|
||||
free(size_message_str );
|
||||
}
|
||||
free(size_group_str);
|
||||
}
|
||||
if (debugMode == TRUE) {
|
||||
printf("A number of %d group has been deserialized.\n", nbGroups);
|
||||
}
|
||||
return i_group;
|
||||
}
|
||||
|
||||
#define OPL 64
|
||||
|
||||
void hexdump(unsigned char *buf, int dlen) {
|
||||
char c[OPL + 1];
|
||||
int i, ct;
|
||||
|
||||
if (dlen < 0) {
|
||||
printf("WARNING: computed dlen %d\n", dlen);
|
||||
dlen = 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < dlen; ++i) {
|
||||
if (i == 0)
|
||||
printf("DATA: ");
|
||||
else if ((i % OPL) == 0) {
|
||||
c[OPL] = '\0';
|
||||
printf("\t\"%s\"\nDATA: ", c);
|
||||
}
|
||||
ct = buf[i] & 0xff;
|
||||
c[i % OPL] = (ct >= ' ' && ct <= '~') ? ct : '.';
|
||||
printf("%02x ", ct);
|
||||
}
|
||||
c[i % OPL] = '\0';
|
||||
for (; i % OPL; ++i)
|
||||
printf(" ");
|
||||
printf("\t\"%s\"\n", c);
|
||||
}
|
||||
|
||||
|
||||
void dumpMessage(t_message message) {
|
||||
unsigned int i;
|
||||
printf("%d ", message.len);
|
||||
for(i = 0; i < message.len; i++) {
|
||||
if(message.mask[i] == 0)
|
||||
printf("%02x", (unsigned char) message.alignment[i]);
|
||||
else if(message.mask[i] == 2)
|
||||
printf("##");
|
||||
else
|
||||
printf("--");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
unsigned int serializeSemanticTags(char ** serializedTags, t_semanticTag ** tags, unsigned int nbSemanticTags) {
|
||||
unsigned int sizeSerializedTags = 0;
|
||||
unsigned int iTag = 0;
|
||||
unsigned int sizeLocalTag = 0;
|
||||
// serializedTags = "tag1;tag2;tag3;..."
|
||||
// first we compute the size of the result:
|
||||
// size(serializedTags) = sum(size(tags->name)+1)+1
|
||||
|
||||
for (iTag=0; iTag<nbSemanticTags; iTag++){
|
||||
if(tags[iTag]->name != NULL) {
|
||||
sizeSerializedTags += strlen(tags[iTag]->name);
|
||||
}
|
||||
sizeSerializedTags +=1;
|
||||
}
|
||||
sizeSerializedTags +=1; // for the NULL byte
|
||||
*serializedTags = calloc(sizeSerializedTags, sizeof(char));
|
||||
for (iTag=0; iTag<nbSemanticTags; iTag++) {
|
||||
if (tags[iTag]->name != NULL) {
|
||||
sizeLocalTag = strlen(tags[iTag]->name);
|
||||
if(sizeLocalTag>0){
|
||||
strncat(*serializedTags, tags[iTag]->name, sizeLocalTag);
|
||||
}
|
||||
}
|
||||
strncat(*serializedTags, ";", 1);
|
||||
}
|
||||
return sizeSerializedTags;
|
||||
}
|
||||
|
||||
PyObject * serializeMessage(t_message * message) {
|
||||
char * semanticTags = NULL;
|
||||
unsigned int lenSemanticTags = serializeSemanticTags(&semanticTags, message->semanticTags, message->len);
|
||||
return Py_BuildValue("(fffy#y#s#)", message->score->s1, message->score->s2, message->score->s3, message->alignment, message->len, message->mask, message->len, semanticTags, lenSemanticTags);
|
||||
|
||||
}
|
||||
313
netzob-030/lib/interface/Py_lib/libInterface.c
Normal file
313
netzob-030/lib/interface/Py_lib/libInterface.c
Normal file
@@ -0,0 +1,313 @@
|
||||
// -*- coding: utf-8 -*-
|
||||
|
||||
//+---------------------------------------------------------------------------+
|
||||
//| 01001110 01100101 01110100 01111010 01101111 01100010 |
|
||||
//| |
|
||||
//| Netzob : Inferring communication protocols |
|
||||
//+---------------------------------------------------------------------------+
|
||||
//| Copyright (C) 2011-2017 Georges Bossert and Frédéric Guihéry |
|
||||
//| This program is free software: you can redistribute it and/or modify |
|
||||
//| it under the terms of the GNU General Public License as published by |
|
||||
//| the Free Software Foundation, either version 3 of the License, or |
|
||||
//| (at your option) any later version. |
|
||||
//| |
|
||||
//| This program is distributed in the hope that it will be useful, |
|
||||
//| but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
//| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||
//| GNU General Public License for more details. |
|
||||
//| |
|
||||
//| You should have received a copy of the GNU General Public License |
|
||||
//| along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
||||
//+---------------------------------------------------------------------------+
|
||||
//| @url : http://www.netzob.org |
|
||||
//| @contact : contact@netzob.org |
|
||||
//| @sponsors : Amossys, http://www.amossys.fr |
|
||||
//| Supélec, http://www.rennes.supelec.fr/ren/rd/cidre/ |
|
||||
//+---------------------------------------------------------------------------+
|
||||
|
||||
//Compilation Windows
|
||||
//cl -Fe_libInterface.pyd -Ox -Ot -openmp -LD /I"C:\Python26\include" /I"C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include" libInterface.c "C:\Python26\libs\python26.lib" "C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\lib\vcomp.lib"
|
||||
|
||||
//+---------------------------------------------------------------------------+
|
||||
//| Import Associated Header
|
||||
//+---------------------------------------------------------------------------+
|
||||
#include "libInterface.h"
|
||||
#ifdef _WIN32
|
||||
#include <stdio.h>
|
||||
#include <malloc.h>
|
||||
#endif
|
||||
|
||||
// The Python callback
|
||||
PyObject *python_callback;
|
||||
PyObject *python_callback_isFinish;
|
||||
|
||||
unsigned int deserializeSymbols(PyObject *symbols, Bool debugMode);
|
||||
PyObject* py_deserializeSymbols(PyObject* self, PyObject* args);
|
||||
|
||||
static PyMethodDef libInterface_methods[] = {
|
||||
{"getBID", py_getBID, METH_NOARGS, NULL},
|
||||
{"deserializeMessages", py_deserializeMessages, METH_VARARGS, NULL},
|
||||
{"deserializeGroups", py_deserializeGroups, METH_VARARGS, NULL},
|
||||
{"deserializeSymbols",py_deserializeSymbols, METH_VARARGS, NULL},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
//+---------------------------------------------------------------------------+
|
||||
//| initlibInterface : Python will use this function to init the module
|
||||
//+---------------------------------------------------------------------------+
|
||||
PyObject* PyInit__libInterface(void) {
|
||||
static struct PyModuleDef moduledef = {
|
||||
PyModuleDef_HEAD_INIT,
|
||||
"_libInterface",
|
||||
NULL,
|
||||
-1,
|
||||
libInterface_methods,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
return PyModule_Create(&moduledef);
|
||||
}
|
||||
|
||||
int callbackIsFinish(void) {
|
||||
if (python_callback_isFinish != NULL) {
|
||||
int isFinish;
|
||||
PyObject *result_cb;
|
||||
result_cb = PyObject_CallObject(python_callback_isFinish, NULL);
|
||||
if (result_cb == NULL) {
|
||||
return -1;
|
||||
}
|
||||
if (result_cb == Py_True) {
|
||||
isFinish = 1;
|
||||
}
|
||||
else if (result_cb == Py_False) {
|
||||
isFinish = 0;
|
||||
} else {
|
||||
isFinish = -1;
|
||||
}
|
||||
Py_DECREF(result_cb);
|
||||
return isFinish;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
//+---------------------------------------------------------------------------+
|
||||
//| callbackStatus : displays the status or call python wrapper is available
|
||||
//+---------------------------------------------------------------------------+
|
||||
int callbackStatus(int stage, double percent, char* message, ...) {
|
||||
// Variadic member
|
||||
va_list args;
|
||||
|
||||
// local variables
|
||||
PyObject *arglist_cb;
|
||||
PyObject *result_cb;
|
||||
char buffer[4096];
|
||||
|
||||
va_start(args, message);
|
||||
vsnprintf(buffer, sizeof(buffer), message, args);
|
||||
va_end(args);
|
||||
buffer[4095] = '\0';
|
||||
if (python_callback != NULL) {
|
||||
arglist_cb = Py_BuildValue("(i,d,s)", stage, percent, buffer);
|
||||
result_cb = PyObject_CallObject(python_callback, arglist_cb);
|
||||
Py_DECREF(arglist_cb);
|
||||
|
||||
if (result_cb == NULL) {
|
||||
return -1;
|
||||
}
|
||||
Py_DECREF(result_cb);
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
printf("[%f] %s\n", percent, buffer);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//+---------------------------------------------------------------------------+
|
||||
//| py_deserializeMessages : Python wrapper for deserializeMessages
|
||||
//+---------------------------------------------------------------------------+
|
||||
PyObject* py_deserializeMessages(__attribute__((unused))PyObject* self, PyObject* args) {
|
||||
unsigned int nbMessages = (unsigned int) PyObject_Size(args);
|
||||
char *format;
|
||||
int sizeFormat;
|
||||
unsigned char *serialMessages;
|
||||
int sizeSerialMessages;
|
||||
unsigned int debugMode = 0;
|
||||
unsigned int nbDeserializedMessage = 0;
|
||||
t_group group_result;
|
||||
// Converts the arguments
|
||||
|
||||
if (!PyArg_ParseTuple(args, "hss#h", &nbMessages, &format, &sizeFormat, &serialMessages, &sizeSerialMessages, &debugMode)) {
|
||||
printf("Error while parsing the arguments provided to py_deserializeMessages\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Deserializes the provided arguments
|
||||
if (debugMode == 1) {
|
||||
printf("py_alignSequences : Deserialization of the arguments (format, serialMessages).\n");
|
||||
}
|
||||
|
||||
group_result.len = nbMessages;
|
||||
group_result.messages = malloc(nbMessages*sizeof(t_message));
|
||||
|
||||
nbDeserializedMessage = deserializeMessages(&group_result, format, serialMessages, nbMessages, debugMode);
|
||||
|
||||
if (nbDeserializedMessage != nbMessages) {
|
||||
printf("Error : impossible to deserialize all the provided messages.\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// cleaning a bit
|
||||
free(group_result.messages);
|
||||
|
||||
if(debugMode == 1) {
|
||||
printf("All the provided messages were deserialized (%d).\n", nbDeserializedMessage);
|
||||
}
|
||||
|
||||
// return the number of deserialized messages
|
||||
return Py_BuildValue("i", nbDeserializedMessage);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//+---------------------------------------------------------------------------+
|
||||
//| py_deserializeGroups : Python wrapper for deserializeGroups
|
||||
//+---------------------------------------------------------------------------+
|
||||
PyObject* py_deserializeGroups(__attribute__((unused))PyObject* self, PyObject* args) {
|
||||
unsigned int nbGroups = 0;
|
||||
char *format;
|
||||
int sizeFormat;
|
||||
unsigned char *serialGroups;
|
||||
int sizeSerialGroups;
|
||||
unsigned int debugMode = 0;
|
||||
unsigned int nbDeserializedGroup = 0;
|
||||
t_groups groups_result;
|
||||
|
||||
// Get the number of group (need python>=2.5)
|
||||
if(PyObject_Size(args) == -1) {
|
||||
printf("The argument has no length");
|
||||
return NULL;
|
||||
}
|
||||
else {
|
||||
nbGroups = (unsigned int) PyObject_Size(args);
|
||||
}
|
||||
|
||||
|
||||
// Converts the arguments
|
||||
if (!PyArg_ParseTuple(args, "hss#h", &nbGroups, &format, &sizeFormat, &serialGroups, &sizeSerialGroups, &debugMode)) {
|
||||
printf("Error while parsing the arguments provided to py_deserializeGroups\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Deserializes the provided arguments
|
||||
if (debugMode == 1) {
|
||||
printf("py_deserializeGroups : Deserialization of the arguments (format, serialGroups).\n");
|
||||
}
|
||||
|
||||
groups_result.len = nbGroups;
|
||||
groups_result.groups = malloc(nbGroups*sizeof(t_group));
|
||||
|
||||
nbDeserializedGroup = deserializeGroups(&groups_result, format, serialGroups, nbGroups, debugMode);
|
||||
// deserializeSymbols(&groups_result, args, debugMode);
|
||||
if (nbDeserializedGroup != nbGroups) {
|
||||
printf("Error : impossible to deserialize all the provided groups, %d/%d were effectly parsed.\n", nbDeserializedGroup, nbGroups);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// cleaning a bit
|
||||
free(groups_result.groups);
|
||||
|
||||
if(debugMode == 1) {
|
||||
printf("All the provided groups were deserialized (%d).\n", nbDeserializedGroup);
|
||||
}
|
||||
|
||||
// return the number of deserialized groups
|
||||
return Py_BuildValue("i", nbDeserializedGroup);
|
||||
}
|
||||
|
||||
/********************************************************************
|
||||
* deserializeSymbols:
|
||||
* push list of symbols in the groups
|
||||
*
|
||||
*********************************************************************/
|
||||
PyObject * py_deserializeSymbols(__attribute__((unused))PyObject* self, PyObject* args) {
|
||||
|
||||
deserializeSymbols(args,0);
|
||||
return Py_BuildValue("i", 1);
|
||||
}
|
||||
unsigned int deserializeSymbols(PyObject *args, Bool debugMode) {
|
||||
PyObject *symbols = PyTuple_GetItem(args, 0);
|
||||
int nbGroups = PyObject_Size(symbols);
|
||||
int nbScore = 0;
|
||||
float tempScore = 0;
|
||||
if (nbGroups == -1)
|
||||
return 0;
|
||||
int i_group = 0;
|
||||
int j_group = 0;
|
||||
PyObject *current_symbol = NULL;
|
||||
PyObject *scoresList = NULL;
|
||||
PyObject *current_position = NULL;
|
||||
|
||||
printf("IN\n");
|
||||
if (!PyList_Check(symbols))
|
||||
{
|
||||
printf("The format of the list of symbols given is not a list");
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
if(debugMode == 1) {
|
||||
printf("Size %d\n",nbGroups);
|
||||
printf("InElse\n");
|
||||
}
|
||||
|
||||
for (i_group = 0; i_group <nbGroups; i_group++) {
|
||||
|
||||
current_position = PyList_GetItem(symbols, i_group);
|
||||
printf("Step1\n");
|
||||
if (!PyList_Check(current_position))
|
||||
{
|
||||
printf("The format of the list of symbols given is not a list");
|
||||
return 0;
|
||||
}
|
||||
current_symbol = PyList_GetItem(current_position, 0); // The Symbols Object
|
||||
scoresList = PyList_GetItem(current_position, 1); // The list of scores
|
||||
nbScore = PyObject_Size(scoresList); // # of scores recorded
|
||||
|
||||
for (j_group = 0; j_group < nbScore ; j_group ++){
|
||||
tempScore = (float) PyFloat_AsDouble(PyList_GetItem(scoresList,j_group));
|
||||
if(debugMode == 1) {
|
||||
printf("tempScore %f\n",tempScore);
|
||||
}
|
||||
|
||||
}
|
||||
if(debugMode == 1) {
|
||||
printf("END SCORE\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Decrease the ref at the end of the loop*/
|
||||
if (i_group == nbGroups-1) {
|
||||
if(current_position != NULL)
|
||||
Py_DECREF(current_position);
|
||||
if(current_symbol != NULL)
|
||||
Py_DECREF(current_symbol);
|
||||
if(scoresList != NULL)
|
||||
Py_DECREF(scoresList);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(debugMode == 1) {
|
||||
printf("End of else\n");
|
||||
}
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user